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-scalarNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows creation of custom string and integer GraphQL scalars with validation options and schema usage.
Migrate to new createStringScalar/createIntScalar factories; consult docs for new option names.
Run 'npm install tslib' or set TypeScript compilerOptions.importHelpers to false (not recommended).
Use import syntax or configure bundler to handle ESM interop.
Check compatibility with your GraphQL version; consider alternatives like graphql-type-json or custom scalars.
npm install tslib
Use import { createStringScalar } from 'graphql-scalar'Ensure createStringScalar returns a GraphQLScalarType, then use it directly in schema fields.