Skip to content
API & TESTING TOOLS

GraphQL Query Formatter Online

Format a GraphQL query with indented selections.

  • Free
  • No signup
  • Runs in your browser

This tool runs in your browser. The text you enter is processed on your device and is not sent to NHP Learning.

GraphQL Query Formatter

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

  1. Paste the GraphQL query into the input box.
  2. Click Run Tool to format it.
  3. 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.

Learn to build this yourself

Free tutorials and courses on NHP Learning cover PHP, JavaScript, SQL and WordPress, from the basics to real projects.