GraphQL Formatter
Format GraphQL queries, mutations, fragments and schemas with this GraphQL Formatter. Paste a document and the tool parses it with a GraphQL parser and prints it in a standard layout: two space indentation, one field per line, commas between fields removed and arguments and variables spaced consistently. Syntax errors are reported, so API developers get readable operations and SDL for docs, reviews and debugging.
Frequently asked questions
How does the GraphQL Formatter work?
It parses your document into a GraphQL syntax tree and prints it back in a standard layout. Because the document is parsed, invalid GraphQL is rejected instead of reformatted incorrectly.
What can I format?
Queries, mutations, subscriptions and fragments as well as schema definitions in SDL, such as type, input, enum, interface, union and schema blocks. You can mix several definitions in one document.
What does the output look like?
Each selection set is indented by two spaces with one field per line, and commas between fields are dropped. Arguments and variable definitions get a space after each colon, for example user(id: $id).
What happens with a syntax error?
The tool stops and shows the parser message, such as Syntax Error: Expected Name, found }. Fix the reported spot and format again.
Are comments preserved?
The formatter keeps hash comments (#) where the parser can attach them, such as after a closing brace. Descriptions in quotes on schema types and fields are part of the document and are always preserved.
Does it validate my query against a schema?
No, it only checks syntax. Whether fields and arguments exist is decided by your server's schema, so use your GraphQL client or server to validate.
Can I format a query string copied from JavaScript?
Paste only the GraphQL document, without surrounding quotes, backticks or a gql tag. Escaped characters from a JSON payload should be unescaped first.
Can I change the indentation?
No, the formatter always uses two spaces and has no options. This matches the layout most GraphQL tools and documentation use.
Why is the result wrapped in a graphql code fence?
The output is returned as a Markdown code block marked graphql, so it renders highlighted in Markdown. Copy the lines between the fences for a .graphql file.
How large can my document be?
Up to 5 MB per run; larger input is rejected with a message. The output is identical to the GraphQL option of the Code Formatter.