Skip to content

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

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

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.

3 participants