graphql-bigint
A 53-bit wide implementation of integers for GraphQL
Last updated 9 years ago by acarl005 .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install graphql-bigint 
SYNC missed versions from official npm registry.

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 
    }
  }
})

Current Tags

  • 1.0.0                                ...           latest (9 years ago)

1 Versions

  • 1.0.0                                ...           9 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 1
Last Month 1
Dependencies (0)
None
Dev Dependencies (3)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |