-
Notifications
You must be signed in to change notification settings - Fork 1.1k
parseValue coercion alignment for Boolean, Float, and Int #3042
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
|
||
if (result.compareTo(INT_MIN) < 0 || result.compareTo(INT_MAX) > 0) { | ||
throw new CoercingParseValueException( | ||
i18nMsg(locale, "Int.outsideRange", result.toString()) |
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.
For values outside of the integer range, we previously threw an exception with the same Int.notInt
message. We ought to use Int.outsideRange
for this case, as we do in parseLiteral
@@ -53,7 +53,6 @@ class ScalarsBooleanTest extends Specification { | |||
def "Boolean serialize #value into #result (#result.class)"() { | |||
expect: | |||
Scalars.GraphQLBoolean.getCoercing().serialize(value, GraphQLContext.default, Locale.default) == result | |||
Scalars.GraphQLBoolean.getCoercing().parseValue(value, GraphQLContext.default, Locale.default) == result |
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.
Moved into separate test below
@@ -58,7 +58,6 @@ class ScalarsFloatTest extends Specification { | |||
def "Float serialize #value into #result (#result.class)"() { | |||
expect: | |||
Scalars.GraphQLFloat.getCoercing().serialize(value, GraphQLContext.default, Locale.default) == result | |||
Scalars.GraphQLFloat.getCoercing().parseValue(value, GraphQLContext.default, Locale.default) == result |
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.
Moved into separate test below
Aligning
parseValue
coercion to be closer to the JavaScript reference implementation https://github.com/graphql/graphql-js/blob/main/src/type/scalars.tsKey change is that a string will no longer be accepted as an input, e.g.
"true"
is no longer accepted as aparseValue
input for Boolean.There is no change corresponding change for ID as coercion for ID was already aligned.
I tried to make coercion as close as possible, keeping in mind that JavaScript uses the floating point
Number
type to represent integer values.