Registry / api / graphql-bigint

graphql-bigint

JSON →
library1.0.0jsnpmunverified

Provides a 53-bit wide integer scalar for graphql-js, extending the default 32-bit GraphQLInt to cover JavaScript's safe integer range (Number.MAX_SAFE_INTEGER). Current stable version is 1.0.0. No recent updates; the library is simple and stable. Key differentiator: unlike alternatives like GraphQLInt, it accepts values up to 2^53-1, solving the common 'Invalid value' error for large integers.

npm install graphql-bigint
INSTALL
IMPORT
SIG · GRAPHQL-BIGINT
G
graphql-bigint
apijavascriptv1.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import BigInt from 'graphql-bigint'
const BigInt = require('graphql-bigint').default
CommonJS requires the default export directly; named exports are not provided.
default
const BigInt = require('graphql-bigint')
const { BigInt } = require('graphql-bigint')
The package exports a single default value, not a named export.
GraphQLBigInt
import GraphQLBigInt from 'graphql-bigint'
import { GraphQLBigInt } from 'graphql-bigint'
The scalar is custom-named as GraphQLBigInt in some contexts, but the package only exports a default.

Creates a GraphQL schema with a BigInt field to handle large integers.

const { GraphQLObjectType, GraphQLSchema, GraphQLString } = require('graphql'); const BigInt = require('graphql-bigint'); const UserType = new GraphQLObjectType({ name: 'User', fields: () => ({ id: { type: BigInt }, name: { type: GraphQLString } }) }); const schema = new GraphQLSchema({ query: UserType }); console.log('Schema using BigInt created');
Debug
Known issues
gotchaThe BigInt scalar accepts only integers up to Number.MAX_SAFE_INTEGER (2^53-1); values outside that range will cause precision loss.
fix
Use a string-based BigInt scalar if you need arbitrary precision beyond 53 bits.
affects: all
gotchaThe scalar does not validate non-integer values (e.g., floats) – they will be accepted and truncated.
fix
Coerce values with Math.floor() or similar before returning from resolvers.
affects: all
deprecatedThe package uses CommonJS only; no ESM exports are provided.
fix
Use dynamic import or a bundler that handles CommonJS.
affects: all
Errors
Common errors & fixes
TypeError: BigInt is not a constructor
Importing the default export incorrectly as a named export.
fix
Use `const BigInt = require('graphql-bigint')` or `import BigInt from 'graphql-bigint'`.
GraphQLError: Argument "num" has invalid value 9007199254740990. Expected type "Int", found 9007199254740990.
Using the default GraphQLInt scalar with a value larger than 32 bits.
fix
Use graphql-bigint's BigInt scalar for such values.
Cannot find module 'graphql-bigint'
Package not installed or missing from dependencies.
fix
Run `npm install graphql-bigint`.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
graphqlrequiredPeer dependency; library is a GraphQL scalar type used with graphql-js
Agent activity
40 hits · last 30 days
node
36
OpenAI (training)
1
Resources
graphql-bigint — npm install graphql-bigint · libregistry