Registry / developer_tools / graphql-prettier

graphql-prettier

JSON →
library1.0.6jsnpmunverified

Prettify & simplify GraphQL queries, mutations, and subscriptions by removing duplicate fields and formatting the output. Version 1.0.6 is the current stable release, with no recent updates or defined release cadence. It offers a simple function-based API with an optional noDuplicates parameter to control deduplication. Compared to general formatters like prettier with graphql plugin, this package focuses only on deduplication and basic indentation. Lightweight with no runtime dependencies.

npm install graphql-prettier
INSTALL
IMPORT
SIG · GRAPHQL-PRETTIER
G
graphql-prettier
developer_toolsjavascriptv1.0.6
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.

gqlPrettier
import gqlPrettier from 'graphql-prettier'
const gqlPrettier = require('graphql-prettier')
Package is ESM-only; CommonJS require will fail in Node.js with esModuleInterop off. Use default import.

Demonstrates importing the default function and using it to deduplicate fields in a GraphQL query with fragments.

import gqlPrettier from 'graphql-prettier'; const query = ` query ViewerQuery { viewer { user { id name id ...userFragment name } } } fragment userFragment on User { id name email name } `; const prettifiedQuery = gqlPrettier(query); console.log(prettifiedQuery); // Output: // query ViewerQuery { // viewer { // user { // id // name // email // } // } // }
Debug
Known issues
gotchaThe noDuplicates parameter defaults to true, but setting it to false may leave duplicate fields in the output, which is not expected by users who assume deduplication always occurs.
fix
Explicitly pass noDuplicates: true to ensure deduplication, or omit the second argument.
affects: >=1.0.0
gotchaThe package does not perform full syntax validation; malformed GraphQL strings may produce unexpected results or throw errors.
fix
Validate your GraphQL string with a proper parser like graphql-tag before passing to gqlPrettier.
affects: >=1.0.0
deprecatedThe package has not been updated in 2+ years and may not support newer GraphQL features (e.g., @defer, @stream, Apollo Federation).
fix
Consider using prettier with graphql plugin or graphql-schema-utilities for more robust formatting.
Errors
Common errors & fixes
TypeError: (0 , _graphqlPrettier.default) is not a function
Import mistake when using CommonJS require incorrectly.
fix
Use import gqlPrettier from 'graphql-prettier' instead of const gqlPrettier = require('graphql-prettier').
SyntaxError: Unexpected token ... - Unexpected token 'export'
Using CommonJS environment (e.g., Node.js without type: module) with ES module import syntax.
fix
Add type: module to package.json or use dynamic import: const gqlPrettier = (await import('graphql-prettier')).default;
Upgrade
Version history
1.0.6latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
graphql-prettier — npm install graphql-prettier · libregistry