-
Notifications
You must be signed in to change notification settings - Fork 2k
Handle NaN as input value #1369
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
Conversation
@@ -46,7 +45,7 @@ export function coerceValue( | |||
): CoercedValue { | |||
// A value must be provided if the type is non-null. | |||
if (isNonNullType(type)) { | |||
if (isNullish(value)) { | |||
if (value == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
== null
block null
and undefined
but not a NaN and simular values
graphql-js/src/jsutils/isNullish.js
Lines 13 to 15 in 85971a2
export default function isNullish(value: mixed): boolean %checks { | |
return value === null || value === undefined || value !== value; | |
} |
@@ -566,9 +565,6 @@ export class GraphQLScalarType { | |||
// Parses an externally provided value to use as an input. | |||
parseValue(value: mixed): mixed { | |||
const parser = this._scalarConfig.parseValue; | |||
if (isInvalid(value)) { | |||
return undefined; | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Safe because it only used here:
graphql-js/src/utilities/coerceValue.js
Lines 61 to 71 in 85971a2
if (isNullish(value)) { | |
// Explicitly return the value null. | |
return ofValue(null); | |
} | |
if (isScalarType(type)) { | |
// Scalars determine if a value is valid via parseValue(), which can | |
// throw to indicate failure. If it throws, maintain a reference to | |
// the original error. | |
try { | |
const parseResult = type.parseValue(value); |
So null
and undefined
values are never passed to parseValue
.
Even though it's not breaking anything in graphql-js
it's still a minor breaking change since there is a chance that someone using parseValue
directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this makes sense to include in 14.0: as you said, removing the isInvalid => undefined case is a slight breaking change.
No description provided.