About GraphQL Query Formatter
GraphQL queries are written as nested selections of fields, and long queries copied from logs or network tabs often arrive on a single line. This formatter puts each field on its own line and indents the selection sets inside braces, so the shape of the response is obvious.
It keeps arguments in parentheses together on one line, handles aliases, fragments and inline fragments such as ... on Admin, and keeps comments and strings unchanged. It formats text only and does not validate the query against a schema.
How to use GraphQL Query Formatter
- Paste the GraphQL query into the input box.
- Click Run Tool to format it.
- Copy the result into your client code, an IDE or documentation.
Example
Input
query GetUser($id: ID!) { user(id: $id) { name email posts(first: 2) { title } ... on Admin { level } } }Output
query GetUser($id: ID!) {
user(id: $id) {
name
email
posts(first: 2) {
title
}
... on Admin {
level
}
}
}Common uses
- Reading a query captured from browser developer tools.
- Cleaning up queries before committing them to a repository.
- Teaching how nested selections correspond to the shape of the JSON response.
Privacy and safety
This tool runs in your browser. The text you enter is processed on your device and is not sent to NHP Learning.
Frequently asked questions
Does it check my query is valid?
No. It does not know your schema. Use your GraphQL server's tooling or an IDE plugin to validate queries.
Does it format variables and JSON?
Only the query text. Format a variables object with the JSON Formatter.
Does it support mutations and fragments?
Yes. Queries, mutations, subscriptions and fragment definitions are all treated as braces and fields, so they indent correctly.