Developer · Formatter
GraphQL formatter.
Paste a GraphQL query, mutation, fragment or schema (SDL) to pretty-print it or squeeze it onto one line. Syntax errors come back with a line and column. Runs in your browser; nothing is sent anywhere.
Input
Result
Paste GraphQL and press Run.
How the GraphQL formatter works
Formatting uses Prettier 3.9.9 (standalone build plus its GraphQL plugin, MIT licence), which parses the text with graphql-js and prints it in Prettier's GraphQL style: one field per line, a space after each colon, commas removed, and consistent indentation. It works on executable documents (queries, mutations, subscriptions, fragments) and on schema definitions (SDL) alike.
Minifying removes what the GraphQL specification calls ignored tokens: whitespace, line breaks, comments and commas (September 2025 edition, Language › Source Text). A single space is kept only between two names or numbers that would otherwise run together, and string values, including block strings, are left exactly as written. Because commas are ignored tokens, a(x: 1, y: 2) becomes a(x:1 y:2), which means the same thing.
Worked example. The query query Q($id:ID!){user(id:$id){name,...F}} formats to four short lines, with $id: ID! spaced and ...F on its own line. The loaded example (the query plus fragment F on User) is 70 characters as typed and 97 once formatted; minified it is 68 characters on one line: query Q($id:ID!){user(id:$id){name...F}}fragment F on User{id email}. The size shown after minifying is a character count, before and after.
Errors: if the text is not valid GraphQL syntax you get the parser's message and the line and column where it stopped, both counted from 1. Nothing is output until the syntax is fixed.
Sources: GraphQL specification, September 2025 (spec.graphql.org); Prettier, browser / standalone usage (prettier.io), vendored at version 3.9.9. Sources checked 2026-09-30.
How to prettify a GraphQL query
Paste the query, fragment or schema into the input box, leave Mode on format, choose an indent and press Run. Switch the mode to minify to get the compact one-line form for a request body or a persisted-query file. Load example fills in a short query so you can see both modes before using your own text.
Worked example: a paginated orders query
Pasted as it often arrives from a log or a network panel (181 characters):
query Orders($status: OrderStatus!, $first: Int = 10) { orders(status: $status, first: $first) { edges { node { id total items { sku qty } } } pageInfo { hasNextPage endCursor } } }
Formatted with a 2-space indent it becomes 18 lines, with one field per line and each selection set indented one level deeper than its parent:
query Orders($status: OrderStatus!, $first: Int = 10) {
orders(status: $status, first: $first) {
edges {
node {
id
total
items {
sku
qty
}
}
}
pageInfo {
hasNextPage
endCursor
}
}
}
Minified, the same query is 153 characters: query Orders($status:OrderStatus!$first:Int=10){orders(status:$status first:$first){edges{node{id total items{sku qty}}}pageInfo{hasNextPage endCursor}}}. The comma between the two variable definitions disappears and the space after $status in the arguments is the only separator, which is valid because commas are ignored tokens.
Formatting a schema (SDL)
The tool is not limited to queries. A compressed type definition such as type User @key(fields:"id"){id:ID! name:String posts(first:Int=10):[Post!]!} prints as a four-line type with a space after each colon and the directive argument spaced as @key(fields: "id"). Directive definitions, enums, interfaces, unions, input types and extend blocks go through the same parser.
Reading the error message
If the text is not valid GraphQL syntax you get the parser’s message plus the line and column where it stopped. For the unfinished query query { user( } the message is “Expected Name, found "}"” at line 1, column 15: the parser opened an argument list and met a closing brace before any argument name. Typical causes are a missing closing brace, an argument with no value, or a variable written without its $.
Syntax, validation and execution are three different checks
This page checks syntax: can the text be parsed as a GraphQL document. The GraphQL specification separately defines validation (do the fields, arguments and types exist in a particular schema, do fragments get used) and execution (running the operation against a service). A query asking for a field that does not exist formats without complaint because that error can only be found against the schema. Use your server’s tooling, or an IDE plugin loaded with your schema, for those stages.
When to minify, and when not to
Minifying is useful when you embed a query in a script, a curl command or a test fixture, or when you compute a hash for persisted queries. It saves bytes in the payload; it does not change what the server does with the query. Keep the formatted version in source control, since comments (which start with #) and readable structure are lost when you minify.
Matching your editor’s output
The formatter is Prettier 3.9.9 with its GraphQL plugin, the same engine many projects run through their editor or a pre-commit hook. If your project pins a different Prettier version or has a .prettierrc, the output of a big schema can differ in small ways; this page does not read configuration files.
Sources
Each source below was opened and checked in October 2026 (retrieved 2026-10).
- GraphQL specification, September 2025: language syntax and ignored tokens, plus the separate validation and execution sections
- Prettier, options: how Prettier output is configured, including the printWidth and tabWidth defaults
- Prettier, browser / standalone usage: how the standalone build and the GraphQL plugin run in a page
- Prettier, rationale: what Prettier changes (layout) and why it reprints from the syntax tree
Frequently asked questions
Does it check my query against my schema?
No. It checks syntax only. An unknown field or a wrong argument type still formats fine, because that needs your schema to detect.
Does minifying change what the query does?
No. Whitespace, commas and comments are ignored tokens in GraphQL, so the minified text parses to the same document. Strings are not touched.
Where did my comments go when I minified?
Minifying drops # comments, since they are ignored tokens. Formatting keeps them.
Is my query uploaded anywhere?
No. Prettier runs in your browser and nothing you paste is stored or sent.
How do I prettify a GraphQL query?
Paste it into the box, set the mode to format and press Run. Every field goes on its own line, each nested selection set is indented one level, and commas between arguments and variables are normalised. The result keeps your comments.
What is the difference between a GraphQL formatter and a GraphQL validator?
A formatter changes layout and only needs the text to parse. A validator checks the document against a schema: whether fields, arguments and types exist. This tool is a formatter and a syntax check; it never sees your schema, so unknown fields still format fine.
Can it format a GraphQL schema as well as a query?
Yes. Schema definition language (type, interface, enum, union, input, directive and extend definitions) is parsed and printed in the same way as queries, mutations, subscriptions and fragments.
Why does the minified query have no commas?
In GraphQL, commas are ignored tokens, like white space. Dropping them does not change the meaning of the document, and a single space is kept wherever two names or values would otherwise run together.
Is this the same output as the Prettier VS Code extension?
It uses the same Prettier GraphQL printer, so for the same Prettier version and default options the layout should match. A project that pins an older version or sets custom options in .prettierrc may differ slightly.
What does the line and column in an error mean?
Both are counted from 1 and point to where the parser stopped, which can be just after the real mistake. If the message says it expected a name and found a closing brace, look for an argument list or selection that was opened and left empty.
Syntax check only
This tool confirms the text is syntactically valid GraphQL and re-prints it. It does not validate against a schema, run the query, or check variables.