Registry / devops / graphql-cli-generate-fragments

graphql-cli-generate-fragments

JSON →
library1.4.1jsnpmunverified

A plugin for graphql-cli that auto-generates GraphQL fragments for each type in your project's schema. Version 1.4.1 is current, with stable release cadence. Key differentiator: generates both standard and no-nesting fragments to avoid recursive spread errors, plus deeply nested fragments when no recursion exists. Integrates with APollo, Prisma, and Graphcool workflows.

npm install graphql-cli-generate-fragments
INSTALL
IMPORT
SIG · GRAPHQL-CLI-GENERA
G
graphql-cli-generate-fragments
devopsjavascriptv1.4.1
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 generateFragments from 'graphql-cli-generate-fragments'
const generateFragments = require('graphql-cli-generate-fragments')
ESM default export; require() works if using CJS interop but prefer ESM.
generateFragments
import { generateFragments } from 'graphql-cli-generate-fragments'
Named export also available; identical to default.
Types
import type { Options } from 'graphql-cli-generate-fragments'
TypeScript types exported for options interface.

Installs graphql-cli and the plugin globally, then generates GraphQL fragments for a project named 'myProject', outputting to src/generated in .graphql format, saving config.

npm i -g graphql-cli graphql-cli-generate-fragments graphql generate-fragments -p myProject -o src/generated -g graphql --save
Debug
Known issues
gotchaRecursive fragments cause 'Cannot spread fragment within itself' error if deep nesting enabled.
fix
Use automatically generated NoNesting fragments to avoid recursion, or manually ensure no cyclic references.
affects: >=1.0.0
breakingThe option --save previously accepted a string 'true' but now expects 'false' (default) or boolean flag? Verify behavior between versions.
fix
Specify --save without argument; it sets to true. For false, omit flag or use --no-save.
affects: <1.4.0
deprecated--generator option 'js' is deprecated in favor of 'graphql' in newer versions? Not specified, but 'graphql' preferred.
fix
Use --generator graphql for GraphQL output or --generator js for JavaScript string constant. Check docs.
affects: >=1.4.0
gotchaGlobal installation required for CLI usage; local install may not expose graphql command.
fix
Install graphql-cli globally: npm i -g graphql-cli
affects: >=0.0.0
gotchaGenerates no-nesting fragments to avoid recursion, but deep nesting fragments may still cause infinite loops in cyclic schemas.
fix
Use NoNesting fragments in queries; DeepNesting fragments are only safe if schema has no cycles.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'graphql-cli-generate-fragments'
Plugin not installed alongside graphql-cli, or installed locally instead of globally.
fix
npm i -g graphql-cli graphql-cli-generate-fragments
Error: Cannot spread fragment 'User' within itself
Including a fragment that references itself (recursive query).
fix
Use the generated UserNoNesting fragment instead of User in nested queries.
TypeError: graphql is not a constructor
Incompatible version of graphql (e.g., v16) with older graphql-cli.
fix
Ensure graphql version compatible with graphql-cli (v15 recommended).
Upgrade
Version history
1.4.1latest on npm
Audit
Dependencies
graphql-clirequiredRequired as the CLI framework; this plugin extends graphql-cli commands.
graphqlrequiredUsed for schema introspection and type traversal.
Agent activity
8 hits · last 30 days
node
8
Resources
graphql-cli-generate-fragments — npm install graphql-cli-generate-fragments · libregistry