Skip to content

Commit

Permalink
Fixes variable values of non-null type with default value (#2192)
Browse files Browse the repository at this point in the history
Fixes #2190
Port of #2191 from `14.x.x` branch
  • Loading branch information
IvanGoncharov committed Sep 20, 2019
1 parent 3d86489 commit 98e5233
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
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
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 98e5233

Please sign in to comment.