parseValue coercion alignment for Boolean, Float, and Int#3042
Merged
parseValue coercion alignment for Boolean, Float, and Int#3042
Conversation
dondonz
commented
Dec 5, 2022
|
|
||
| if (result.compareTo(INT_MIN) < 0 || result.compareTo(INT_MAX) > 0) { | ||
| throw new CoercingParseValueException( | ||
| i18nMsg(locale, "Int.outsideRange", result.toString()) |
Member
Author
There was a problem hiding this comment.
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
dondonz
commented
Dec 5, 2022
| 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 |
Member
Author
There was a problem hiding this comment.
Moved into separate test below
dondonz
commented
Dec 5, 2022
| 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 |
Member
Author
There was a problem hiding this comment.
Moved into separate test below
bbakerman
approved these changes
Dec 5, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Aligning
parseValuecoercion 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 aparseValueinput 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
Numbertype to represent integer values.