@@ -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 ( {
@@ -439,6 +456,44 @@ describe('Execute: Handles inputs', () => {
439
456
} ) ;
440
457
} ) ;
441
458
459
+ describe ( 'Handles custom enum values' , ( ) => {
460
+ it ( 'allows custom enum values as inputs' , ( ) => {
461
+ const result = executeQuery ( `
462
+ {
463
+ null: fieldWithEnumInput(input: NULL)
464
+ NaN: fieldWithEnumInput(input: NAN)
465
+ false: fieldWithEnumInput(input: FALSE)
466
+ customValue: fieldWithEnumInput(input: CUSTOM)
467
+ defaultValue: fieldWithEnumInput(input: DEFAULT_VALUE)
468
+ }
469
+ ` ) ;
470
+
471
+ expect ( result ) . to . deep . equal ( {
472
+ data : {
473
+ null : 'null' ,
474
+ NaN : 'NaN' ,
475
+ false : 'false' ,
476
+ customValue : "'custom value'" ,
477
+ defaultValue : "'DEFAULT_VALUE'" ,
478
+ } ,
479
+ } ) ;
480
+ } ) ;
481
+
482
+ it ( 'allows non-nullable inputs to have null as enum custom value' , ( ) => {
483
+ const result = executeQuery ( `
484
+ {
485
+ fieldWithNonNullableEnumInput(input: NULL)
486
+ }
487
+ ` ) ;
488
+
489
+ expect ( result ) . to . deep . equal ( {
490
+ data : {
491
+ fieldWithNonNullableEnumInput : 'null' ,
492
+ } ,
493
+ } ) ;
494
+ } ) ;
495
+ } ) ;
496
+
442
497
describe ( 'Handles nullable scalars' , ( ) => {
443
498
it ( 'allows nullable inputs to be omitted' , ( ) => {
444
499
const result = executeQuery ( `
0 commit comments