JSPM

graphql-bigint

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 7798
  • Score
    100M100P100Q122323F
  • License MIT

A 53-bit wide implementation of integers for GraphQL

Package Exports

  • graphql-bigint

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (graphql-bigint) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

graphql-bigint

A wider integer type for graphql-js than the default 32-bit GraphQLInt. This implementation gives you 53-bit integers.

The problem

The GraphQL spec limits its Int type to 32-bits. Maybe you've seen this error before:

GraphQLError: Argument "num" has invalid value 9007199254740990.
              Expected type "Int", found 9007199254740990.

Why? 64-bits would be too large for JavaScript's 53-bit limit. According to Lee Byron, a 52-bit integer spec would have been "too weird" see this issue.

Usage

$ npm install graphql-bigint

Use it the same as any other scalar type, either input or output.

const BigInt = require('graphql-bigint')

const SomeType = new GraphQLObjectType({
  name: 'SomeType',
  fields: {
    numberField: {
      type: BigInt,
      // this would throw an error with the GraphQLInt
      resolve: () => Number.MAX_SAFE_INTEGER 
    }
  }
})