Registry / devops / graphql-fetch-schema

graphql-fetch-schema

JSON →
library1.1.0jsnpmunverified

A CLI tool and library (v1.1.0) for fetching a GraphQL schema from a remote endpoint and writing it to a local file. Lightweight wrapper around introspection queries, supports JSON and SDL output formats, cookie-based auth, and custom headers. Stable but low-maintenance; no recent releases. Simpler than graphql-cli's schema download — no dependencies beyond Node.js built-ins.

npm install graphql-fetch-schema
INSTALL
IMPORT
SIG · GRAPHQL-FETCH-SCHE
G
graphql-fetch-schema
devopsjavascriptv1.1.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.

default
import fetchSchema from 'graphql-fetch-schema'
const fetchSchema = require('graphql-fetch-schema')
Package is ESM-only; no CommonJS support.
fetchSchema (typed)
import fetchSchema from 'graphql-fetch-schema'
import { fetchSchema } from 'graphql-fetch-schema'
No named export; only default export. TypeScript users may need to declare module.
CLI invocation
npx graphql-fetch-schema <url>
graphql-fetch-schema()
CLI is separate; use npx or global install.

Shows how to fetch and save a GraphQL schema using the library API with auth header.

import fetchSchema from 'graphql-fetch-schema'; fetchSchema('https://api.example.com/graphql', { json: true, graphql: false, outputPath: './schema', cookie: '', headers: { Authorization: 'Bearer ' + process.env.GRAPHQL_TOKEN ?? '' } }).then( () => console.log('Schema written'), err => console.error('Failed:', err) );
Debug
Known issues
gotchaThe library does not validate the response; it may silently write an error page if the endpoint is misconfigured.
fix
Verify the endpoint returns a valid GraphQL schema before calling fetchSchema.
affects: >=1.0.0
breakingESM-only: package does not support CommonJS require().
fix
Use ESM imports or dynamic import().
affects: >=1.0.0
gotchaThe 'cookie' option only sets a single Cookie header; multiple cookies are not supported.
fix
Combine cookies into one string (e.g., 'a=1; b=2').
affects: >=1.0.0
Errors
Common errors & fixes
Error: fetchSchema is not a function
Using named import instead of default import.
fix
Change to import fetchSchema from 'graphql-fetch-schema' (no curly braces).
TypeError: graphql-fetch-schema is not defined
Attempting to run the library as a function in a non-Node environment.
fix
Use the CLI: npx graphql-fetch-schema <url>.
Error: 'outputPath' directory does not exist
The library does not create the directory automatically.
fix
Ensure the output directory exists before calling fetchSchema.
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
12 hits · last 30 days
node
12
Resources
graphql-fetch-schema — npm install graphql-fetch-schema · libregistry