Registry / devops / graphql-json-to-sdl

graphql-json-to-sdl

JSON →
library0.5.0jsnpmunverified

A command line utility for converting a JSON GraphQL schema to GraphQL SDL (Schema Definition Language). Current version 0.5.0, released with low frequency (last release in 2020). Key differentiator: it sorts fields from the JSON schema before writing the SDL, ensuring consistent output even with nondeterministic field order from code-first libraries. Useful for tooling that requires a .graphql file when only a JSON schema is available. Ships TypeScript types.

npm install graphql-json-to-sdl
INSTALL
IMPORT
SIG · GRAPHQL-JSON-TO-SD
G
graphql-json-to-sdl
devopsjavascriptv0.5.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.

graphqlJsonToSdl
import { graphqlJsonToSdl } from 'graphql-json-to-sdl'
const graphqlJsonToSdl = require('graphql-json-to-sdl')
ESM-only since v0.5.0
default
import graphqlJsonToSdl from 'graphql-json-to-sdl'
import { graphqlJsonToSdl } from 'graphql-json-to-sdl'
There is no default export; use named export.

Reads a JSON GraphQL schema from a file, converts it to SDL string, and writes it to another file.

import { graphqlJsonToSdl } from 'graphql-json-to-sdl' import { readFileSync, writeFileSync } from 'fs' const jsonSchema = JSON.parse(readFileSync('./schema.json', 'utf8')) const sdl = graphqlJsonToSdl(jsonSchema) writeFileSync('./schema.graphql', sdl) console.log('Converted schema.json to schema.graphql')
Debug
Known issues
deprecatedPackage has not been updated since 2020.
fix
Consider using graphql-js's printSchema or other actively maintained alternatives.
affects: >=0.5.0
gotchaThe input JSON must be a valid GraphQL schema introspected in the standard format (e.g., from graphql-js). Other JSON schema formats may fail silently.
fix
Ensure your JSON schema follows the GraphQL introspection result format (with __schema key).
affects: >=0.1.0
gotchaNo TypeScript types shipped before v0.5.0.
fix
Upgrade to v0.5.0 or use @types/graphql-json-to-sdl if available.
affects: <0.5.0
Errors
Common errors & fixes
Cannot find module 'graphql-json-to-sdl'
Package not installed or global installation missing.
fix
Run 'npm install graphql-json-to-sdl' or 'yarn add graphql-json-to-sdl'.
TypeError: graphqlJsonToSdl is not a function
Incorrect import style (default instead of named).
fix
Use 'import { graphqlJsonToSdl } from "graphql-json-to-sdl"'.
SyntaxError: Unexpected token < in JSON at position 0
Input file is not valid JSON or is missing.
fix
Verify the source file exists and contains valid JSON GraphQL schema.
Upgrade
Version history
0.5.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
graphql-json-to-sdl — npm install graphql-json-to-sdl · libregistry