Registry / devops / graphql-rest-router

graphql-rest-router

JSON →
library1.0.0-beta.0jsnpmunverified

GraphQL Rest Router (v1.0.0-beta.0) converts an internal GraphQL API into a REST API using a simple DSL, without exposing the full GraphQL schema. It ships with TypeScript types, supports caching (including Redis), generates Swagger/OpenAPI docs, and integrates with Express and Koa. Key differentiators: security against introspection attacks, client-side caching, and a declarative endpoint mapping DSL. Release cadence is irregular; currently in beta.

npm install graphql-rest-router
INSTALL
IMPORT
SIG · GRAPHQL-REST-ROUTE
G
graphql-rest-router
devopsjavascriptv1.0.0-beta.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.

GraphQLRestRouter
import GraphQLRestRouter from 'graphql-rest-router'
const GraphQLRestRouter = require('graphql-rest-router')
Default export is ESM-only; no CommonJS support.
GraphQLRestRouter
import GraphQLRestRouter from 'graphql-rest-router'
import { GraphQLRestRouter } from 'graphql-rest-router'
It is a default export, not a named export.
types
import type { Options } from 'graphql-rest-router'
TypeScript types are included and can be imported as type imports.

Creates a REST router that exposes three GraphQL queries as REST endpoints with caching and different HTTP methods.

import GraphQLRestRouter from 'graphql-rest-router'; import fs from 'fs'; const clientSchema = fs.readFileSync('./clientSchema.gql', 'utf-8'); const options = { defaultCacheTimeInMS: 10 }; const api = new GraphQLRestRouter('http://graphqlurl.com', clientSchema, options); api.mount('SearchUsers').at('/users'); api.mount('GetUserById').at('/users/:id'); api.mount('CreateUser').at('/users').as('post').withOption('cacheTimeInMs', 0); api.listen(3000, () => { console.log('GraphQL Rest Router is listening!'); });
Debug
Known issues
breakingBreaking changes from alpha to beta: API methods renamed and options restructured.
fix
Review the 'Upgrading From Alpha' section in the README; use new method signatures.
affects: <1.0.0-alpha
deprecatedThe default export is ESM-only; CommonJS require() is not supported.
fix
Use ESM imports (import) or use dynamic import() in a CJS context.
affects: >=1.0.0-beta.0
gotchaThe client schema file must define operations (queries/mutations) exactly as expected; mismatches cause runtime errors.
fix
Ensure the schema file contains the exact operation names used in api.mount().
affects: all
gotchaCache is in-memory by default; for distributed caches, Redis must be configured manually.
fix
Pass a Redis client or custom cache store in options.
affects: all
gotchaDynamic route parameters (e.g., :id) require the GraphQL query to accept a corresponding variable.
fix
Define the variable in the query (e.g., $id: ID!) and map it via the : parameter.
affects: all
Errors
Common errors & fixes
TypeError: graphql_rest_router_1.default is not a function
Using CommonJS require() on an ESM-only package.
fix
Switch to ESM: use import or set type: 'module' in package.json.
Error: Cannot find module 'graphql-rest-router'
Package not installed or wrong import path.
fix
Run 'npm install graphql-rest-router' and verify import path.
GraphQLRestRouter is not a constructor
Importing named export instead of default export.
fix
Use 'import GraphQLRestRouter from ...' without curly braces.
ReferenceError: fs is not defined
Missing import for fs module when reading schema file.
fix
Add 'import fs from 'fs';' at the top.
Upgrade
Version history
1.0.0-beta.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
8 hits · last 30 days
node
8
Resources
graphql-rest-router — npm install graphql-rest-router · libregistry