Skip to content

Commit 9901470

Browse files
committed
GraphQLEnumType: Drop support for 'undefined' custom value (#2148)
Motivation: #1383 (comment) Fixes #1367
1 parent dc34aa9 commit 9901470

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

src/type/__tests__/definition-test.js

+13-3
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,8 @@ describe('Type System: Enums', () => {
538538
name: 'EnumWithNullishValue',
539539
values: {
540540
NULL: { value: null },
541-
UNDEFINED: { value: undefined },
541+
NAN: { value: NaN },
542+
NO_CUSTOM_VALUE: { value: undefined },
542543
},
543544
});
544545

@@ -553,9 +554,18 @@ describe('Type System: Enums', () => {
553554
astNode: undefined,
554555
},
555556
{
556-
name: 'UNDEFINED',
557+
name: 'NAN',
557558
description: undefined,
558-
value: undefined,
559+
value: NaN,
560+
isDeprecated: false,
561+
deprecationReason: undefined,
562+
extensions: undefined,
563+
astNode: undefined,
564+
},
565+
{
566+
name: 'NO_CUSTOM_VALUE',
567+
description: undefined,
568+
value: 'NO_CUSTOM_VALUE',
559569
isDeprecated: false,
560570
deprecationReason: undefined,
561571
extensions: undefined,

src/type/definition.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1290,7 +1290,7 @@ function defineEnumValues(
12901290
return {
12911291
name: valueName,
12921292
description: valueConfig.description,
1293-
value: 'value' in valueConfig ? valueConfig.value : valueName,
1293+
value: valueConfig.value !== undefined ? valueConfig.value : valueName,
12941294
isDeprecated: Boolean(valueConfig.deprecationReason),
12951295
deprecationReason: valueConfig.deprecationReason,
12961296
extensions: valueConfig.extensions && toObjMap(valueConfig.extensions),

src/utilities/__tests__/valueFromAST-test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ describe('valueFromAST', () => {
6464
GREEN: { value: 2 },
6565
BLUE: { value: 3 },
6666
NULL: { value: null },
67-
UNDEFINED: { value: undefined },
6867
NAN: { value: NaN },
68+
NO_CUSTOM_VALUE: { value: undefined },
6969
},
7070
});
7171

@@ -76,8 +76,8 @@ describe('valueFromAST', () => {
7676
testCase(testEnum, '"BLUE"', undefined);
7777
testCase(testEnum, 'null', null);
7878
testCase(testEnum, 'NULL', null);
79-
testCase(testEnum, 'UNDEFINED', undefined);
8079
testCase(testEnum, 'NAN', NaN);
80+
testCase(testEnum, 'NO_CUSTOM_VALUE', 'NO_CUSTOM_VALUE');
8181
});
8282

8383
// Boolean!

0 commit comments

Comments
 (0)