Skip to main content

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 browser

Result

Formatted or minified GraphQL will appear here.

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.

Frequently asked questions

What kinds of GraphQL documents can this formatter handle?
Queries, mutations, subscriptions (including the shorthand form with no operation keyword), fragment definitions, inline fragments, variable definitions with default values, directives, and all standard argument/value types (strings, numbers, booleans, enums, lists, and objects).
Does this validate my GraphQL against a schema?
No — this only checks that the document is syntactically valid GraphQL and re-prints it with consistent indentation. It doesn't know your schema, so it can't catch things like an unknown field or a wrong argument type; a real GraphQL client or server will still validate that when the query runs.
What happens to comments in my query?
It depends which button you use — confirmed by testing. Format preserves comments (lines starting with #), re-emitting each one directly above the field or definition it was attached to. Minify removes every comment, since a single compact line has no way to hold them, and it tells you how many were removed. Keep the original (or use Format) if you need the comments back.
Is my GraphQL query uploaded anywhere?
No. Parsing and formatting run entirely in your browser using a small hand-written GraphQL tokenizer and parser — nothing you paste is sent to a server.
How do I make a GraphQL query readable?
Paste the operation and press Format. Each nested selection gets its own indentation level, so you can see which fields belong to which type, and long argument lists are split across lines. The formatter checks the syntax of the query, but only the API itself can say whether a field exists, so test the query against the server as well.

Related tools

More Formatters & Parsers

View all Formatters & Parsers tools →