Registry / testing / json-graphql-server

json-graphql-server

JSON →
library3.3.1jsnpmunverified

json-graphql-server version 3.3.1 is a zero-configuration GraphQL testing and mocking tool for Node.js. Given a JSON data file or JavaScript module exporting arrays of entities, it spins up a full GraphQL API (queries, mutations, filters, pagination, sorting, and relationships) on localhost in under 30 seconds, no schema writing needed. Released under MIT with contributors from Marmelab; updates are infrequent but stable. Compared to alternatives like json-graphql-mocker or graphql-faker, this tool provides automatic schema generation and GraphiQL IDE out of the box, but does not support authentication, custom resolvers, or complex business logic.

npm install json-graphql-server
INSTALL
IMPORT
SIG · JSON-GRAPHQL-SERVE
J
json-graphql-server
testingjavascriptv3.3.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.

default (express middleware)
const jsonGraphqlServer = require('json-graphql-server');
import jsonGraphqlServer from 'json-graphql-server';
The library exports an Express middleware function via CommonJS. ESM import with default may fail before version 4 (if ever). Use require or dynamic import().
expressMiddleware
const expressMiddleware = require('json-graphql-server').default || require('json-graphql-server');
import { expressMiddleware } from 'json-graphql-server';
The package does not export named 'expressMiddleware' in v3.3.1. Use the default export or check docs for exact export name.
graphqlSchema
const { graphql } = require('json-graphql-server');
import { graphql } from 'json-graphql-server';
The library may export a 'graphql' function for building schema. Not well documented; prefer using the CLI or middleware.

Create a data file exporting entity arrays, then start server via CLI or programmatic middleware for zero-config GraphQL API.

// db.js module.exports = { posts: [ { id: 1, title: "Hello", views: 100, user_id: 10 }, { id: 2, title: "World", views: 200, user_id: 20 } ], users: [ { id: 10, name: "Alice" }, { id: 20, name: "Bob" } ] };
Debug
Known issues
gotchaSchema generation inflects entity names; 'posts' becomes 'Post' type, 'allPosts' query. Ensure consistent plural/singular.
fix
Name your keys as plural lowercase (e.g., 'posts', 'users') to match expected conventions.
affects: >=2.0 <4.0
breakingMutations return 'data' and 'error' fields; error handling differs from standard GraphQL as errors may be in 'error' key instead of 'errors' array.
fix
Check both 'errors' and 'error' in response; prefer using the 'graphql-http' client for compatibility.
affects: >=3.0 <4.0
deprecatedCLI option '--p' for port is deprecated in favor of '--port' (full name).
fix
Use '--port' instead of '-p' or '--p'.
affects: >=3.0
gotchaIDs must be unique across all entities of the same type; duplicate IDs cause undefined behavior.
fix
Ensure each entity in an array has a unique 'id' field, numeric or string.
affects: >=1.0
Errors
Common errors & fixes
Error: Cannot find module 'json-graphql-server'
Package not installed or globally installed when using npx without local install.
fix
Run 'npm install -D json-graphql-server' in your project, or use 'npx json-graphql-server' with care (must be installed).
TypeError: jsonGraphqlServer is not a function
Using ESM import (import jsonGraphqlServer from 'json-graphql-server') which does not work because package uses CommonJS default export.
fix
Use require: const jsonGraphqlServer = require('json-graphql-server');
GraphQLError: Cannot query field "allPosts" on type "Query"
The data file has key 'posts' but the schema generated 'Post' type and 'allPosts' query; querying 'allPost' (typo) fails.
fix
Check your entity key names and use correct query names (e.g., 'allPosts', 'allUsers').
Upgrade
Version history
3.3.1latest on npm
Audit
Dependencies
graphqlrequiredPeer dependency for GraphQL execution and schema construction
inflectionrequiredUsed for pluralization/singularization of entity names in generated schema
Agent activity
47 hits · last 30 days
node
42
OpenAI (training)
1
Resources
json-graphql-server — npm install json-graphql-server · libregistry