GraphQL Formatter
Format or minify GraphQL queries and SDL with a canonical printer — errors pinned to line and column, entirely on this device.
Paste a query, mutation or SDL schema — it formats as you type, and Minify strips every ignored character. Nothing you paste leaves this tab.
Runs synchronously in this tab — no upload, no worker, no request. Share links carry the mode and indent only, never your document. · Press ? for shortcuts
Do it offline:$ npx prettier --parser graphql --write 'src/**/*.graphql'
How to use it
- Pick a mode: Format pretty-prints the document; Minify strips every ignored character it legally can.
- Paste a query, mutation, fragment or SDL schema into the input pane — anything the October 2021 grammar accepts, up to 1 MB.
- For Format, choose the indent unit: 2 spaces, 4 spaces or tabs. Minify has no style options.
- Read the result as you type. A syntax error shows the parser's own message with its line and column — Jump to line puts your cursor on the exact spot.
- Copy the result, download it as a .graphql file, or share a link. Links carry the mode and indent only, never your document.
Paste a GraphQL query, mutation or SDL schema and get it back in the canonical style graphql-js prints — two-space indent by default, argument lists wrapped past 80 characters, block strings dedented by the spec's own algorithm. Switch to Minify and the same token stream collapses to its shortest legal form. Errors land with line, column and a caret frame, and the document never leaves this tab.
Examples
query FilmHeroes($episode: Episode = JEDI) { hero(episode: $episode) { name, friends { name }, ... on Droid { primaryFunction } } }query FilmHeroes($episode: Episode = JEDI) {
hero(episode: $episode) {
name
friends {
name
}
... on Droid {
primaryFunction
}
}
}
Format — a one-line operation unfolds at two spaces per level. The commas vanish because GraphQL treats them as ignored tokens, each selection takes its own line, and the inline fragment keeps its ... on Droid head.
"""
A film character.
"""
type Character { "Stable identifier." id: ID! name: String! appearsIn: [Episode!]! }"""A film character."""
type Character {
"Stable identifier."
id: ID!
name: String!
appearsIn: [Episode!]!
}
Format on SDL — a short block-string description collapses onto one line between its triple quotes, and the field description moves onto the line above its field inside the type body.
mutation SaveDraft($draft: DraftInput!) {
saveDraft(draft: $draft) {
id
updatedAt
}
}
mutation SaveDraft($draft:DraftInput!){saveDraft(draft:$draft){id updatedAt}}Minify — an already-formatted mutation collapses back to one line. A space survives only where two tokens would otherwise fuse: id updatedAt keeps one, while ){ and :$ need none.
Every example on this page is executed against the same engine that powers the tool, on every build.
Gotchas worth knowing
Block strings are dedented by the spec's own algorithm
Triple-quoted strings pass through BlockStringValue(): the common leading whitespace of every line after the first is stripped, and blank first and last lines are removed. That is why the formatter may re-indent a nested block string freely — the indentation it adds is exactly what the next parse subtracts, so the value never changes.
Comment fidelity, stated exactly
A # comment that starts its line is kept and re-anchored above the nearest following line — a definition, a field, an enum value or the closing brace it precedes. A comment sitting after code on the same line is dropped by the printer. Minify strips all of them, because comments are ignored tokens.
An anonymous plain query collapses to the shorthand
query { viewer { id } } prints as { viewer { id } } — when an operation has no name, no variables and no directives, the query keyword is redundant and the canonical form omits it. Named or decorated operations always keep their keyword, and mutations and subscriptions are never shortened.
Commas are whitespace to GraphQL
[1, 2] and [1 2] are the same document: the grammar lists commas among ignored tokens, alongside spaces and the byte-order mark. Format drops them everywhere, and Minify counts on the same rule when it fuses tokens like JEDI$withFriends.
Every cap is named, never silent
Input stops at 1 MB, lexing at 500,000 tokens, and nesting at 128 levels — each limit refuses with its own message and position instead of freezing the tab. Deeper nesting than 128 levels is a hostile document, not a working query.
Common errors
Unterminated block string — the closing """ was never found.- A """ opener swallows everything — including quotes and line breaks — until the next """. The position points at the opener, so look forward from there; to write a literal triple quote inside, escape it as \""".
Unexpected character U+1F680 — not valid in GraphQL outside a string.- Emoji and other symbols are legal inside string values but not in the document structure itself: outside strings the grammar only knows names, numbers, punctuators and comments. The code point in the message tells you exactly which character to remove.
Expected a field name, "..." or "}", found end of input.- The classic unbalanced brace: a selection set opened and the document ended before it closed. The expected-set names what could legally come next, and the position sits just past the last character — count your closing braces from there.
FAQ
Is my query or schema uploaded when I format it?
No. The parser and printer are a single synchronous pass inside this tab — there is no server call, no worker, and no request of any kind behind the Format or Minify buttons. Share links encode the mode and indent choice only; the document itself is never placed in a URL.
Does it validate my document against a schema?
No — this page is parse-level by design. It proves the document matches the October 2021 grammar and flags what a parser can see, such as two operations sharing a name or an anonymous operation beside a named one. Checking fields against an actual schema is typed work that belongs to a schema-aware tool.
Can I run the same formatting in my CI pipeline?
The closest widely-installed equivalent is Prettier's GraphQL parser — the Do-it-offline command below the tool rewrites every .graphql file in place and requires prettier installed. Its style differs from this page's graphql-js form in small deliberate ways (it keeps the query keyword on anonymous operations, for one), so pick one canon per repository and stay with it.