Loading GraphQL Formatter...
Please wait a moment

How to Format GraphQL Queries - Step by Step Guide

Step 1

Input Your GraphQL Query or Schema

Let's get your GraphQL into the formatter! Whether you're working with Apollo Client, need to validate schemas, or want to minify queries later, you have several convenient options:

•
Paste directly: Copy your GraphQL query or schema and paste it into the input editor
•
Upload a file: Click "Upload" to select a .graphql or .gql file from your computer
•
Try the sample: Click "Sample" to load example data and see how the formatter works

Example: Unformatted GraphQL Query Input

Here's what messy, unformatted GraphQL looks like:

query{user(id:"123"){name email posts{title content comments{author message}}}}
Step 2

Automatic Formatting & Validation

About half a second after you stop typing, the formatter reads your GraphQL and:

•
Checks the syntax: If the document doesn't parse, you see the parser's message and the line and column where it stopped
•
Adds proper indentation: Makes nested queries and schema types easy to read
•
Keeps what you wrote: # comments, strings, descriptions and numbers like 14.50 come through unchanged; only the spacing and line breaks move

Example: Beautifully Formatted Output

The same query, now properly formatted and readable:

query {
  user(id: "123") {
    name
    email
    posts {
      title
      content
      comments {
        author
        message
      }
    }
  }
}
Step 3

Choose Format Options

There are two ways to look at the result:

•
Pretty format: Default beautified GraphQL with proper indentation (2 spaces)
•
Minify option: Click "Minify" for a compact version without comments or extra spaces, handy for query strings and request bodies. The button then reads "Format" to switch back
•
Syntax highlighting: Color-coded elements make it easy to spot queries, mutations, and fragments
Step 4

Export Your Formatted GraphQL

When it looks right, take it with you:

•
Copy to clipboard: One-click copying for quick pasting into your code editor or application
•
Download as file: Save as a .graphql file for later use or sharing with your team
•
Syntax check, not a schema check: The green badge means the document parses. It does not know which fields your API has, so run queries against your server or a schema validator as well

Frequently Asked Questions

How do I format messy GraphQL queries?

Paste the query into the input editor. Once you stop typing, it comes back with two-space indentation, one field per line and long argument lists broken over several lines. Queries copied out of browser DevTools, logs or a minified bundle usually arrive on a single line, and this is the quickest way to read them again.

Can I format GraphQL schemas as well as queries?

Yes. Anything the GraphQL spec allows is accepted: queries, mutations, subscriptions, fragments, and schema definitions such as type, interface, union, enum, input, scalar, directive and schema blocks, including their descriptions and extend statements.

Will formatting change my comments, strings or numbers?

No. Unlike printers that rebuild the document from scratch, this one keeps your # comments, and strings, block-string descriptions, enum values and numbers stay exactly as typed, so a default like 8901240544102066246 or 14.50 is not rounded or re-spelled. Before showing anything, the formatter parses its own output and only uses it if it describes exactly the same document as your input. Comments may move to their own line, but they are never dropped.

What happens when my GraphQL has a syntax error?

You get the error message from the GraphQL parser together with the line and column where it stopped, for example a missing closing brace or a colon in the wrong place. Nothing is fixed for you, and no output is shown until the document parses. If you paste JSON by mistake, such as a request body with a "query" field, the page tells you so.

What does the Minify button do?

It removes every space, line break, comma and comment that GraphQL ignores, using the same rules as the graphql-js stripIgnoredCharacters function. The text inside strings and block strings is left alone. Comments are the one thing that does not survive minifying, so keep the formatted version as your source copy.

Does the formatter check my query against my schema?

No, it only checks syntax. A query that asks for a field your API does not have will still format fine. To check a schema file on its own, use the GraphQL Schema Validator.

Is my GraphQL uploaded anywhere?

No. Formatting runs in your browser, so the query or schema is not sent to our server, and nothing is kept: reloading the page starts with an empty editor.

Related: check a schema file with the GraphQL Schema Validator, squeeze a query down with the GraphQL Minifier, or turn a schema into TypeScript types.