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 fails on a serialization of special float values #1811

Closed
fedinskiy opened this issue Dec 9, 2020 · 5 comments
Closed

GraphQL fails on a serialization of special float values #1811

fedinskiy opened this issue Dec 9, 2020 · 5 comments
Assignees
Labels
graphql Issues related to GraphQL module invalid

Comments

@fedinskiy
Copy link

Version

3.9.5

Context

When a Graphql server tries to return a special float value(NaN or one of the Infinites), it fails with the exception "Expected type 'Float' but was 'Float'."

Do you have a reproducer?

https://github.com/vert-x3/vertx-web/blob/907f4d638a01c00bcb71465c25d79094986204d3/vertx-web-graphql/src/test/java/io/vertx/ext/web/handler/graphql/ReproduceServer.java

Steps to reproduce

  1. Create a GraphQL server with a Float field
  2. Make the wiring return Float.NaN, Float.POSITIVE_INFINITY or Float.NEGATIVE_INFINITY for this field
  3. Start the server and query the field from a client

Expected result: some data is received
Actual result: Error with message "Can't serialize value (/${fieldname}) : Expected type 'Float' but was 'Float'."

Extra

Java 8

Also, it looks like the cause of the bug lies in the GraphQL java library, which uses BigDecimal for serialization of float values. And according to its documentation, BigDecimal is unable to handle NaN and ±Infinity.

@fedinskiy fedinskiy added the bug Something isn't working label Dec 9, 2020
@tsegismont tsegismont self-assigned this Dec 9, 2020
@tsegismont tsegismont added bug graphql Issues related to GraphQL module and removed bug Something isn't working labels Dec 9, 2020
@tsegismont
Copy link
Contributor

According to the spec, NaN should be transformed to null.

Can you report the issue to GraphQL-Java?

@fedinskiy
Copy link
Author

@tsegismont, yes, will do it tomorrow.

@fedinskiy
Copy link
Author

@tsegismont it looks like they already have issues for NaNs (graphql-java/graphql-java#1062) and for infinities (graphql-java/graphql-java#1998). If I understand correctly, the implementation was created before the specification was updated to describe a proper handling of NaNs.
As a side note, there is an ongoing proposal to remove NaNs and Infinities from the specification: graphql/graphql-spec/pull/780

@tsegismont tsegismont added invalid and removed bug labels Dec 10, 2020
@tsegismont
Copy link
Contributor

@fedinskiy thanks for letting us know. I'm closing the issue as this is something that needs to be handled in either user's code or GraphQL-Java

@glasser
Copy link

glasser commented Dec 10, 2020

@fedinskiy I'd describe my proposal as a clarification of the language in the spec rather than a removal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
graphql Issues related to GraphQL module invalid
Development

No branches or pull requests

3 participants