Skip to content

Commit

Permalink
GraphQLEnumType: Drop support for 'undefined' custom value (#2148)
Browse files Browse the repository at this point in the history
Motivation: #1383 (comment)
Fixes #1367
  • Loading branch information
IvanGoncharov committed Sep 15, 2019
1 parent dc34aa9 commit 9901470
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
16 changes: 13 additions & 3 deletions src/type/__tests__/definition-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,8 @@ describe('Type System: Enums', () => {
name: 'EnumWithNullishValue',
values: {
NULL: { value: null },
UNDEFINED: { value: undefined },
NAN: { value: NaN },
NO_CUSTOM_VALUE: { value: undefined },
},
});

Expand All @@ -553,9 +554,18 @@ describe('Type System: Enums', () => {
astNode: undefined,
},
{
name: 'UNDEFINED',
name: 'NAN',
description: undefined,
value: undefined,
value: NaN,
isDeprecated: false,
deprecationReason: undefined,
extensions: undefined,
astNode: undefined,
},
{
name: 'NO_CUSTOM_VALUE',
description: undefined,
value: 'NO_CUSTOM_VALUE',
isDeprecated: false,
deprecationReason: undefined,
extensions: undefined,
Expand Down
2 changes: 1 addition & 1 deletion src/type/definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -1290,7 +1290,7 @@ function defineEnumValues(
return {
name: valueName,
description: valueConfig.description,
value: 'value' in valueConfig ? valueConfig.value : valueName,
value: valueConfig.value !== undefined ? valueConfig.value : valueName,
isDeprecated: Boolean(valueConfig.deprecationReason),
deprecationReason: valueConfig.deprecationReason,
extensions: valueConfig.extensions && toObjMap(valueConfig.extensions),
Expand Down
4 changes: 2 additions & 2 deletions src/utilities/__tests__/valueFromAST-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ describe('valueFromAST', () => {
GREEN: { value: 2 },
BLUE: { value: 3 },
NULL: { value: null },
UNDEFINED: { value: undefined },
NAN: { value: NaN },
NO_CUSTOM_VALUE: { value: undefined },
},
});

Expand All @@ -76,8 +76,8 @@ describe('valueFromAST', () => {
testCase(testEnum, '"BLUE"', undefined);
testCase(testEnum, 'null', null);
testCase(testEnum, 'NULL', null);
testCase(testEnum, 'UNDEFINED', undefined);
testCase(testEnum, 'NAN', NaN);
testCase(testEnum, 'NO_CUSTOM_VALUE', 'NO_CUSTOM_VALUE');
});

// Boolean!
Expand Down

0 comments on commit 9901470

Please sign in to comment.