GraphQL Formatter

100% private — runs on your device, never uploaded. Works offline once loaded.

Paste a messy GraphQL query, mutation or SDL schema and get it back cleanly indented — or minified to a single line. The tokenizer and pretty-printer run entirely in your browser.

Consistent formatting for GraphQL

GraphQL is easy to write badly: a working query can arrive as one long line with no indentation, or with inconsistent spacing copied from three different places. This formatter re-lays-out the whole document from a clean slate so nested selection sets, arguments and directives are easy to scan. It is built on a small tokenizer and pretty-printer written specifically for GraphQL — no heavyweight parser and no external libraries.

Because it reformats from the token stream rather than doing find-and-replace, the output is uniform regardless of how the input was spaced. Each selection set opens with a brace on the same line as its field and indents its children by two spaces, exactly the convention you see in the official GraphQL documentation.

How the tokenizer and printer work

First the input is scanned into tokens: names, punctuators ({ } ( ) [ ] : ! = | & @ $), variables, fragment spreads (...), strings including triple-quoted block strings, and # comments. GraphQL treats commas as insignificant whitespace, so they are dropped during tokenizing and never appear in the output.

The printer then walks those tokens tracking brace depth for indentation. Braces trigger line breaks and change the indent level; parentheses and square brackets keep their contents inline, so arguments like (id: $id, first: 10) and list types like [Post!]! stay on one line. Directives such as @include(if: $x) attach to the field they modify rather than jumping to a new line, and each field inside a selection set gets its own line.

Prettify, minify, and the limits

The Minify toggle does the opposite job: it rebuilds the document on a single line, inserting a space only where two adjacent words would otherwise merge, and it strips comments entirely (a # comment on one line would otherwise swallow everything after it). That is useful when you need to inline a query as a string in application code.

  • Formatting is purely cosmetic — it never rewrites field names, aliases, arguments or variable definitions.
  • The tool assumes reasonably well-formed GraphQL; it is a formatter, not a validator, so it will not report syntax errors in a broken document.
  • Block-string descriptions ("""...""") are preserved verbatim, including their internal line breaks.
  • Minified output drops comments by design, since inline # comments cannot survive on a single line.

Frequently asked questions

Will the formatter validate my GraphQL?

No. It focuses on layout and assumes your document is broadly well-formed. For strict validation, run the query against your schema with a GraphQL client or server.

Does it keep my comments?

In prettify mode, # comments are preserved on their own lines. In minify mode they are removed, because a single-line document cannot safely contain a # comment.

How are arguments and list types handled?

Contents of parentheses and square brackets stay inline, so field arguments and list types such as [User!]! read naturally on one line rather than being split across lines.

Can I format a full SDL schema?

Yes. Type, input, enum, interface, union, scalar and directive definitions are all supported, with each definition separated onto its own block and fields indented consistently.

Is my query sent anywhere?

No. Tokenizing and printing happen entirely in your browser, so private or internal queries never leave your machine.

Why did my commas disappear?

Commas are optional and insignificant in GraphQL. The formatter normalises them away for a cleaner result; the meaning of your document is unchanged.

Advertisement