Skip to main content
CaseSwitch

GraphQL Formatter

Use the CaseSwitch GraphQL Formatter to pretty-print a one-line query or mutation so it is readable in a ticket. Paste the operation, copy the indented result. Formatting runs in this browser — the query is not sent to any API.

Written by the CaseSwitch editorial team. We maintain these tools in the browser so drafts, keys, and images stay on your device.

Last reviewed: 23 July 2026

Processed locally in your browser. Nothing is sent to a server.

Paste or type text to convert. Output stays empty until there is input.

Character count: 0 · Word count: 0 · Line count: 0

Examples

Query with nested fields

Input

query{user(id:1){name email}}

Output

query {
  user(id: 1) {
    name
    email
  }
}

Mutation with variables

Input

mutation($id:ID!){deleteUser(id:$id){ok}}

Output

mutation ($id: ID!) {
  deleteUser(id: $id) {
    ok
  }
}

Anonymous selection set

Input

{ hero { name } }

Output

{
  hero {
    name
  }
}

Fragment

Input

fragment U on User{id name}

Output

fragment U on User {
  id
  name
}

Named query with string variable

Input

query Q($n:String!){search(q:$n){id}}

Output

query Q($n: String!) {
  search(q: $n) {
    id
  }
}

How to use

  1. Paste a GraphQL operation or fragment.
  2. Copy the indented document if formatting succeeds.
  3. Format variables separately as JSON if you need those pretty-printed too.

What this tool is for

Network-tab queries arrive as a single line. This page indents selection sets, arguments, and fragments with Prettier’s GraphQL parser so humans can review them. It does not execute operations and is not schema-aware against your production graph.

How it works

Pretty mode runs Prettier with the GraphQL parser. Fields, nested selections, and variable definitions get consistent wrapping. Invalid documents fail instead of guessing. Variables JSON belongs on the JSON Formatter, not inside this panel.

When to use it

Cleaning a query copied from a network tab, sharing a fragment in a PR, teaching selection sets, and normalizing a mutation before documentation.

When not to use it

Not GraphiQL. Not a mutation runner. Do not paste auth headers into the query text. Schema validation needs your GraphQL server or IDE plugins.

How it compares to related tools

JSON Formatter for variables JSON. JavaScript Formatter for resolver code. This page is only the GraphQL document.

Common mistakes

Formatting a query and accidentally committing leftover client-only directives your server rejects. Pasting secrets in `#` comments. Expecting unused field warnings — there is no schema here.

Documents vs variables

The operation document and the variables object travel separately on the wire. Format the document here. Paste variables JSON into the JSON formatter. Do not concatenate them into one invalid GraphQL file.

No execution, no schema

Formatting never hits your API. Unknown fields still format if the syntax is valid. Use your IDE’s GraphQL plugin or the server for schema errors.

Frequently asked questions

Does this execute the query?+

No. Local text formatting only.

Are GraphQL variables formatted?+

The query document is the focus. Format variables JSON in the JSON formatter.

Will it check fields against my schema?+

No. Syntax formatting only. Schema-aware checks need your tooling.

Can I format multiple operations?+

A document with several operations may format if it is valid GraphQL. Prefer one operation per paste for clarity.

Is my query uploaded?+

No. Formatting runs in this browser. Still avoid pasting tokens in comments.

Why did spacing around colons change?+

Prettier GraphQL normalizes argument and type punctuation. Meaning stays the same.

Does this tool send my payload to CaseSwitch?+

No. Formatting, encoding, and naming conversions for this page run in your browser after load — your sample stays on the device.

Related tools