the original issue was submitted to the graphql-tools repo, but it seems that it never made it here.
the issue is that after following the official documentation the enum value is not resolved to the internal value when used as a default value or in directives.
the test attached to the original issue provided by @JakeDawkins
https://gist.github.com/JakeDawkins/66f5b026cf21515f1004f057754a2cd4
@raduflp With current graphql-js design defaultValue should be in internal representation. So to correct @JakeDawkins example you need to do:
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'Query',
fields: () => ({
avatar: {
type: GraphQLBoolean,
args: {
anEnum: {
type: allowedColor,
defaultValue: '#f00',
// ^ Changed to value
},
},
resolve: (root, args) => (args.anEnum === '#f00' ? false : true),
},
}),
}),
});
Same goes for custom scalars, arrays or any other example of input coercion.
For example ID coerce numbers to strings but this coercion is not applied on defaultValue:
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'Query',
fields: () => ({
avatar: {
type: GraphQLBoolean,
args: {
id: {
type: GraphQLID,
// INVALID defaultValue: 0
defaultValue: '0', //VALID
},
},
},
}),
}),
});
@raduflp Can I close this issue?
Current behavior is expected :+1:
@raduflp If you want this issue to be reopened, please free to ping me.
@IvanGoncharov / @langpavel: how do I pass the default value in the internal representation if it's a query parameter?
I've tried 0, but the resolver gets undefined. I've tried an enum value, and the resolver gets it as a string. Here's the Code Sandbox.
Actually see https://github.com/ardatan/graphql-tools/issues/715#issuecomment-638532140, which shows the problem lies within graphql.js.