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
- Paste a GraphQL operation or fragment.
- Copy the indented document if formatting succeeds.
- 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
JSON Formatter
Debugging a 401 response, comparing two configs, preparing a gist, shrinking a JSON blob before embedding it in a test fixture, and checking whether a file is actually JSON before you commit it. If you need to escape a string as a JSON literal, use JSON Stringify instead. If you need YAML, use JSON to YAML after the JSON is valid.
YAML Formatter
Cleaning a workflow file snippet, reviewing a Helm values fragment, normalizing list indentation, and teaching YAML structure on a short sample.
TypeScript Formatter
Cleaning a type copied from a library .d.ts, reviewing a generic-heavy snippet, preparing a PR comment, and normalizing a short TSX-ish example.
JavaScript Formatter
Reading a minified function from DevTools, cleaning a gist, sharing a snippet in a ticket, and normalizing a short example before a PR comment.
HTML Formatter & Minifier
Cleaning an email HTML snippet, reviewing a CMS export, shrinking a static fragment for a demo, and making a nested list readable before you edit it by hand.
CSS Formatter
Inspecting a production CSS file, cleaning a snippet from Stack Overflow, teaching cascade with readable examples, and preparing a small style review.
SCSS Formatter
Cleaning a mixin you copied, reviewing a theme file fragment, preparing a style PR comment, and teaching nesting with a readable example.