DataToolsLab
Code Formatter Tools

GraphQL Query Formatter

Pretty-print GraphQL queries, mutations and schema definitions with consistent indentation.

Loading tool…

What is GraphQL Formatter?

A formatter for GraphQL documents and schema definition language. Queries pasted from a client's network tab become something you can read, and SDL type definitions gain a consistent layout.

How it works

Names, arguments, braces and comments are tokenized, then re-emitted so every selection set is indented under its parent and each field starts a new line. Arguments stay inline as `first: 20, status: OPEN` unless you ask for one per line, and block strings ("""…""") are copied verbatim.

  1. Paste the source. Drop in code, a stylesheet, a query or a selector list. Everything is read locally — the page never uploads what you paste.
  2. Choose the options. Indent width, quote style, keyword case or target browsers. The result updates as you change them, so you can see the effect immediately.
  3. Copy or download. Copy the result to the clipboard or download it as a file. Reset clears the form and returns every option to its default.

Examples

A minified bundle → readable code

Beautifying a 40 KB one-line stylesheet or script turns it into something reviewable, without altering a single token of the program itself.

A query moved between databases

MySQL's backticks, AUTO_INCREMENT and LIMIT 10, 20 become PostgreSQL's double quotes, identity columns and OFFSET — with a list of what still needs a human.

A stylesheet that only breaks in Safari

backdrop-filter, user-select and position: sticky need -webkit- prefixes for older Safari, which the CSS Autoprefixer adds for exactly the targets you tick.

Common mistakes

Expecting a formatter to fix invalid code

Formatting is whitespace and quoting. A missing brace, an unclosed tag or an unquoted variable survives the round trip and is reported instead — check the findings list.

Minifying without running the tests afterwards

Even a safe, non-mangling minifier can expose an existing automatic-semicolon-insertion bug. The JavaScript Minifier keeps the newlines that matter, but re-run your tests before shipping.

Treating a rewritten query as verified

The SQL Dialect Converter translates the syntax it can prove; data types, casts and function differences are listed for review, not guessed. Run the converted query against a real database.

Renaming or reformatting generated files

Regenerating a formatter's output is a no-op only if the formatter is the same one that produced it. Keep generated code out of the round trip and format the source it came from.

Frequently asked questions

Does it validate the query against a schema?

No — it formats and nothing more. A misspelled field or a missing required argument passes through, because validation needs the schema and the server's rules. The GraphQL playground or your client's codegen step is the right place for that.

Will it keep my aliases and directives?

Yes. Aliases (`total: amount`), directives (`@include(if: $flag)`), inline fragments (`... on User`) and variable definitions are all preserved; only whitespace changes.

What happens with a malformed document?

It formats as far as the tokens go and produces the best layout it can rather than failing. Compare the result with the input before pasting it back — a missing brace will still be missing.

Online