Registry / testing / graphql-schema-from-json

graphql-schema-from-json

JSON →
library0.0.3jsnpmunverified

A library that infers a GraphQL schema from example JSON data, generating types, queries, and mutations. Version 0.0.3 is the latest. It guesses types, relationships (based on field naming like `*_id`), and provides CRUD operations with pagination and filtering. Release cadence is low, with few updates. Key differentiator: zero-config schema generation from sample data, useful for prototyping or mocking APIs.

npm install graphql-schema-from-json
INSTALL
IMPORT
SIG · GRAPHQL-SCHEMA-FRO
G
graphql-schema-from-json
testingjavascriptv0.0.3
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.

getSchemaFromData
import getSchemaFromData from 'graphql-schema-from-json'
import { getSchemaFromData } from 'graphql-schema-from-json'
Default export only; named import will fail.
printSchema
import { printSchema } from 'graphql'
import printSchema from 'graphql'
printSchema is a named export from graphql library.
GraphQLSchema
import { GraphQLSchema } from 'graphql'
TypeScript users may need to import types separately.

Shows how to generate a GraphQL schema from sample JSON data and print it using graphql library.

import getSchemaFromData from 'graphql-schema-from-json'; import { printSchema } from 'graphql'; const data = { posts: [{ id: 1, title: "Lorem Ipsum", views: 254, user_id: 123 }], users: [{ id: 123, name: "John Doe" }], comments: [{ id: 987, post_id: 1, body: "Consectetur adipiscing elit", date: new Date('2017-07-03') }] }; const schema = getSchemaFromData(data); console.log(printSchema(schema));
Debug
Known issues
gotchaPackage name has changed from 'graphql-schema-from-json' to 'graphql-schema-from-json' (original). No breaking changes.
fix
Use latest version 0.0.3.
affects: <0.0.3
gotchaGenerated schema expects all entities to have an 'id' field; missing id will cause errors in relationships.
fix
Ensure JSON data includes 'id' fields for each entity.
affects: >=0.0.1
gotchaScalar type 'Date' is generated for Date objects, but GraphQL does not natively support Date; you need a custom scalar resolver.
fix
Add a custom Date scalar resolver to your GraphQL server.
affects: >=0.0.1
Errors
Common errors & fixes
TypeError: getSchemaFromData is not a function
Incorrect import (named import instead of default import).
fix
Use `import getSchemaFromData from 'graphql-schema-from-json'` instead of `import { getSchemaFromData } from '...'`
Cannot find module 'graphql'
Missing dependency graphql.
fix
Run `npm install --save graphql`.
Returned schema has no queries defined
JSON data may not be an object with arrays as values or no id fields.
fix
Ensure data is an object where each key maps to an array of objects with 'id' fields.
Upgrade
Version history
0.0.3latest on npm
Audit
Dependencies
graphqlrequiredRequired for GraphQL type definitions and schema printing.
Agent activity
6 hits · last 30 days
node
6
Resources
graphql-schema-from-json — npm install graphql-schema-from-json · libregistry