Registry / devops / graphql2rest

graphql2rest

JSON →
library1.0.1jsnpmunverified

Automatically generate a RESTful API from your existing GraphQL API. This Node.js library reads your GraphQL schema and a user-provided manifest file to generate an Express router with fully RESTful HTTP routes. v1.0.1 is the current stable version, released under MIT license by Sisense. Key differentiators: supports any GraphQL server execution function, customizable endpoints mapping, and allows you to have both GraphQL and REST APIs from a single schema with full control over REST configuration.

npm install graphql2rest
INSTALL
IMPORT
SIG · GRAPHQL2REST
G
graphql2rest
devopsjavascriptv1.0.1
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.

GraphQL2REST
import GraphQL2REST from 'graphql2rest';
const GraphQL2REST = require('graphql2rest');
ESM-only since v1.0.0, no CommonJS support.
type GraphQL2RESTConfig
import type { GraphQL2RESTConfig } from 'graphql2rest';
Type imported for TypeScript type checking.
default (with express)
import express from 'express'; import GraphQL2REST from 'graphql2rest';
const express = require('express'); const GraphQL2REST = require('graphql2rest');
Express must be used alongside graphql2rest. Both are ESM-only.

Shows full setup: generate query files from schema, initialize router with manifest, and mount on Express app.

import express from 'express'; import path from 'path'; import { fileURLToPath } from 'url'; import GraphQL2REST from 'graphql2rest'; import { execute } from 'graphql'; import { schema } from './myGraphQLSchema.js'; import { readFileSync } from 'fs'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); const gqlGeneratorOutputFolder = path.resolve(__dirname, './gqlFilesFolder'); const manifestFile = path.resolve(__dirname, './manifest.json'); // One-time pre-processing GraphQL2REST.generateGqlQueryFiles(schema, gqlGeneratorOutputFolder); // Initialize REST router const restRouter = GraphQL2REST.init(schema, execute, { gqlGeneratorOutputFolder, manifestFile }); const app = express(); app.use('/api', restRouter); app.listen(4000, () => { console.log('REST API listening on port 4000'); });
Debug
Known issues
gotchagenerateGqlQueryFiles must be called once before init, otherwise init will fail with missing files.
fix
Ensure generateGqlQueryFiles is called first, typically as a build step or at startup before calling init.
affects: >=1.0.0
gotchaThe execute function must match the signature expected by graphql2rest (standard GraphQL execute). Using a custom execute with different arguments will break.
fix
Use graphql's execute function or wrap your custom executor to match the standard signature.
affects: >=1.0.0
gotchaThe manifest file path must be absolute or relative to process.cwd(), not relative to the script file.
fix
Use path.resolve(__dirname, 'manifest.json') to ensure correct path resolution.
affects: >=1.0.0
deprecatedVersion 1.0 is the first stable release; no deprecation warnings yet, but be aware future versions may change internal APIs.
fix
Pin to exact version in package.json and review changelog before upgrading.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'graphql2rest'
Package not installed or import path incorrect.
fix
Run 'npm install graphql2rest' and ensure your project uses ESM (type: module in package.json or .mjs extension).
TypeError: GraphQL2REST.generateGqlQueryFiles is not a function
Incorrect import style (CommonJS require used instead of ESM import).
fix
Replace 'const GraphQL2REST = require("graphql2rest")' with 'import GraphQL2REST from "graphql2rest"'.
Error: ENOENT: no such file or directory, open '.../gqlFilesFolder'
generateGqlQueryFiles not called or output folder does not exist.
fix
Call GraphQL2REST.generateGqlQueryFiles(schema, './gqlFilesFolder') before calling init, or create the folder manually.
Error: Manifest file not found at path: ./manifest.json
Manifest file path is incorrect or file missing.
fix
Ensure manifest.json exists at the specified path and use absolute path with path.resolve(__dirname, 'manifest.json').
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
expressrequiredGenerates Express router for RESTful routes
Agent activity
6 hits · last 30 days
node
6
Resources
graphql2rest — npm install graphql2rest · libregistry