GraphQL Query Formatter
Format, prettify and minify GraphQL queries, mutations and fragments. Turn one-line queries into readable, indented code right in your browser.
GraphQL document
Stays in your browserResult
Shortcuts: Ctrl+Enter run · Ctrl+Shift+C copy result · / search (use ⌘ on Mac)
Next steps
Done here? Use the Send to… menu on the result to carry it on to Text Compare or Diff Checker.
Free Online GraphQL Formatter
Paste a GraphQL query, mutation, subscription, or fragment to reformat it with consistent two-space indentation, or collapse it to a single compact line for embedding in code. It helps API developers read queries, mutations, and fragments consistently while debugging a GraphQL request.
Why format GraphQL queries?
GraphQL queries built by hand, copied from browser devtools network tabs, or generated by tooling often arrive as a single dense line or with inconsistent indentation. A consistently formatted query is far easier to review in a pull request, paste into documentation, or debug when something in a nested selection set isn't returning what you expect. This tool parses the query as real GraphQL syntax — not just guessing at brace positions — so the structure it prints back out is guaranteed to match what a GraphQL server would actually parse.
How to use this formatter
Paste any GraphQL document — a query, mutation, subscription, or a standalone fragment definition — into the box and click Format to get readable, indented output, or Minify to collapse it to a single compact line suitable for embedding in a config file or a URL parameter. Variable definitions, directives like @include and @skip, inline fragments, and nested selection sets are all handled and re-indented correctly.
Common use cases
- Cleaning up a GraphQL query copied from a browser's network inspector before adding it to your codebase
- Reviewing a large, deeply nested query in a pull request where indentation matters for readability
- Minifying a query before sending it as a URL query-string parameter for a GET-based GraphQL request
- Formatting a fragment definition shared across multiple queries so it's easy to read on its own
Everything runs locally in your browser using a small hand-written GraphQL parser — nothing you paste is ever uploaded to a server.
Worked example
A query starting with # fetch a user on its own line, followed by query GetUser($id: ID!) { user(id: $id) { id name email @include(if: $id) } }, formats to one field per line with the comment preserved directly above the operation. Clicking Minify on the same input collapses it to a single compact line — the comment is removed, and a warning says so.
Common mistakes and edge cases
- Minify removes comments, because a compact single line has nowhere to put a
#comment without breaking the query. A warning above the result says how many were removed. - A block string (
"""...""") may contain an escaped triple quote (\"""); it does not end the string. A block string that is never closed is reported as an error.