Registry / devops / graphql-query-rewriter-rc

graphql-query-rewriter-rc

JSON →
library0.0.19jsnpmunverified

A library that rewrites GraphQL queries in middleware to turn breaking schema changes into non-breaking ones, avoiding the need for versioned fields like `doTheThingV3`. Current stable version is 0.0.19, with no active release cadence (last updated in 2021). Key differentiator: allows schema changes (e.g., `String!` to `ID!`) without breaking old clients, by rewriting queries at the middleware level. Supports express-graphql and Apollo Server. Ships with TypeScript types and has peer dependency on GraphQL 14 or 15.

npm install graphql-query-rewriter-rc
INSTALL
IMPORT
SIG · GRAPHQL-QUERY-REWR
G
graphql-query-rewriter-rc
devopsjavascriptv0.0.19
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.

FieldArgTypeRewriter
import { FieldArgTypeRewriter } from 'graphql-query-rewriter'
const FieldArgTypeRewriter = require('graphql-query-rewriter').FieldArgTypeRewriter
Package is ESM-only; require() will not work.
graphqlRewriterMiddleware
import { graphqlRewriterMiddleware } from 'express-graphql-query-rewriter'
import { graphqlRewriterMiddleware } from 'graphql-query-rewriter'
Middleware adapter is a separate package; must import from framework-specific package.
Rewriter
import { Rewriter } from 'graphql-query-rewriter'
Base class for custom rewriters.

Sets up middleware to automatically rewrite GraphQL queries, replacing a field argument type from String! to ID! seamlessly.

import { FieldArgTypeRewriter } from 'graphql-query-rewriter'; import { graphqlRewriterMiddleware } from 'express-graphql-query-rewriter'; import express from 'express'; import { graphqlHTTP } from 'express-graphql'; const app = express(); const rewriters = [ new FieldArgTypeRewriter({ fieldName: 'userById', argName: 'id', oldType: 'String!', newType: 'ID!', }), ]; app.use('/graphql', graphqlRewriterMiddleware({ rewriters })); app.use('/graphql', graphqlHTTP({ schema })); app.listen(4000); console.log('Running a GraphQL API server at http://localhost:4000/graphql');
Debug
Known issues
gotchaPackage version 0.0.19 is a pre-major release and API may change incompatibly.
fix
Pin to exact version and test upgrades thoroughly.
affects: <1.0.0
deprecatedPeer dependency supports GraphQL v14 and v15 only; GraphQL v16 is not supported.
fix
Use graphql@15 or older, or look for alternative packages.
affects: >=16.0.0
gotchaMiddleware package 'express-graphql-query-rewriter' is separate and must be installed alongside the core package.
fix
npm install graphql-query-rewriter express-graphql-query-rewriter
affects: >=0.0.0
gotchaThe package requires ESM imports; CommonJS require() will fail.
fix
Use ES module imports (e.g., import ... from 'graphql-query-rewriter').
affects: >=0.0.0
gotchaRewriters must be applied in middleware before the GraphQL handler; order matters.
fix
Place graphqlRewriterMiddleware before graphqlHTTP in middleware stack.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'graphql-query-rewriter'
Core package not installed separately from middleware adapter.
fix
Run npm install graphql-query-rewriter express-graphql-query-rewriter
Expected argument of type 'String!' but got type 'ID!'
FieldArgTypeRewriter misconfigured with incorrect type strings (missing '!' or wrong casing).
fix
Ensure oldType and newType match exactly the schema's type strings (e.g., 'String!' not 'string').
TypeError: graphqlRewriterMiddleware is not a function
Importing from wrong package (core instead of adapter) or using CommonJS require.
fix
Use ES import: import { graphqlRewriterMiddleware } from 'express-graphql-query-rewriter'
Upgrade
Version history
0.0.19latest on npm
Audit
Dependencies
graphqlrequiredpeer dependency required for GraphQL schema operations
Agent activity
9 hits · last 30 days
node
8
Amazon
1
Resources
graphql-query-rewriter-rc — npm install graphql-query-rewriter-rc · libregistry