diff --git a/src/execution/__tests__/variables-test.js b/src/execution/__tests__/variables-test.js index de1c95d092..e3ac263ccf 100644 --- a/src/execution/__tests__/variables-test.js +++ b/src/execution/__tests__/variables-test.js @@ -577,6 +577,20 @@ describe('Execute: Handles inputs', () => { }); describe('Handles non-nullable scalars', () => { + it('allows non-nullable variable to be omitted given a default', () => { + const result = executeQuery(` + query ($value: String! = "default") { + fieldWithNullableStringInput(input: $value) + } + `); + + expect(result).to.deep.equal({ + data: { + fieldWithNullableStringInput: '"default"', + }, + }); + }); + it('allows non-nullable inputs to be omitted given a default', () => { const result = executeQuery(` query ($value: String = "default") { diff --git a/src/execution/values.js b/src/execution/values.js index 945528191e..d56132bf79 100644 --- a/src/execution/values.js +++ b/src/execution/values.js @@ -96,9 +96,7 @@ function coerceVariableValues( if (!hasOwnProperty(inputs, varName)) { if (varDefNode.defaultValue) { coercedValues[varName] = valueFromAST(varDefNode.defaultValue, varType); - } - - if (isNonNullType(varType)) { + } else if (isNonNullType(varType)) { const varTypeStr = inspect(varType); onError( new GraphQLError(