Registry / database / graphql-input-number

graphql-input-number

JSON →
library0.0.10jsnpmunverified

A configurable custom input number scalar type for GraphQL with built-in sanitization and validation for integer and float values. Current stable version 0.0.10. Provides factory functions GraphQLInputInt and GraphQLInputFloat that generate GraphQL scalar types with configurable min/max, sanitize, test, parse, and error handling. Differentiators: lightweight, no other dependencies beyond graphql peer, simple API for defining numeric constraints directly in schema.

npm install graphql-input-number
INSTALL
IMPORT
SIG · GRAPHQL-INPUT-NUMB
G
graphql-input-number
databasejavascriptv0.0.10
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.

GraphQLInputInt
import { GraphQLInputInt } from 'graphql-input-number'
const GraphQLInputInt = require('graphql-input-number').GraphQLInputInt;
Package uses CommonJS internally but supports ESM usage. Named export.
GraphQLInputFloat
import { GraphQLInputFloat } from 'graphql-input-number'
import GraphQLInputFloat from 'graphql-input-number';
Import the named export, not default. Both are factory functions.
GraphQLInputInt as GraphQLSafeInt
import { GraphQLInputInt as GraphQLSafeInt } from 'graphql-input-number'
import { GraphQLSafeInt } from 'graphql-input-number'
If you rename, use the original named export with an alias.

Creates a custom PositiveInt scalar that validates integer >= 0 and uses it in a GraphQL schema.

import { GraphQLInputInt, GraphQLInputFloat } from 'graphql-input-number'; import { GraphQLObjectType, GraphQLInt, GraphQLSchema } from 'graphql'; const PositiveInt = GraphQLInputInt({ name: 'PositiveInt', min: 0, description: 'Integers >= 0' }); const QueryType = new GraphQLObjectType({ name: 'Query', fields: { double: { type: GraphQLInt, args: { n: { type: PositiveInt } }, resolve: (_, { n }) => n * 2 } } }); export const schema = new GraphQLSchema({ query: QueryType });
Debug
Known issues
gotchaThe 'name' option is REQUIRED but not enforced at runtime for GraphQLInputInt/GraphQLInputFloat calls; forgetting it may cause cryptic errors.
fix
Always provide a unique 'name' string that matches GraphQL type naming rules.
affects: >=0.0.0
gotchaPackage has not been updated since 2016; may not support newer graphql versions (v15/v16) properly.
fix
Test with your graphql version; consider alternatives like graphql-scalars.
affects: >=0.0.10
breakingThe 'sanitize' option is called before validation, but it may convert number to non-number, causing unexpected errors.
fix
Ensure sanitize returns a number, or handle the converted value in validation/test.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: Cannot read property 'name' of undefined
Calling GraphQLInputInt() without the 'name' option.
fix
Provide a name: GraphQLInputInt({ name: 'MyInt', min: 1 })
GraphQLError: Expected type Float!
Using GraphQLInputFloat but passing an integer value that fails validation.
fix
Check min/max constraints; ensure value is a number.
GraphQLError: Variable \"$n\" got invalid value \"abc\". Expected type PositiveInt.
Passing a non-numeric string to a field with GraphQLInputInt/GraphQLInputFloat.
fix
Ensure input is a valid number. The package only validates numbers, not converts strings.
Upgrade
Version history
0.0.10latest on npm
Audit
Dependencies
graphqlrequiredPeer dependency; provides GraphQLScalarType constructor and GraphQLError.
Agent activity
6 hits · last 30 days
node
6
Resources
graphql-input-number — npm install graphql-input-number · libregistry