GraphQL Query Formatter
Format, beautify, and minify GraphQL queries.
What is GraphQL?
GraphQL is a query language for APIs developed by Meta. Instead of exposing many fixed endpoints, a GraphQL server exposes a single endpoint and a typed schema, and clients describe exactly the fields they need. The server returns only those fields, which avoids both over-fetching and the round trips that plague REST when a screen needs data from several resources.
A GraphQL document is hierarchical: selection sets nest with curly braces, arguments sit in parentheses, and variables are referenced with a leading $. Because whitespace is insignificant, a query that arrived minified from a build step or a network log can be hard to read. This formatter rewrites it with consistent indentation and line breaks so the structure is obvious at a glance.
The tool understands the full document grammar you are likely to use in practice: queries, mutations, subscriptions, and fragments, including variables, directives, aliases, inline fragments, and string arguments. It also supports the # comment syntax, which many editors omit.
Key features
- Format — re-indent a document with 2 or 4 spaces per level for readability.
- Minify — strip whitespace and comments to produce the smallest payload for production.
- Live stats — see character and line counts for both input and output.
- Copy and download — copy the result or save it as
query.graphql. - Private — tokenising and formatting happen in your browser; queries are never uploaded.
How to Use
- Paste the query — Paste or type a GraphQL document, or click Example to load a sample query, mutation, and fragment.
- Choose an indent — Select 2 or 4 spaces per level.
- Format or minify — Click Format to beautify, or Minify to compress.
- Copy or download — Use Copy or download the result as a
.graphqlfile.
The formatter is syntax-aware for layout but does not validate your schema. It will not detect unknown fields or type errors — use a GraphQL validator for that.
Format vs Minify
Format is for humans: it adds newlines and indentation so that nested selection sets are easy to follow, and it preserves comments. Minify is for machines: it removes every optional space and all comments, which shrinks the payload you send over the network.
A minified query and its formatted equivalent are semantically identical to a GraphQL server, which ignores insignificant whitespace. That makes minification a safe size optimisation, not a transformation of meaning.
# Formatted
query {
users {
id
name
}
}
# Minified
query{users{id name}}
When to format a GraphQL query
- Debugging — reformat a query captured from a network tab or an error log so you can spot the missing field.
- Documentation — produce clean, readable examples for a README or an API guide.
- Code review — beautify a pasted query before discussing it with a teammate.
- Production payloads — minify a query string before embedding it in client code to save bytes.
- Learning — see how nesting, arguments, and fragments map to indentation.
Frequently Asked Questions
What types of GraphQL operations are supported?
This tool supports queries, mutations, subscriptions, and fragments. All standard GraphQL syntax including variables, directives, inline fragments, aliases, and string arguments are preserved.
Is my GraphQL query data stored on a server?
No. All formatting happens entirely in your browser using JavaScript. Your queries never leave your device.
What is the difference between Format and Minify?
Format adds proper indentation and line breaks for readability. Minify removes all unnecessary whitespace and comments to produce the smallest possible query string for production use.
Does the formatter validate my query?
No. It rearranges whitespace and line breaks but does not compare your document against a schema. It will not flag unknown fields, wrong argument types, or missing required variables — use a GraphQL server or linter for validation.
Are GraphQL comments preserved?
When you click Format, lines beginning with # are kept and placed on their own line. When you click Minify, comments are removed along with the extra whitespace, since comments are meaningless to the server.
Which indentation can I choose?
The Indent selector offers 2 spaces and 4 spaces per nesting level. Pick whichever matches your team style; the choice only affects readability, not the meaning of the document.
Can I format fragments and variables?
Yes. Named and inline fragments, fragment spreads written as ...Name, and variable definitions such as ($page: Int) are all tokenised and laid out correctly.
Can I save the result to a file?
Yes. The Download button saves the current output as a plain-text file named query.graphql, which you can drop straight into a project or commit to a repository.
Related Tools
SQL Formatter
Format and beautify SQL queries
JSON Formatter
Format and validate JSON data
JS Beautifier
Format JavaScript code
HTML Formatter
Format and beautify HTML code
CSS Beautifier
Format and beautify CSS code
XML Formatter
Format and validate XML documents