Registry / testing / graphql-transform-scalars

graphql-transform-scalars

JSON →
library2.2.0jsnpmunverified

GraphQL response transformer for custom scalars. Version 2.2.0. Enables transforming scalar values in GraphQL responses from client-side requests (e.g., with graphql-request) using user-defined mapper functions. Requires graphql >= 15 and a local schema/operations file for type resolution. Unlike server-side scalar handling, this library works on the client after receiving the response. Ships TypeScript types. Actively maintained with regular releases.

npm install graphql-transform-scalars
INSTALL
IMPORT
SIG · GRAPHQL-TRANSFORM-
G
graphql-transform-scalars
testingjavascriptv2.2.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.

TransformCustomScalars
import { TransformCustomScalars } from 'graphql-transform-scalars'
const TransformCustomScalars = require('graphql-transform-scalars').TransformCustomScalars
ESM default: named export. CJS works but named import is standard.
getSdkWrapper
import { getSdkWrapper } from 'graphql-transform-scalars'
const getSdkWrapper = require('graphql-transform-scalars').getSdkWrapper
ESM named export. Used with graphql-codegen generated SDK.
TransformCustomScalars (require)
const { TransformCustomScalars } = require('graphql-transform-scalars')
const TransformCustomScalars = require('graphql-transform-scalars')
CJS requires destructuring for named export. Direct require returns module object.

Shows how to instantiate TransformCustomScalars with custom scalar definitions, schema, and operations for client-side scalar transformation.

import { TransformCustomScalars } from 'graphql-transform-scalars'; import fs from 'fs'; const schema = fs.readFileSync('schema.graphql', 'utf8'); const operations = fs.readFileSync('operations.graphql', 'utf8'); const customScalarDefinitions = [ { name: 'Date', parseValue: (val: unknown) => new Date(val as string), }, ]; const transformScalars = new TransformCustomScalars({ transformDefinitions: customScalarDefinitions, schema, operations, }); // Use with graphql-request SDK wrapper // import { getSdkWrapper } from 'graphql-transform-scalars'; // const sdk = getSdk(client, getSdkWrapper(transformScalars));
Debug
Known issues
gotchaSchema and operations files must be provided as strings (e.g., read from files). Missing them causes runtime errors.
fix
Provide both 'schema' and 'operations' options to TransformCustomScalars constructor.
affects: >=2.0.0
deprecatedparseValue in transformDefinitions expects a single function, not an object with serialize/parseValue/parseLiteral.
fix
Use parseValue only. For full GraphQLScalarType, use separate import from graphql.
affects: >=2.0.0
gotchagetSdkWrapper only works with graphql-codegen generated SDKs. Not a general-purpose wrapper.
fix
Ensure you are using graphql-codegen with the appropriate plugin (e.g., graphql-request).
affects: >=2.0.0
gotchaThe library does not handle server-side scalar serialization; it only transforms client-side responses.
fix
Use GraphQLScalarType definitions for server-side handling.
affects: all
breakingVersion 2.x changed the constructor options from an object with separate properties to a single config object.
fix
Pass a single object with { transformDefinitions, schema, operations }.
affects: >=2.0.0 <3.0.0
Errors
Common errors & fixes
TypeError: schema must be a string
Missing or invalid schema argument in TransformCustomScalars constructor.
fix
Pass a valid GraphQL schema string via the 'schema' option.
Error: Cannot find module 'graphql'
Missing peer dependency graphql.
fix
Run 'npm install graphql' or 'yarn add graphql'.
TypeError: transformDefinitions is not iterable
transformDefinitions not provided or not an array.
fix
Provide an array of objects with 'name' and 'parseValue' functions.
Upgrade
Version history
2.2.0latest on npm
Audit
Dependencies
graphqlrequiredPeer dependency for GraphQL types and schema parsing
Agent activity
6 hits · last 30 days
node
6
Resources
graphql-transform-scalars — npm install graphql-transform-scalars · libregistry