Given the schema:
var graphql = require('graphql')
var TestEnumType = new graphql.GraphQLEnumType({
name: 'TestEnum',
values: {
FOO: {
value: 1
},
BAR: {
value: 2
}
}
})
var schema = new graphql.GraphQLSchema({
query: new graphql.GraphQLObjectType({
name: 'Query',
fields: {
print: {
type: graphql.GraphQLString,
args: {
test: {
type: TestEnumType
}
}
}
}
})
})
Having literal enum in the query results in error
relayCompiler.Printer.print(
relayCompiler.Parser.parse(
schema,
'query Foo { print(test: FOO) }'
)[0]
)
Invariant Violation: GraphQLIRPrinter: Expected value of type TestEnum to be a string, got `1`.
at invariant (/home/freiksenet/Work/gatsby/gatsby/node_modules/fbjs/lib/invariant.js:40:15)
at printLiteral (/home/freiksenet/Work/gatsby/gatsby/node_modules/relay-compiler/lib/GraphQLIRPrinter.js:255:105)
at printValue (/home/freiksenet/Work/gatsby/gatsby/node_modules/relay-compiler/lib/GraphQLIRPrinter.js:243:12)
at /home/freiksenet/Work/gatsby/gatsby/node_modules/relay-compiler/lib/GraphQLIRPrinter.js:212:24
at Array.forEach (<anonymous>)
at printArguments (/home/freiksenet/Work/gatsby/gatsby/node_modules/relay-compiler/lib/GraphQLIRPrinter.js:211:8)
at printField (/home/freiksenet/Work/gatsby/gatsby/node_modules/relay-compiler/lib/GraphQLIRPrinter.js:56:81)
at printSelection (/home/freiksenet/Work/gatsby/gatsby/node_modules/relay-compiler/lib/GraphQLIRPrinter.js:74:11)
Seems that relay is replacing all enums with literal values, which breaks for enums that don't have string values.
Thanks for reporting this, looks like this is a supported use of GraphQLEnumType in graphql-js, so we should support it. I think the issue is that printLiteral should be calling type.serialize(literalValue) instead of trying to emit a string value. PRs welcome!
Cool, I can make a fix..
@freiksenet let me know if you need some help
Most helpful comment
Thanks for reporting this, looks like this is a supported use of GraphQLEnumType in graphql-js, so we should support it. I think the issue is that
printLiteralshould be callingtype.serialize(literalValue)instead of trying to emit a string value. PRs welcome!