GraphQL Query Formatter
Format GraphQL query, mutation and subscription text with consistent indentation, or minify it to a single line. Syntax checking is limited to bracket-stack matching - this is not a full AST parser.
FreeOnline Tool
Loading…
How to Use
- Paste your GraphQL query, mutation or subscription into the input box.
- Press "Format" to re-indent it under a single rule set: every selection-set field on its own line, argument lists kept on one line, directives attached to the field they belong to.
- Press "Minify" to strip comments and redundant whitespace and squeeze the query onto one line, ready to paste into a log or a network request.
- Press "Check syntax only" to run the bracket check on its own without changing the output.
- The result panel reports whether curly braces, parentheses and square brackets are balanced and whether strings are closed, quoting the line number of any problem.
- Press "Replace input with output" to feed the formatted or minified result into the next operation, or "Load sample query" for an example with variables, fragments and directives.
Features
- Formatting: re-indents the query by selection-set depth, keeps argument lists (...) on the same line, attaches directives such as @include to their field, and puts fragment spreads (... FragmentName / ... on Type) on their own lines.
- Minifying: removes comments and redundant whitespace and reduces the query to a single line, keeping one space only where it is needed to stop adjacent identifiers from merging.
- Syntax checking: a bracket-stack check for balanced {}, () and [] and for properly closed strings, reporting the specific line when something is off.
- Honest about its limits: this is not a complete GraphQL syntax or semantic parser. It cannot detect misspelled fields, undeclared variables or type mismatches - only structural bracket balance.
- Processing is entirely local; queries are never uploaded.
Use Cases
Restoring a minified query from DevTools
Paste the single-line GraphQL request body copied from the Network panel and format it back into a readable indented structure for debugging.
Shrinking a query before sending it
Minify a multi-line development query into a single line to reduce request size or to drop into an API client or a log entry.
Enforcing query style in code review
When teammates submit queries with inconsistent indentation, run everything through the formatter for a uniform style.
Finding an unbalanced bracket fast
Deeply nested handwritten queries easily lose a closing brace - use "check syntax only" to locate the offending line.
FAQ
Does it fully validate GraphQL syntax?
No. It works by bracket-stack matching and simple token scanning, so it can only tell you whether {}, () and [] are balanced and whether strings are closed. Misspelled fields, undeclared variables and type mismatches are invisible to it - it is not a complete GraphQL AST parser.
What indentation rules does formatting use?
Each field inside a selection set goes on its own line, indented two spaces per level. Argument lists (...) and variable definition lists stay on one line. Directives such as @include(if: $x) stay on the same line as their field. Fragment spreads (...Frag) and inline fragments (... on Type) each get their own line.
Does a minified query still work?
Yes. Minifying only removes comments and redundant whitespace, keeping the single spaces the syntax needs to separate adjacent identifiers, so the meaning of the query is unchanged.
What happens if my query has a syntax error?
The result panel points at the line where a bracket is unbalanced or unclosed. Formatting still produces best-effort output, but correctness is not guaranteed for invalid input, so fix the syntax error first.