Skip to content

Handling of NaN on Int scalar violates GraphQL Specification #4488

@robross0606

Description

@robross0606

When resolving an output value through Int scalar, NaN causes an error to be thrown:

Int cannot represent non-integer value: NaN

  const schema = makeExecutableSchema({
    typeDefs: /* GraphQL */ `
    type Query {
      testInt: Int
    }
  `,
    resolvers: {
      Query: {
        testInt: () => NaN,
      },
    },
  });
  const query = parse(/* GraphQL */ `query {
    testInt
  }`);
  const result = executeSync({
    schema,
    document: query,
  });
  expect(result).toEqual({ data: { testInt: null }, errors: [expect.objectContaining({ message: 'Int cannot represent non-integer value: NaN' })] });

However, the GraphQL Specification states that NaN should be coerced to null and returned:

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

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