About this tool
GraphQL queries copied from network logs, persisted-query stores or code are often squashed onto one line. This formatter lays them out the conventional way, one field per line with nested selections indented and arguments separated by commas, and works for queries, mutations, subscriptions, fragments and schema definitions (SDL). Unlike many formatters, it keeps your # comments. Minify does the reverse for compact network payloads.
What it handles
- Variables with defaults, directives (
@include,@skip,@deprecated), aliases, fragments and inline fragments (... on User). - Object and list arguments, block strings (
""") and descriptions in SDL. - Errors such as unclosed braces or strings are reported with their line and column.
Formatting changes only whitespace and commas, which are insignificant in GraphQL, so the document means exactly the same thing.
In your project
For formatting on save and in CI, use Prettier, which supports .graphql files and GraphQL inside gql template literals: npx prettier --write "**/*.graphql". Explore a schema with the GraphQL Explorer.
FAQ
How do I format a GraphQL query?
Paste it above. It is formatted instantly with one field per line; copy the result or download it as a .graphql file.
Does formatting change my query?
No. Only whitespace and commas change; both are insignificant in GraphQL.
Can it format schema files (SDL)?
Yes: type, input, enum, interface, union, scalar and directive definitions, including descriptions.
Are comments kept?
Yes. Comments starting with # stay in place. Minify removes them.