Registry / devops / graphql-2-json-schema

graphql-2-json-schema

JSON →
library0.10.0jsnpmunverified

Transforms GraphQL schema introspection data into a valid JSON Schema (draft-06). Current stable version is 0.10.0, maintained as needed. Key differentiators: supports GraphQL unions, input types, enums, descriptions, default values, nullable array items, and configurable ID scalar mapping. Lightweight with no production dependencies beyond GraphQL itself. Suitable for generating JSON Schema from GraphQL schemas for documentation or validation purposes.

npm install graphql-2-json-schema
INSTALL
IMPORT
SIG · GRAPHQL-2-JSON-SCH
G
graphql-2-json-schema
devopsjavascriptv0.10.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.

fromIntrospectionQuery
import { fromIntrospectionQuery } from 'graphql-2-json-schema'
const { fromIntrospectionQuery } = require('graphql-2-json-schema')
Package ships TypeScript definitions. Named export only, no default export. Works in both ESM and CJS environments.
fromIntrospectionQuery (type)
import type { fromIntrospectionQuery } from 'graphql-2-json-schema'
import { fromIntrospectionQuery } from 'graphql-2-json-schema' // when only type needed
For TypeScript, use 'import type' if you only need the type of the function (though it's a value). Correct use: import { fromIntrospectionQuery } from 'graphql-2-json-schema' is fine for both.
GraphQLJsonSchemaOptions
import { GraphQLJsonSchemaOptions } from 'graphql-2-json-schema'
import { Options } from 'graphql-2-json-schema'
The options interface is exported as GraphQLJsonSchemaOptions. Common mistake is to use a different name.

Demonstrates converting a GraphQL schema to JSON Schema using fromIntrospectionQuery with typical options.

import { graphqlSync, getIntrospectionQuery } from 'graphql'; import { fromIntrospectionQuery } from 'graphql-2-json-schema'; // Assume schema is a valid GraphQLSchema object const introspectionResult = graphqlSync(schema, getIntrospectionQuery()) as { data: any }; const jsonSchema = fromIntrospectionQuery(introspectionResult.data, { ignoreInternals: true, nullableArrayItems: true, idTypeMapping: 'string' }); console.log(JSON.stringify(jsonSchema, null, 2));
Debug
Known issues
breakingSetting nullableArrayItems to false is deprecated; future versions will treat it as true.
fix
Set nullableArrayItems to true to prepare for future default behavior.
affects: >=0.7.0
deprecatedOptions like 'ignoreInternals' and 'nullableArrayItems' may change defaults in future major versions.
fix
Explicitly set all options to avoid breaking changes when defaults change.
affects: >=0.7.0
gotchaIgnoreInternals removes internal GraphQL types; ensure you want that.
fix
Set ignoreInternals: false if you need types like __Type.
affects: >=0.1.0
gotchaID type defaults to string; if your API uses numeric IDs, set idTypeMapping: 'number' or 'both'.
fix
Pass idTypeMapping: 'number' or 'both' in options.
affects: >=0.1.0
Errors
Common errors & fixes
Cannot find module 'graphql-2-json-schema'
Package not installed or missing from node_modules.
fix
npm install graphql-2-json-schema
Property 'ignoreInternals' does not exist on type 'GraphQLJsonSchemaOptions'
Using an older version of the package where options were different.
fix
Check the current option names; upgrade to latest version.
fromIntrospectionQuery is not a function
Incorrect import or package version mismatch.
fix
Ensure you are importing from 'graphql-2-json-schema' and not a subpath.
Upgrade
Version history
0.10.0latest on npm
Audit
Dependencies
graphqlrequiredPeer dependency for introspection query execution and type definitions
Agent activity
7 hits · last 30 days
node
6
Resources
graphql-2-json-schema — npm install graphql-2-json-schema · libregistry