Skip to content

Commit 53afba1

Browse files
valueFromAST: fixed coercing of null variables on non-nullable… (#2348)
1 parent f462347 commit 53afba1

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

src/utilities/__tests__/valueFromAST-test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ describe('valueFromAST', () => {
7272
expectValueFrom('"BLUE"', testEnum).to.equal(undefined);
7373
expectValueFrom('null', testEnum).to.equal(null);
7474
expectValueFrom('NULL', testEnum).to.equal(null);
75+
expectValueFrom('NULL', new GraphQLNonNull(testEnum)).to.equal(null);
7576
expectValueFrom('NAN', testEnum).to.deep.equal(NaN);
7677
expectValueFrom('NO_CUSTOM_VALUE', testEnum).to.equal('NO_CUSTOM_VALUE');
7778
});
@@ -184,6 +185,7 @@ describe('valueFromAST', () => {
184185
expectValueFrom('$var', GraphQLBoolean, {}).to.equal(undefined);
185186
expectValueFrom('$var', GraphQLBoolean, { var: true }).to.equal(true);
186187
expectValueFrom('$var', GraphQLBoolean, { var: null }).to.equal(null);
188+
expectValueFrom('$var', nonNullBool, { var: null }).to.equal(undefined);
187189
});
188190

189191
it('asserts variables are provided as items in lists', () => {

src/utilities/valueFromAST.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,6 @@ export function valueFromAST(
5050
return;
5151
}
5252

53-
if (isNonNullType(type)) {
54-
if (valueNode.kind === Kind.NULL) {
55-
return; // Invalid: intentionally return no value.
56-
}
57-
return valueFromAST(valueNode, type.ofType, variables);
58-
}
59-
60-
if (valueNode.kind === Kind.NULL) {
61-
// This is explicitly returning the value null.
62-
return null;
63-
}
64-
6553
if (valueNode.kind === Kind.VARIABLE) {
6654
const variableName = valueNode.name.value;
6755
if (!variables || isInvalid(variables[variableName])) {
@@ -78,6 +66,18 @@ export function valueFromAST(
7866
return variableValue;
7967
}
8068

69+
if (isNonNullType(type)) {
70+
if (valueNode.kind === Kind.NULL) {
71+
return; // Invalid: intentionally return no value.
72+
}
73+
return valueFromAST(valueNode, type.ofType, variables);
74+
}
75+
76+
if (valueNode.kind === Kind.NULL) {
77+
// This is explicitly returning the value null.
78+
return null;
79+
}
80+
8181
if (isListType(type)) {
8282
const itemType = type.ofType;
8383
if (valueNode.kind === Kind.LIST) {

0 commit comments

Comments
 (0)