Developer

GraphQL Query Formatter

Format a GraphQL query, mutation or schema document with consistent indentation, or minify it for transport. Reports unbalanced braces with the line number where the nesting broke.

Last reviewed by the Radiatus Cloud team

Need this built for your product?

We design, build & host secure software & APIs.

Talk to an engineer

Why GraphQL needs its own formatter

A GraphQL document is not JSON and not JavaScript, so neither of those formatters will touch it correctly. Fields are separated by whitespace or optional commas, arguments live in parentheses, directives attach with an at sign, string arguments can be triple quoted block strings, and comments run from a hash to the end of the line. Run a query through a JSON beautifier and you get an error; run it through a JavaScript one and the argument lists come out wrong.

Unbalanced braces are the real bug

The most common thing wrong with a hand edited query is a selection set that was never closed, usually after a field was deleted from the middle. The server responds with a syntax error at the end of the document, which tells you nothing about where the mistake was. Formatting exposes it immediately: the indentation runs away from the point the brace went missing, and this formatter also reports the line where the nesting depth stopped returning to zero.

Minifying for transport

Queries sent in a GET request count against URL length limits, and queries embedded in a mobile bundle count against download size. Minifying removes comments, collapses runs of whitespace to the single spaces the grammar requires, and drops optional commas. String literals and block strings are preserved byte for byte, because whitespace inside a string is data rather than formatting.

Related tools

  • JSON Formatter — Format and beautify JSON in your browser. Pinpoints syntax errors by line and column, flags unsafe integers, and never uploads your data to a server.
  • JSON Validator — Validate JSON syntax with precise line and column errors, and check documents against a JSON Schema. Runs locally in your browser, nothing uploaded.
  • Regex Tester — Test regular expressions against sample text with live match highlighting, capture groups and flag control. Runs entirely in your browser.
  • HTML Minifier — Minify HTML by removing comments and redundant whitespace, without breaking inline elements or pre blocks. Runs entirely in your browser.

Frequently Asked Questions

Does this validate the query against a schema?

No. It parses structure only: braces, parentheses, strings and comments. Validating field names and argument types requires the schema, which the tool does not have. A document can format cleanly and still be rejected by the server.

Are block strings preserved?

Yes. Triple quoted block strings and ordinary quoted strings are copied through untouched, including their internal whitespace and escapes, because changing them would change the request.

Will it format a schema definition file?

Yes. Type, interface, input, enum and union definitions use the same brace structure, so an SDL file formats the same way as a query.

Why did minify not shorten my query much?

GraphQL is already terse. Most of the savings come from removing indentation, so a deeply nested query gains more than a flat one. Comments and optional commas are also removed.

Are variables and fragments handled?

Yes. Variable definitions in the operation signature, fragment definitions, inline fragments with type conditions and directives all pass through with the same indentation rules as fields.

Privacy & Security

Everything runs in your browser; nothing is uploaded.

Data: None
Client-side-Side
Active
v1.0

How to Use

Paste a GraphQL document and press Format, or Minify to strip it down for a request body.

Disclaimer: This tool is provided "as is" without warranty of any kind. Results are for educational and utility purposes.