Registry / devops / graphql-introspect

graphql-introspect

JSON →
library1.0.0jsnpmunverified

A CLI tool and programmatic API for generating GraphQL schema representations in Schema Language format (SDL) from a GraphQLSchema object or a running GraphQL server URL. Version 1.0.0 is stable with no recent releases; it is a single-purpose utility that depends on the graphql package. It differentiates from similar tools by supporting both local schema files and remote introspection, outputting directly to STDOUT for easy file redirection.

npm install graphql-introspect
INSTALL
IMPORT
SIG · GRAPHQL-INTROSPECT
G
graphql-introspect
devopsjavascriptv1.0.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.

introspect
import { introspect } from 'graphql-introspect'
const introspect = require('graphql-introspect').introspect
Default export is not available; use named import. Supports both ESM and CJS, but CJS require must use destructuring.
introspectURL
import { introspectURL } from 'graphql-introspect'
const introspectURL = require('graphql-introspect')
CJS require returns an object; must destructure to get introspectURL.
introspectFile
import { introspectFile } from 'graphql-introspect'
import introspectFile from 'graphql-introspect'
Not a default export; use named import.
typeof introspect
import type { introspect } from 'graphql-introspect'
TypeScript users can import type for type annotations, available since v1.0.0.

Shows how to introspect a remote GraphQL server and print the schema SDL using async/await.

import { introspect } from 'graphql-introspect'; async function main() { const sdl = await introspect('http://example.com/graphql'); console.log(sdl); } main().catch(console.error);
Debug
Known issues
gotchaThe CLI tool outputs to STDOUT; redirect to file to save.
fix
Use shell redirection: $ graphql-introspect http://example.com/graphql > schema.graphql
affects: >=1.0.0
gotchaintrospect() is an alias for introspectURL() if the argument is a URL, and for introspectFile() if the argument is a file path. The behavior depends on the input string, which can be ambiguous.
fix
Use introspectURL() or introspectFile() explicitly to avoid confusion.
affects: >=1.0.0
gotchaThe package has no TypeScript type definitions; users must create their own or use `@types/graphql-introspect` if available.
fix
Add a declaration file or use `any` type.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'graphql'
Missing peer dependency graphql
fix
npm install graphql
TypeError: introspect is not a function
Incorrect import: using default import instead of named import
fix
import { introspect } from 'graphql-introspect'
Error: Not a valid URL or file path
Provided argument is neither a valid URL nor an existing file
fix
Ensure the argument is a valid GraphQL server URL or path to a JavaScript module exporting a GraphQLSchema
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
graphqlrequiredPeer dependency for GraphQL schema introspection and SDL printing
Agent activity
7 hits · last 30 days
node
6
Amazon
1
Resources
graphql-introspect — npm install graphql-introspect · libregistry