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

Allow graphql to pass through null values instead of ignoring them #268

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/execution/values.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ function coerceValue(type: GraphQLInputType, value: any): any {
return coerceValue(nullableType, value);
}

if (isNullish(value)) {
if (value === undefined) {
return null;
}

Expand All @@ -148,10 +148,9 @@ function coerceValue(type: GraphQLInputType, value: any): any {
return Object.keys(fields).reduce((obj, fieldName) => {
var field = fields[fieldName];
var fieldValue = coerceValue(field.type, value[fieldName]);
if (isNullish(fieldValue)) {
if (fieldValue === undefined) {
fieldValue = field.defaultValue;
}
if (!isNullish(fieldValue)) {
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems like a mistake - did your unit tests pass or are we missing a test for this condition? As I read it, if a fieldValue is coerced to be undefined, then we set fieldValue to the default value, however never actually set it on the response object.

obj[fieldName] = fieldValue;
}
return obj;
Expand All @@ -162,6 +161,10 @@ function coerceValue(type: GraphQLInputType, value: any): any {
type instanceof GraphQLScalarType || type instanceof GraphQLEnumType,
'Must be input type'
);

if (value === null) {
return null;
}

var parsed = type.parseValue(value);
if (!isNullish(parsed)) {
Expand Down