rmosolgo/graphql-ruby

Unable to use `type` as enum value

fhoeben opened this issue · 1 comments

Describe the bug

Queries containing fields that have an enum argument do not accept the value type for that argument. Instead an error is raised: Expected VALUE, actual: TYPE (\"type\")

I know this is not a value according to the regular all caps naming scheme, but as far as I can tell it is not an illegal name for a value and another lowercase name (e.g. foo does work)

Versions

graphql version: 2.2.0 - 2.3.4 (query works in 2.1.12)
rails (or other framework): N/A
other applicable versions (graphql-batch, etc) N/A

GraphQL schema

class MyEnum < GraphQL::Schema::Enum
  value "foo"
  value "type"
end

class QueryType < GraphQL::Schema::Object
  field :hello, String do
    argument :arg, MyEnum
  end

  def hello(arg:)
    "Hello #{arg}"
  end
end

class ApplicationSchema < GraphQL::Schema
  query QueryType
end

GraphQL query

The following query works:

{ hello(arg: foo) }
{
  "data": {
    "hello": "Hello foo"
  }
}

Steps to reproduce

But when I send:

{ hello(arg: type) }

I get

{
  "errors": [
   "message": "Expected VALUE, actual: TYPE (\"type\") at [1, 14]",
   "locations": [{"line": 1, "columns": 14}]
  ]
}

Hey, thanks for reporting this! I just checked the spec to confirm, and yes, this should work like you expect. true, false and null are the only values which may not be enum values (https://spec.graphql.org/draft/#sec-Enum-Value)