Skip to content

Commit c2a169d

Browse files
committed
Allow graphql to pass through null values instead of ignoring them
As set out in graphql#133 and graphql/graphql-spec#83
1 parent a6bcc75 commit c2a169d

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/execution/values.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ function coerceValue(type: GraphQLInputType, value: any): any {
130130
return coerceValue(nullableType, value);
131131
}
132132

133-
if (isNullish(value)) {
133+
if (value === undefined) {
134134
return null;
135135
}
136136

@@ -148,10 +148,9 @@ function coerceValue(type: GraphQLInputType, value: any): any {
148148
return Object.keys(fields).reduce((obj, fieldName) => {
149149
var field = fields[fieldName];
150150
var fieldValue = coerceValue(field.type, value[fieldName]);
151-
if (isNullish(fieldValue)) {
151+
if (fieldValue === undefined) {
152152
fieldValue = field.defaultValue;
153-
}
154-
if (!isNullish(fieldValue)) {
153+
} else {
155154
obj[fieldName] = fieldValue;
156155
}
157156
return obj;
@@ -162,6 +161,10 @@ function coerceValue(type: GraphQLInputType, value: any): any {
162161
type instanceof GraphQLScalarType || type instanceof GraphQLEnumType,
163162
'Must be input type'
164163
);
164+
165+
if (value === null) {
166+
return null;
167+
}
165168

166169
var parsed = type.parseValue(value);
167170
if (!isNullish(parsed)) {

0 commit comments

Comments
 (0)