What This GraphQL Formatter Does
- Uses Prettier’s GraphQL parser to apply consistent, community-standard formatting
- Supports queries, mutations, subscriptions, fragments and full schema SDL (types, interfaces, unions, enums, inputs, directives)
- Adjustable indentation: choose spaces or tabs and configure indent size (1–8)
- Optional line-length / wrapping control via a configurable column width
- Keeps descriptions (`"""…"""`) and inline comments intact while normalizing their layout
- Validates your GraphQL document structure as part of formatting; invalid syntax will surface errors instead of silently mangling code
- Hybrid execution: runs Prettier in-browser when available and falls back to a server formatter if required
- Paste or upload `.graphql` / `.gql` files, then preview, copy or download the formatted result
📝 How to Format GraphQL Online for graphql-formatter
Paste or Upload Your GraphQL
Paste your GraphQL schema or queries into the editor, or drop a `.graphql` / `.gql` file. The formatter works for both SDL and operation documents.
Adjust Formatting Options
Choose spaces or tabs, set the indent size, and configure your preferred line length. These options are passed to Prettier’s GraphQL formatter.
Format, Review & Export
Click Format to apply the changes. Review the result in the preview pane, then copy it back into your editor or download the formatted file.
Technical Specifications
Supported Input
Designed for standard GraphQL schema and operation documents.
| Type | Examples | Notes |
|---|---|---|
| Schema SDL | schema.graphql, schema.gql | Types, interfaces, unions, enums, inputs, directives, schema definition |
| Operations | queries.graphql, app.gql | Queries, mutations, subscriptions and fragments |
| Extensions | schema extensions in separate files | e.g., `extend type Query { … }` blocks |
Formatting Engine
Formatting is performed using Prettier’s GraphQL support. In most cases, Prettier runs in the browser via a lightweight runtime. If the GraphQL plugin cannot be resolved in the current environment, the formatter transparently falls back to a server-side Prettier worker.
Available Options (Mapped to Prettier)
| Option | Behavior | Typical Values |
|---|---|---|
| Indent Style | Choose between spaces and tabs | space (default) or tab |
| Indent Size | Number of spaces per indent level (when using spaces) | 1–8, default: 2 |
| Line Length | Target column for wrapping / breaking long selections | 0–120 (0 ≈ effectively no wrapping) |
Limits & Performance
The tool is tuned for typical GraphQL schemas and operation files. Requests around a few hundred KB to ~2 MB are generally safe; extremely large documents may hit timeouts or size guards.
Privacy & Safety
GraphQL documents are formatted either in your browser or on encode64’s formatter backend. They are not executed or sent to third-party services. For sensitive schemas, you can mirror the same configuration locally with Prettier.
Command Line Equivalent (Prettier)
If you already have Node.js and Prettier installed, you can reproduce this behavior locally.
Node.js (all platforms)
Format a GraphQL schema file in place
npx prettier --write schema.graphqlPrettier auto-detects GraphQL based on the file extension.
Format with custom indent and line length
npx prettier --write schema.graphql --tab-width 2 --use-tabs false --print-width 80Reflects the indent and wrapping options exposed in the online tool.
Format from stdin (e.g. piped from another tool)
cat input.graphql | npx prettier --stdin-filepath input.graphqlUseful in shell scripts, CI pipelines or Git hooks.
Common GraphQL Formatter Use Cases
API Schema Development
- Keep large schema files consistently formatted for easier navigation
- Reduce noisy whitespace diffs in schema PRs
- Prepare clean SDL for code generation tools
# Before
type User{ id:ID! name:String!}
# After
type User {
id: ID!
name: String!
}Frontend Operations & Fragments
- Normalize shared queries across multiple apps or packages
- Make nested selections easier to scan during debugging
- Keep documentation snippets and playground examples nicely formatted
Tests, Fixtures & Tooling
- Standardize GraphQL fixtures used in snapshot tests
- Integrate formatting into pre-commit hooks or CI jobs
- Feed clean documents into schema validation or diff tools
❓ Frequently Asked Questions
What does the GraphQL formatter actually change?
Does it support both operations and schema SDL?
Are comments and description strings preserved?
Is my GraphQL code executed?
Where does the formatting run: client or server?
Is this free to use?
Pro Tips
Use this formatter to standardize legacy schemas before adding linting or breaking changes; it makes subsequent diffs much easier to review.
Align your online tool settings (indent size and line length) with your project’s Prettier config to keep local and web formatting identical.
Extract long embedded GraphQL strings from code into `.graphql` files so they can be uniformly formatted and reused.
Pair formatting with linting (e.g., GraphQL ESLint) to catch schema and query issues that go beyond whitespace and wrapping.
Additional Resources
Other Tools
- CSS Beautifier
- HTML Beautifier
- Javascript Beautifier
- PHP Beautifier
- Color Picker
- Sprite Extractor
- Base64 Decoder
- Base64 Encoder
- Csharp Formatter
- Csv Formatter
- Dockerfile Formatter
- Elm Formatter
- ENV Formatter
- Go Formatter
- Hcl Formatter
- INI Formatter
- JSON Formatter
- Latex Formatter
- Markdown Formatter
- Objectivec Formatter
- Php Formatter
- Proto Formatter
- Python Formatter
- Ruby Formatter
- Rust Formatter
- Scala Formatter
- Shell Script Formatter
- SQL Formatter
- SVG Formatter
- Swift Formatter
- TOML Formatter
- Typescript Formatter
- XML Formatter
- YAML Formatter
- Yarn Formatter
- CSS Minifier
- Html Minifier
- Javascript Minifier
- JSON Minifier
- XML Minifier
- Http Headers Viewer
- PDF To Text
- Regex Tester
- Serp Rank Checker
- Whois Lookup