Skip to content

Spec should be more explicit about whether NaN and Inf are valid Floats #778

Closed
@glasser

Description

@glasser

The spec documents the Float type as representing "signed double‐precision fractional values as specified by IEEE 754".

In addition to "normal" finite numbers, IEEE 754 includes NaN and positive and negative infinity.

A plain reading of section 3.5.2 would imply that the GraphQL Float type includes all IEEE 754 values, not just the finite ones.

However, I don't believe this is the intent. First, you cannot express these values as literals, which is very clear in the definition of FloatValue. Secondly, the reference implementation GraphQL-JS explicitly rejects non-finite values (introduced by @IvanGoncharov in graphql/graphql-js#1365 and @leebyron in graphql/graphql-js#1382).

The only allusion to NaN in the spec is in the value completion section which it suggests that mapping NaN to null may be appropriate (I don't believe graphql-js does this, though).

I think the right fix is to change the Float section to be clear that only IEEE 754 finite values are part of the Float type (and maybe to remove the note about NaN mapping to null). Happy to send a PR if folks agree.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions