GraphQL Beautifier and Formatter
WM-73Paste a GraphQL query, mutation, fragment or schema to format it with consistent indentation, or minify it to one line. Syntax errors come with a line and column.
Runs in your browser. Nothing is uploaded.
GraphQL
Result
How to use it
- Paste your GraphQL into the input box, or open a .graphql file.
- Pick 2 spaces, 4 spaces or a tab for the indent.
- Choose Format for readable GraphQL or Minify for a single line.
- Copy the result or download it as a .graphql file.
What Format changes
Format uses the Prettier GraphQL printer. It puts each field on its own line, indents selection sets, and breaks long argument lists across lines. It reads queries, mutations, subscriptions, fragments, variables, directives and schema definitions such as type, input, enum and interface. Comments are kept. The optional commas between fields and arguments are dropped, because GraphQL treats them as whitespace, so the query means the same thing.
What Minify changes
Minify is our own code. It removes comments, commas and whitespace and writes one line, leaving a space only where two names would otherwise run together. Strings and block strings are copied exactly as written. It splits the text into tokens and reports unclosed strings and stray characters, but it does not check the grammar, so run Format first if you also want the structure checked.
Errors and limits
If the text is not valid GraphQL, Format reports what it expected and the line and column where it stopped, and nothing is formatted. That position is where the parser noticed the problem, which can be just after the real mistake, such as a missing closing brace at the end. Nothing is sent to a server and the query is never run, so variables, types and field names are not checked against any schema.
Error messages and what to do
| Message | What it means | Fix |
|---|---|---|
Invalid GraphQL: Expected Name, found <EOF>. at line 1, column 11 | The text ended where a name was needed, often because a brace or field is missing. | Complete the field or add the missing closing brace. |
Unclosed string at line 1. Add the closing quote | A quoted string has no closing quote on its line (Minify). | Add the closing quote, or use a block string for multiple lines. |
Questions people ask
How do I format a GraphQL query online?
Paste the query and choose Format. Fields go on separate lines, selection sets are indented, and long argument lists are broken up. Copy the result or download it as a .graphql file. It works on queries, mutations, fragments and schema definitions.
Can it format a GraphQL schema?
Yes. Type, input, enum, interface, union and scalar definitions are formatted the same way as queries, and descriptions and comments are kept. Directives and extend definitions are handled too. Only the layout changes.
Why were my commas removed?
In GraphQL, commas between fields, arguments and list items are optional and ignored by the parser. The formatter writes one field per line instead, so the commas are not needed. The query means exactly the same thing before and after.
How do I minify GraphQL?
Choose Minify. Comments, commas and extra spaces are removed and the query becomes one line, with a space only where two names would touch. Strings stay exactly as written. This is handy for sending a query in a URL or a log line.
Does it check my query against a schema?
No. It checks the syntax only. It does not know your schema, so unknown fields, wrong types and missing variables are not reported. Use a GraphQL server, a schema-aware editor or a linter for that.
Can I choose tabs instead of spaces?
Yes. The Indent list offers 2 spaces, 4 spaces or a tab. There is also a box for spaces inside braces in object values, such as { a: 1 } versus {a: 1}.
About this tool
Format uses the Prettier GraphQL printer, which reads queries, mutations, fragments and schema definitions. It reflows lines and indentation, keeps comments, and drops the optional commas between fields. A syntax error is reported with its line and column and nothing is formatted. Minify is our own: it removes comments, commas and extra whitespace and leaves strings and block strings exactly as written. It does not rename anything, and it checks the text only for unclosed strings and stray characters, so run Format first if you also want the syntax checked. Descriptions in schemas are kept.