@@ -18,6 +18,7 @@ import {
18
18
GraphQLString ,
19
19
GraphQLNonNull ,
20
20
GraphQLScalarType ,
21
+ GraphQLEnumType ,
21
22
} from '../../type' ;
22
23
23
24
const TestComplexScalar = new GraphQLScalarType ( {
@@ -60,6 +61,18 @@ const TestNestedInputObject = new GraphQLInputObjectType({
60
61
} ,
61
62
} ) ;
62
63
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
+
63
76
function fieldWithInputArg ( inputArg ) {
64
77
return {
65
78
type : GraphQLString ,
@@ -75,6 +88,10 @@ function fieldWithInputArg(inputArg) {
75
88
const TestType = new GraphQLObjectType ( {
76
89
name : 'TestType' ,
77
90
fields : {
91
+ fieldWithEnumInput : fieldWithInputArg ( { type : TestEnum } ) ,
92
+ fieldWithNonNullableEnumInput : fieldWithInputArg ( {
93
+ type : GraphQLNonNull ( TestEnum ) ,
94
+ } ) ,
78
95
fieldWithObjectInput : fieldWithInputArg ( { type : TestInputObject } ) ,
79
96
fieldWithNullableStringInput : fieldWithInputArg ( { type : GraphQLString } ) ,
80
97
fieldWithNonNullableStringInput : fieldWithInputArg ( {
@@ -358,6 +375,46 @@ describe('Execute: Handles inputs', () => {
358
375
} ) ;
359
376
} ) ;
360
377
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
+
361
418
describe ( 'Handles nullable scalars' , ( ) => {
362
419
it ( 'allows nullable inputs to be omitted' , ( ) => {
363
420
const result = executeQuery ( `
0 commit comments