Skip to content
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

GraphQL Java + GSON - Handling of ID types #2544

Open
treverj opened this issue Sep 9, 2021 · 1 comment
Open

GraphQL Java + GSON - Handling of ID types #2544

treverj opened this issue Sep 9, 2021 · 1 comment
Labels

Comments

@treverj
Copy link

treverj commented Sep 9, 2021

Describe the bug
Even though it has been discussed here and here about the use of GSON and the way it converts integers to double by treating them as numbers, and the work arounds to use LenientNumericalScalars, we have come across potentially 2 issues with how GraphQL Java handles them.

According to the GraphQL spec for id fields,

any string (such as "4") or integer (such as 4) input value should be coerced to ID as appropriate for the ID formats a given GraphQL server expects. Any other input value, including float input values (such as 4.0), must raise a query error indicating an incorrect type.

The 2 potential issues I see are:

  1. When a Double reaches GraphqlIDCoercing.parseValue, it is converted to a string and accepted rather than being rejected with CoercingParseValueException (whether this is because of GSON or not, it doesn't seem to get stopped before reaching here and will enter the execution as a String ending .0) - This may be me taking the above line from the spec too literally.
  2. With how GSON treats integers as Numbers, should the GraphqlIDCoercing class be able to handle integers that have come in as Double due to following how JS and Numbers work. Obviously for custom scalars this can be avoided, but is this something that should be natively handled for IDs. If not, should the docs be updated to include a recommended solution of overriding the default behaviour.

To Reproduce
Pass a value in with a .0 on the end for an ID field as a variable and you will receive a string version of that value but with .0 at the end. If you do the same with an actual double e.g. 3.5, you will get that as a string in the execution.

Copy link

Hello, this issue has been inactive for 60 days, so we're marking it as stale. If you would like to continue this discussion, please comment within the next 30 days or we'll close the issue.

@github-actions github-actions bot added the Stale label Dec 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants
@treverj and others