Skip to content

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

Merged
merged 6 commits into from
Dec 6, 2022

Conversation

dondonz
Copy link
Member

@dondonz dondonz commented Dec 5, 2022

Aligning parseValue coercion to be closer to the JavaScript reference implementation https://github.com/graphql/graphql-js/blob/main/src/type/scalars.ts

Key change is that a string will no longer be accepted as an input, e.g. "true" is no longer accepted as a parseValue 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.


if (result.compareTo(INT_MIN) < 0 || result.compareTo(INT_MAX) > 0) {
throw new CoercingParseValueException(
i18nMsg(locale, "Int.outsideRange", result.toString())
Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Member Author

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

@dondonz dondonz added this to the 20.0 milestone Dec 5, 2022
@dondonz dondonz added the breaking change requires a new major version to be relased label Dec 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change requires a new major version to be relased
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants