@@ -18,6 +18,7 @@ import {
1818 GraphQLString ,
1919 GraphQLNonNull ,
2020 GraphQLScalarType ,
21+ GraphQLEnumType ,
2122} from '../../type' ;
2223
2324const TestComplexScalar = new GraphQLScalarType ( {
@@ -60,6 +61,18 @@ const TestNestedInputObject = new GraphQLInputObjectType({
6061 } ,
6162} ) ;
6263
64+ const TestEnum = new GraphQLEnumType ( {
65+ name : 'TestEnum' ,
66+ values : {
67+ NULL : { value : null } ,
68+ UNDEFINED : { value : undefined } ,
69+ NAN : { value : NaN } ,
70+ FALSE : { value : false } ,
71+ CUSTOM : { value : 'custom value' } ,
72+ DEFAULT_VALUE : { } ,
73+ } ,
74+ } ) ;
75+
6376function fieldWithInputArg ( inputArg ) {
6477 return {
6578 type : GraphQLString ,
@@ -75,6 +88,10 @@ function fieldWithInputArg(inputArg) {
7588const TestType = new GraphQLObjectType ( {
7689 name : 'TestType' ,
7790 fields : {
91+ fieldWithEnumInput : fieldWithInputArg ( { type : TestEnum } ) ,
92+ fieldWithNonNullableEnumInput : fieldWithInputArg ( {
93+ type : GraphQLNonNull ( TestEnum ) ,
94+ } ) ,
7895 fieldWithObjectInput : fieldWithInputArg ( { type : TestInputObject } ) ,
7996 fieldWithNullableStringInput : fieldWithInputArg ( { type : GraphQLString } ) ,
8097 fieldWithNonNullableStringInput : fieldWithInputArg ( {
@@ -358,6 +375,46 @@ describe('Execute: Handles inputs', () => {
358375 } ) ;
359376 } ) ;
360377
378+ describe ( 'Handles custom enum values' , ( ) => {
379+ it ( 'allows custom enum values as inputs' , ( ) => {
380+ const result = executeQuery ( `
381+ {
382+ null: fieldWithEnumInput(input: NULL)
383+ undefined: fieldWithEnumInput(input: UNDEFINED)
384+ NaN: fieldWithEnumInput(input: NAN)
385+ false: fieldWithEnumInput(input: FALSE)
386+ customValue: fieldWithEnumInput(input: CUSTOM)
387+ defaultValue: fieldWithEnumInput(input: DEFAULT_VALUE)
388+ }
389+ ` ) ;
390+
391+ expect ( result ) . to . deep . equal ( {
392+ data : {
393+ null : 'null' ,
394+ undefined : 'undefined' ,
395+ NaN : 'NaN' ,
396+ false : 'false' ,
397+ customValue : "'custom value'" ,
398+ defaultValue : "'DEFAULT_VALUE'" ,
399+ } ,
400+ } ) ;
401+ } ) ;
402+
403+ it ( 'allows non-nullable inputs to have null as enum custom value' , ( ) => {
404+ const result = executeQuery ( `
405+ {
406+ fieldWithNonNullableEnumInput(input: NULL)
407+ }
408+ ` ) ;
409+
410+ expect ( result ) . to . deep . equal ( {
411+ data : {
412+ fieldWithNonNullableEnumInput : 'null' ,
413+ } ,
414+ } ) ;
415+ } ) ;
416+ } ) ;
417+
361418 describe ( 'Handles nullable scalars' , ( ) => {
362419 it ( 'allows nullable inputs to be omitted' , ( ) => {
363420 const result = executeQuery ( `
0 commit comments