Skip to content
100% local

GraphQL formatter

Format or minify a GraphQL query, mutation, fragment or schema with consistent indentation.

Input
Output

GraphQL formatter

Paste a GraphQL query, mutation, fragment or schema and this tool reformats it with consistent, readable indentation — or minifies it to a single line for shipping over the wire. It understands the structure shared by operations and type definitions, so a query with nested selection sets and a schema full of type blocks both come out cleanly indented, with fields, arguments, directives and variable definitions in the right place.

Choose the indent width (2 spaces, 4 spaces or a tab), or turn on "Minify instead of format" to strip whitespace and comments down to the shortest valid document. "Sort fields alphabetically" reorders the fields inside each selection set or type block, useful for spotting a missing or duplicated field in a long query. "Collapse query variables to one line" decides whether an operation's `$variable: Type` list stays on one line or breaks onto its own indented line per variable, and "Blank line between operations" adds spacing when the input has more than one query, mutation or fragment.

The tool also checks as it formats: unmatched or unclosed brackets are reported instead of guessed at, and a selection set that spreads a fragment (`...MyFragment`) with no matching definition in the pasted text gets its line flagged. The live tally reports how many definitions were found and how deeply the query nests — an early-warning sign for an over-fetching query.

Formatting runs entirely in your browser — nothing you paste is uploaded, which matters for schemas and queries that reference internal field or type names. Copy the result, download it as a .txt file, or send the output back into the input to apply another pass with different options.

FAQ

Does it work on schema definitions (SDL), not just queries?
Yes. Type, interface, input, enum, union, scalar and schema blocks are all formatted with the same consistent indentation as operations, and "Sort fields alphabetically" applies to their fields too.
What happens if my query references a fragment that isn’t in the input?
The tool still formats the rest of the document, but the line spreading the missing fragment is flagged so you can paste in its definition or fix a typo in its name.
Can I use this to shrink a query before sending it over the network?
Yes — turn on "Minify instead of format" to strip comments and non-essential whitespace down to the smallest valid document, keeping the query semantically identical.
Are comments preserved?
By default, yes: # comments and description strings are kept on their own line above what they describe. Turn off "Keep comments" to strip them, which also happens automatically when minifying.
Is my query or schema uploaded anywhere?
No. Formatting and minifying run entirely in your browser — nothing you paste ever leaves your device.