Skip to content

Commit 02af5de

Browse files
Fixes variable values of non-null type with default value (#2191)
Fixes #2190
1 parent 5723234 commit 02af5de

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/execution/__tests__/variables-test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,20 @@ describe('Execute: Handles inputs', () => {
577577
});
578578

579579
describe('Handles non-nullable scalars', () => {
580+
it('allows non-nullable variable to be omitted given a default', () => {
581+
const result = executeQuery(`
582+
query ($value: String! = "default") {
583+
fieldWithNullableStringInput(input: $value)
584+
}
585+
`);
586+
587+
expect(result).to.deep.equal({
588+
data: {
589+
fieldWithNullableStringInput: '"default"',
590+
},
591+
});
592+
});
593+
580594
it('allows non-nullable inputs to be omitted given a default', () => {
581595
const result = executeQuery(`
582596
query ($value: String = "default") {

src/execution/values.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,7 @@ function coerceVariableValues(
9696
if (!hasOwnProperty(inputs, varName)) {
9797
if (varDefNode.defaultValue) {
9898
coercedValues[varName] = valueFromAST(varDefNode.defaultValue, varType);
99-
}
100-
101-
if (isNonNullType(varType)) {
99+
} else if (isNonNullType(varType)) {
102100
const varTypeStr = inspect(varType);
103101
onError(
104102
new GraphQLError(

0 commit comments

Comments
 (0)