Registry / devops / graphql-document-collector

graphql-document-collector

JSON →
library0.2.2jsnpmunverified

CLI tool to collect all GraphQL queries, mutations, and subscriptions from a project into a single JSON file, resolving fragments inline. Version 0.2.2 (stable, low release cadence). It precompiles `.graphql` files into a single `documents.json` with AST format, intended for use with Apollo Client or similar GraphQL clients. Differentiator: automates fragment resolution and document bundling without build tool plugins.

npm install graphql-document-collector
INSTALL
IMPORT
SIG · GRAPHQL-DOCUMENT-C
G
graphql-document-collector
devopsjavascriptv0.2.2
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.

documents.json
const docs = require('./documents.json')
import docs from './documents.json'
CommonJS require is typical; ESM import may need assert { type: 'json' } or a loader
graphql-document-collector (CLI)
npx graphql-document-collector '**/*.graphql' > documents.json
npm install -g graphql-document-collector && graphql-document-collector src/**/*.graphql
Use npx to avoid global install; glob must be quoted to prevent shell expansion

Collects all .graphql files into documents.json and loads them with require.

npx graphql-document-collector '**/*.graphql' > documents.json; const graphqlDocs = require('./documents.json'); // graphqlDocs is an object mapping file paths to document ASTs console.log(Object.keys(graphqlDocs));
Debug
Known issues
breakingOutput format may change between minor versions; rely on structure documented in README.
fix
Pin to exact version and test document structure on upgrade.
affects: <1.0.0
gotchaCLI arguments: glob pattern must be quoted to avoid shell globbing.
fix
Use single quotes around glob: '**/*.graphql'.
affects: all
gotchaIf using webpack, you need a JSON loader (e.g., json-loader) to require documents.json.
fix
Add 'json-loader' to webpack config or use webpack 5 which supports JSON imports natively.
affects: all
gotchaFragments are resolved in the output, but if a fragment is missing from any collected file, the process will fail.
fix
Ensure all fragment definitions are included in the glob pattern or manually included.
affects: all
Errors
Common errors & fixes
Error: ENOENT: no such file or directory, open 'documents.json'
The output redirection > documents.json was not executed or the file wasn't written.
fix
Run the CLI command with proper redirection: npx graphql-document-collector '**/*.graphql' > documents.json
SyntaxError: Invalid or unexpected token
Attempting to require documents.json without a JSON loader in webpack (webpack 4 and below).
fix
Add json-loader to webpack configuration.
Cannot find module 'graphql'
graphql is required as a peer dependency but not installed.
fix
Run npm install graphql
Upgrade
Version history
0.2.2latest on npm
Audit
Dependencies
graphqlrequiredUsed for parsing and printing GraphQL documents
Agent activity
8 hits · last 30 days
node
8
Resources
graphql-document-collector — npm install graphql-document-collector · libregistry