GraphQL Formatter

Turn a cramped GraphQL query into indented, readable code.

What it does

The formatter puts each selection set on its own indented lines so the shape of the query is clear.

Tip

Format queries before sharing them in tickets or pull requests so reviewers can read them.

How to use it

  1. Paste your query into GraphQL query.
  2. Press Format.
  3. Copy the formatted query.

Example

This query:

query { user(id: 1) { name email posts { title } } }

is indented so each selection set opens on its own line.

Common use cases

How the formatting works

The formatter is a small text pass, not a GraphQL parser. It turns every { into a line ending with {, puts every } on its own line, trims each line and re-indents by brace depth with two spaces. That is all it does, and it is why the results are predictable. Verified on a compact query:

query GetUser($id: ID!){user(id:$id){id name posts(first:5){title}}}

becomes

query GetUser($id: ID!) {
  user(id:$id) {
    id name posts(first:5) {
      title
    }
  }
}

Several things are left exactly as typed: spacing inside parentheses, the missing space in (id:$id), commas, and sibling fields on one line. Fields written id name stay together on the same line.

Getting one field per line

Existing line breaks are kept, only repeated blank lines are collapsed, so the formatter will not split fields for you. If you want one field per line, put a newline between them before pressing Format; the indentation of every line is recalculated, so inconsistent or tab-based indentation is cleaned up. Multiple operations and fragments in one paste work too: a fragment F on User { id } after a query ends up on its own lines.

Gotchas and limits

If your project uses Prettier, keep that as the source of truth, since it understands the full grammar including comments, descriptions and directives. This page is for reading a query lifted from a network tab or a bug report.

Where it fits in a debugging session

Copy the query string out of a request body, where it appears with \n escapes and quotes, unescape it with the String Escape tool, then format it here. This is often the quickest way to see which fields a front end really asks for, and to spot an accidentally requested large nested list. Paste the formatted version into a ticket so reviewers can compare it with the schema.

Frequently asked questions

Does it run my query?

No. It only formats the text.

Does it validate against a schema?

No, it formats the syntax you provide.

Is it free?

Yes.

Is my data uploaded?

No. This tool runs entirely in your browser, so what you type or paste is not sent to our servers.

Why are my fields still on one line?

The formatter only breaks lines at braces. Put a newline between fields in the input if you want one per line; existing line breaks are preserved.

Can I format the variables JSON too?

Not with this tool. Use the JSON Formatter for the variables object and keep it separate from the query.

Related tools

Explore all developer tools →