Skip to content

Number-based scalars are violating GraphQL Specification for NaN #2915

@robross0606

Description

@robross0606

Issue workflow progress

Progress of the issue based on the
Contributor Workflow

  • 1. The issue provides a reproduction available on GitHub, Stackblitz or CodeSandbox

    Make sure to fork this template and run yarn generate in the terminal.

    Please make sure the GraphQL Scalars package version under package.json matches yours.

  • 2. A failing test has been provided
  • 3. A local solution has been provided
  • 4. A pull request is pending review

Describe the bug

If the value returned on a query resolver through a scalar like PositiveInt is NaN, the library is violating the GraphQL Specification by throwing an error:

Value is not a finite number: NaN

As per the specification:

  1. If result is null (or another internal value similar to null such as undefined or NaN), return null.

To Reproduce Steps to reproduce the behavior:

Resolve a scalar value such as PositiveInt as NaN.

Expected behavior

Should return a null and not throw an error unless the value is required (i.e. PositiveInt!).

Environment:

  • OS: Microsoft Windows [Version 10.0.19045.6396]
  • GraphQL Scalars Version: 1.24.2
  • NodeJS: 24.9.0

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