diff --git a/src/execution/__tests__/variables-test.js b/src/execution/__tests__/variables-test.js index ecc60e14ed..52b6006a26 100644 --- a/src/execution/__tests__/variables-test.js +++ b/src/execution/__tests__/variables-test.js @@ -18,6 +18,7 @@ import { GraphQLString, GraphQLNonNull, GraphQLScalarType, + GraphQLEnumType, } from '../../type'; const TestComplexScalar = new GraphQLScalarType({ @@ -60,6 +61,18 @@ const TestNestedInputObject = new GraphQLInputObjectType({ }, }); +const TestEnum = new GraphQLEnumType({ + name: 'TestEnum', + values: { + NULL: { value: null }, + UNDEFINED: { value: undefined }, + NAN: { value: NaN }, + FALSE: { value: false }, + CUSTOM: { value: 'custom value' }, + DEFAULT_VALUE: {}, + }, +}); + function fieldWithInputArg(inputArg) { return { type: GraphQLString, @@ -75,6 +88,10 @@ function fieldWithInputArg(inputArg) { const TestType = new GraphQLObjectType({ name: 'TestType', fields: { + fieldWithEnumInput: fieldWithInputArg({ type: TestEnum }), + fieldWithNonNullableEnumInput: fieldWithInputArg({ + type: GraphQLNonNull(TestEnum), + }), fieldWithObjectInput: fieldWithInputArg({ type: TestInputObject }), fieldWithNullableStringInput: fieldWithInputArg({ type: GraphQLString }), fieldWithNonNullableStringInput: fieldWithInputArg({ @@ -439,6 +456,44 @@ describe('Execute: Handles inputs', () => { }); }); + describe('Handles custom enum values', () => { + it('allows custom enum values as inputs', () => { + const result = executeQuery(` + { + null: fieldWithEnumInput(input: NULL) + NaN: fieldWithEnumInput(input: NAN) + false: fieldWithEnumInput(input: FALSE) + customValue: fieldWithEnumInput(input: CUSTOM) + defaultValue: fieldWithEnumInput(input: DEFAULT_VALUE) + } + `); + + expect(result).to.deep.equal({ + data: { + null: 'null', + NaN: 'NaN', + false: 'false', + customValue: "'custom value'", + defaultValue: "'DEFAULT_VALUE'", + }, + }); + }); + + it('allows non-nullable inputs to have null as enum custom value', () => { + const result = executeQuery(` + { + fieldWithNonNullableEnumInput(input: NULL) + } + `); + + expect(result).to.deep.equal({ + data: { + fieldWithNonNullableEnumInput: 'null', + }, + }); + }); + }); + describe('Handles nullable scalars', () => { it('allows nullable inputs to be omitted', () => { const result = executeQuery(` diff --git a/src/utilities/__tests__/valueFromAST-test.js b/src/utilities/__tests__/valueFromAST-test.js index a4ce684a48..37f59ee5c2 100644 --- a/src/utilities/__tests__/valueFromAST-test.js +++ b/src/utilities/__tests__/valueFromAST-test.js @@ -66,6 +66,7 @@ describe('valueFromAST', () => { BLUE: { value: 3 }, NULL: { value: null }, UNDEFINED: { value: undefined }, + NAN: { value: NaN }, }, }); @@ -77,6 +78,7 @@ describe('valueFromAST', () => { testCase(testEnum, 'null', null); testCase(testEnum, 'NULL', null); testCase(testEnum, 'UNDEFINED', undefined); + testCase(testEnum, 'NAN', NaN); }); // Boolean!