Skip to content

Commit

Permalink
Fixes variable values of non-null type with default value (#2191)
Browse files Browse the repository at this point in the history
Fixes #2190
  • Loading branch information
IvanGoncharov authored Sep 20, 2019
1 parent 5723234 commit 02af5de
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
14 changes: 14 additions & 0 deletions src/execution/__tests__/variables-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
4 changes: 1 addition & 3 deletions src/execution/values.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 02af5de

Please sign in to comment.