Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes variable values of non-null type with default value #2191

Merged
merged 1 commit into from Sep 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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