Registry / devops / format-graphql

format-graphql

JSON →
library1.5.0jsnpmunverified

A GraphQL SDL formatter that sorts definitions, fields, arguments, and enums alphabetically (version 1.5.0). It works as both a CLI tool and a Node.js API, with options to control which sorting aspects are applied. Designed for predictable schema organization in large GraphQL projects. Notable differentiator: defaults to sorting all elements alphabetically, unlike prettier which only does basic formatting. Stable release with no recent updates.

npm install format-graphql
INSTALL
IMPORT
SIG · FORMAT-GRAPHQL
F
format-graphql
devopsjavascriptv1.5.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.

formatSdl
import { formatSdl } from 'format-graphql'
const formatSdl = require('format-graphql')
ESM only; CommonJS require is not supported.
default (named export)
import { formatSdl } from 'format-graphql'
import formatSdl from 'format-graphql'
The package exports a named function formatSdl, not a default export.
formatSdl options
formatSdl(schema, { sortDefinitions: true, sortFields: true })
formatSdl(schema, { sortDefinitions: false })
Options boolean defaults are true unless explicitly set to false.

Demonstrates formatting a GraphQL SDL string with default sort options, showing alphabetical ordering of types and fields.

import { formatSdl } from 'format-graphql'; const input = ` type Query { bananas: [Banana!]! apples: [Apple!]! } type Apple { name: String! id: ID! } type Banana { name: String! id: ID! } `; const formatted = formatSdl(input); console.log(formatted); // Output: // type Apple { // id: ID! // name: String! // } // type Banana { // id: ID! // name: String! // } // type Query { // apples: [Apple!]! // bananas: [Banana!]! // }
Debug
Known issues
gotchagraphql peer dependency is required; not installed automatically
fix
Install graphql: npm install graphql
affects: >=1.0.0
deprecatedCLI option --write expects 'true' or 'false' as string, not boolean flag
fix
Use --write=true or --write=false, not --write
affects: >=1.0.0
gotchaSorting is applied alphabetically and cannot be customized per type
fix
Accepts current behavior or use pre-processing before formatting
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: formatSdl is not a function
Incorrect import: using default import instead of named import
fix
Change import to: import { formatSdl } from 'format-graphql'
Cannot find module 'graphql'
Peer dependency graphql is not installed
fix
Install graphql: npm install graphql
Unrecognized option: --write
CLI argument --write used without =true or =false
fix
Use --write=true or --write=false
Upgrade
Version history
1.5.0latest on npm
Audit
Dependencies
graphqlrequiredPeer dependency required for parsing GraphQL SDL syntax
Agent activity
2 hits · last 30 days
node
2
Resources
format-graphql — npm install format-graphql · libregistry