Registry / testing / graphql-scalar

graphql-scalar

JSON →
library0.1.0jsnpmunverified

graphql-scalar v0.1.0 is a TypeScript library for creating configurable custom GraphQL scalars with built-in sanitization, validation, and transformation. It provides factory functions like createStringScalar, createIntScalar, and createFloatScalar that accept options for constraints (min/max length, pattern, numeric range) and hooks (coerce, parse, sanitize, serialize, validate). The package ships with type declarations and has peer dependencies on graphql and tslib (^1.10.0). It supersedes older packages (graphql-input-number, graphql-input-string) with breaking changes. Release cadence is low; no recent updates. Key differentiators include TypeScript first-class support and a unified API for creating scalars with common patterns. Note: tslib peer dependency may cause issues with TypeScript projects using importHelpers.

npm install graphql-scalar
INSTALL
IMPORT
SIG · GRAPHQL-SCALAR
G
graphql-scalar
testingjavascriptv0.1.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.

createStringScalar
import { createStringScalar } from 'graphql-scalar'
const createStringScalar = require('graphql-scalar')
Library exports ESM-style named exports. CommonJS require will not work directly without default interop.
createIntScalar
import { createIntScalar } from 'graphql-scalar'
import createIntScalar from 'graphql-scalar'
Default export is not available; always use named import.
createFloatScalar
import { createFloatScalar } from 'graphql-scalar'
import { createFloatScalar } from 'graphql-scalar/src'
Do not import from source path; it will break bundler resolution. Use top-level package.

Shows creation of custom string and integer GraphQL scalars with validation options and schema usage.

import { createStringScalar, createIntScalar, createFloatScalar } from 'graphql-scalar'; import { GraphQLSchema, GraphQLObjectType, GraphQLString } from 'graphql'; const StringScalar = createStringScalar({ name: 'SafeString', minLength: 1, maxLength: 100, trim: true, nonEmpty: true, lowercase: true }); const IntScalar = createIntScalar({ name: 'PositiveInt', minimum: 0, maximum: 1000 }); const schema = new GraphQLSchema({ query: new GraphQLObjectType({ name: 'Query', fields: { test: { type: StringScalar, resolve: () => 'Hello' } } }) }); console.log(schema);
Debug
Known issues
breakingv0.1.0 is a rewrite from previous graphql-input-number and graphql-input-string packages; API completely changed.
fix
Migrate to new createStringScalar/createIntScalar factories; consult docs for new option names.
affects: >=0.0.0 <0.1.0
gotchatslib peer dependency not automatically installed; missing tslib leads to runtime errors due to missing __importStar helper.
fix
Run 'npm install tslib' or set TypeScript compilerOptions.importHelpers to false (not recommended).
affects: >=0.1.0
gotchaCommonJS require() may not work due to ESM-first export pattern; require may return an object with .default missing.
fix
Use import syntax or configure bundler to handle ESM interop.
affects: >=0.1.0
deprecatedPackage hasn't been updated for years; may not support GraphQL v16+ (peer dep allows any version but might have compatibility issues).
fix
Check compatibility with your GraphQL version; consider alternatives like graphql-type-json or custom scalars.
affects: >=0.1.0
Errors
Common errors & fixes
Cannot find module 'tslib'
Missing tslib peer dependency when using the library in a TypeScript project that uses importHelpers.
fix
npm install tslib
TypeError: createStringScalar is not a function
Using default import or wrong import syntax; package exposes named exports only.
fix
Use import { createStringScalar } from 'graphql-scalar'
GraphQLError: Expected type "SafeString" to be a GraphQL named type
Passing invalid schema definition; scalar must be used as a GraphQLOutputType, not a GraphQLScalarTypeConfig.
fix
Ensure createStringScalar returns a GraphQLScalarType, then use it directly in schema fields.
Upgrade
Version history
0.1.0latest on npm
Audit
Dependencies
graphqlrequiredRequired to use GraphQL types; err if missing.
tsliboptionalRequired for TypeScript compiled output that uses __importStar, etc.; visible if project doesn't set importHelpers.
Agent activity
6 hits · last 30 days
node
6
Resources
graphql-scalar — npm install graphql-scalar · libregistry