01What is GraphQL Formatter?
GraphQL Formatter takes a query, mutation or schema that has been squashed onto one line and lays it out so you can actually read it. The usual source is a request body copied from the browser's network tab or a line in a server log. The formatting updates as you type, so there is no button to press. Under the hood it is a small tokenizer, not a regex trick. It reads names, punctuation, numbers, variables, strings, block strings ("""" ... """") and # comments one token at a time. Then it rebuilds the document. Every field, enum value or input field inside a { } selection set goes on its own line, indented by 2 or 4 spaces. Arguments, variable definitions, directives like @include(if: $flag) and default values stay on the same line as the field they belong to. The GraphQL specification treats whitespace and commas as insignificant tokens ("ignored tokens" in the spec's own words). That is the only thing this tool changes. Names, string contents and numbers are copied exactly as you typed them, so the result means the same thing to your server. A quick example. Paste mutation AddUser($n:String!){addUser(name:$n){id}} and you get the operation header on the first line as mutation AddUser($n: String!) {, then addUser(name: $n) { indented one level, then id one level deeper, and two closing braces. Schema definition language works as well: type, input, enum, interface, union, scalar, directive and implements A & B. Top-level definitions get a blank line between them, and description strings stay directly above the field they describe. The tokenizer also catches a few mistakes. An unexpected character, an unterminated string or block string, or braces and brackets that don't match produce an error message instead of output. That makes it handy for finding the missing } in a long query. Now the honest limits. This is a formatter, not a validator. It has never seen your schema, so a misspelled field, a wrong argument type or a missing required argument passes straight through. Use GraphiQL or your server for that. A comment written at the end of a line is moved onto its own line. Your query stays in the browser tab, because the formatting is plain JavaScript with no network call.
Frontend and API developers who copy raw GraphQL out of network logs or chat messages and need to read or review it quickly. The tool runs entirely in your browser, so your data never leaves your device.
02How to use GraphQL Formatter
- Paste your GraphQL operation or schema into the Input box, or pick one of the examples
- Choose 2 Spaces or 4 Spaces from the Indent menu
- Read the result in Formatted Output, which updates as you type
- If an error appears instead, fix the line, string or brace it names
- Click Copy to take the formatted GraphQL, or Reset to clear both boxes
03Worked examples
- Input:
query{user(id:1){name,friends(first:2){name}}} (indent 2) - Result:
query { user(id: 1) { name friends(first: 2) { name } } } - Commas are insignificant in GraphQL and are dropped.
- Input:
mutation AddUser($n:String!){addUser(name:$n){id}} - Result:
mutation AddUser($n: String!) { addUser(name: $n) { id } } - Input:
fragment F on User{id ...on Admin{level}} - Result:
fragment F on User { id ... on Admin { level } } - Input:
query { a { b } - Result:
Error: missing closing "}" - The tool shows an error instead of output when braces don't balance.
- Input:
query Q($f:Boolean=false){me @include(if:$f){id}} (indent 4) - Result:
query Q($f: Boolean = false) { me @include(if: $f) { id } } - Default values get spaces around the equals sign, and directives stay on the field's line.
- Input:
type Book implements Node & Item{"the title" title:String! tags:[String!]!}enum Color{RED GREEN} - Result:
type Book implements Node & Item { "the title" title: String! tags: [String!]! } enum Color { RED GREEN } - Schema definitions work too. The description string stays right above its field, and a blank line separates the two types.
04Common use cases
- Reading a minified operation copied from the request payload in browser dev tools while debugging a broken screen
- Making sense of a one-line query logged by an Apollo or Yoga server when a slow request shows up in your logs
- Tidying hand-written queries and fragments before pasting them into docs, a README or a pull request description
- Formatting a schema (SDL) snippet someone pasted into an issue or chat so you can review the types
- Finding the unbalanced brace or unterminated string in a long query that your client rejects
- Normalising indentation to 2 or 4 spaces before committing a .graphql file by hand
05Tips
- Commas between fields are dropped because GraphQL ignores them. Commas inside argument lists are put back as a comma and a space.
- Name your operations (query GetUser instead of a bare { user }). Server logs and tracing tools show the operation name, which makes slow requests far easier to find.
- Keep dynamic values in variables ($id: ID!) rather than string-built arguments. The query text stays constant, which helps persisted queries and server caching.
- An end-of-line # comment lands on its own line after formatting, so check comments that refer to the line above them.
- A clean format does not mean the query is valid for your schema. Run it in GraphiQL to catch unknown fields.
06Related concepts
GraphQL SDL, Apollo Client, Selection set, GraphQL fragments.
Frequently Asked Questions
What is GraphQL Formatter?
GraphQL Formatter is a free, browser-based developer tool on AIDToolStack. Format and prettify GraphQL queries, mutations, and fragments. It requires no installation or sign-up and works entirely in your browser.
Is GraphQL Formatter free to use?
Yes. No sign-up, no fees and no usage cap.
Does GraphQL Formatter store my data?
No. It runs in your browser; nothing is uploaded.