Registry / productivity / graphql-formatter

graphql-formatter

JSON →
library1.0.3jsnpmunverified

A lightweight GraphQL code formatter that preserves structural indentation and layout. Current stable version is 1.0.3, with infrequent releases. It focuses on simple, predictable formatting of GraphQL schema definitions, queries, and fragments without heavy configuration or AST manipulation. Ships TypeScript type definitions. Differentiates from alternatives like prettier by being minimal, dependency-free, and respecting existing structural patterns.

npm install graphql-formatter
INSTALL
IMPORT
SIG · GRAPHQL-FORMATTER
G
graphql-formatter
productivityjavascriptv1.0.3
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.

format
import { format } from 'graphql-formatter'
import format from 'graphql-formatter'
The library exports a named export 'format', not a default export.
format
const { format } = require('graphql-formatter')
const format = require('graphql-formatter')
CommonJS users must destructure the require result to get the 'format' function.
format
import type { format } from 'graphql-formatter'
import { format } from 'graphql-formatter/types'
TypeScript types are bundled with the package; no separate /types path needed.

Shows basic usage: importing format, passing a multi-line GraphQL string, and logging the formatted output.

import { format } from 'graphql-formatter'; const input = ` type User{ id:ID! name: String } `; const result = format(input); console.log(result); /* Output: type User { id: ID! name: String } */
Debug
Known issues
gotchaPreserves source structure but may not re-indent deeply nested fields consistently.
fix
Use prettier with graphql plugin if consistent indentation across files is critical.
affects: >=1.0.0
gotchaDoes not validate GraphQL syntax; malformed input may produce unexpected output.
fix
Validate your GraphQL with a parser before formatting.
affects: >=1.0.0
gotchaOnly exports named function 'format'; no default export. TypeScript users must use named import syntax.
fix
Use `import { format } from 'graphql-formatter'` instead of default import.
affects: >=1.0.0
Errors
Common errors & fixes
SyntaxError: Unexpected token 'export'
Using ES import syntax in a CommonJS environment without transpilation.
fix
Use `const { format } = require('graphql-formatter')` or enable ESM support.
TypeError: format is not a function
Default import used instead of named import.
fix
Change to named import: `import { format } from 'graphql-formatter'`
Cannot find module 'graphql-formatter' or its corresponding type declarations.
Package not installed or TypeScript cannot resolve types.
fix
Run `npm install graphql-formatter` and ensure tsconfig.json includes types.
Upgrade
Version history
1.0.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
33 hits · last 30 days
node
32
OpenAI (training)
1
Resources
graphql-formatter — npm install graphql-formatter · libregistry