tool
GraphQL Formatter, Validator & Minifier
Format queries, mutations and schemas, find syntax errors and minify GraphQL for smaller requests.
paste your code and choose format or minify
Format, validate and minify GraphQL
Paste a GraphQL query, mutation, subscription, fragment or a schema written in SDL and turn it into readable, indented code, with one field per line and nested selections clearly laid out. Validate it to catch syntax errors such as a missing brace or a misplaced argument, with the exact line and column. Or minify it into a compact single-line document for request bodies, persisted queries and URLs. Everything runs locally in your browser.
What can you do?
- 1. Format queries and schemas
Operations, fragments, variables with default values, directives, input objects and type definitions (type, input, enum, interface, union, scalar, directive) are all formatted with Prettier. - 2. Validate GraphQL syntax
Get a precise message such as “Line 1, column 15: Expected Name, found "{"” when the document doesn't parse. - 3. Minify GraphQL
Remove whitespace, line breaks, # comments and optional commas. String values and """block string""" descriptions are kept exactly as written. - 4. Token-verified minification
The minified document is parsed again and compared token by token with the original, so the query your server receives is exactly the same. - 5. Definition count
See how many operations, fragments and type definitions a document contains.
Why format and minify GraphQL?
GraphQL queries are often built in one place and read in another: copied from browser network logs, pasted from an API explorer, embedded in code as single-line strings. Formatting turns those dense strings back into a structure that mirrors the shape of the response you'll get.
Minifying goes the other way. Whitespace and commas are meaningless in GraphQL, so removing them shrinks request bodies and GET URLs without changing the operation at all, which is useful for persisted queries, CDN-cached GET requests and logs.
How to format a GraphQL query
- 1. Paste the query or schema
One operation, several operations with fragments, or an entire schema.graphql file. - 2. Choose format, minify or validate
The document is parsed first, so you'll know immediately if it's invalid. - 3. Fix syntax errors
Jump to the reported line and column and correct the problem. - 4. Copy the result
Paste it into your client code, API explorer or schema file.
Example: a query formatted and minified
The minified version has no commas between variables and arguments. That's valid: commas are optional in GraphQL and are treated like whitespace, so ($a: Int, $b: Int) and ($a:Int $b:Int) mean exactly the same thing.
What a GraphQL document can contain
| Definition | Used in | Example |
|---|---|---|
| query | Clients | query GetUser($id: ID!) { … } |
| mutation | Clients | mutation AddItem($input: ItemInput!) { … } |
| subscription | Clients | subscription OnMessage { … } |
| fragment | Clients | fragment UserFields on User { … } |
| type / input / enum | Schemas | type User { id: ID! name: String } |
| interface / union | Schemas | union SearchResult = User | Post |
| scalar / directive | Schemas | directive @auth(role: String) on FIELD_DEFINITION |
| extend | Schemas | extend type Query { me: User } |
Frequently asked questions
Does validation check my query against a schema?
No. It checks GraphQL syntax only. Whether a field exists, an argument has the right type or a fragment matches its type depends on your server's schema, which tools like GraphiQL, Apollo Studio or graphql-codegen check against.
Are comments kept?
Formatting keeps # comments. Minifying removes them, because they are ignored by GraphQL servers. Descriptions written as strings ("…" or """…""") are part of the schema, so they're always kept.
Can I minify a schema (SDL) as well as queries?
Yes. Type definitions, directives and descriptions minify the same way as operations.
Will a minified query still work with my GraphQL client?
Yes. Apollo, Relay, urql and plain fetch requests send the query as a string, and any spec-compliant server parses the minified version exactly like the formatted one.
Is my query or schema uploaded?
No. Everything is processed in your browser.
Related tools
Turning a GraphQL response into types? Paste the JSON into the JSON to TypeScript converter.
- JSON Formatter & Validator – Pretty-print, validate and minify JSON.
- JSON to TypeScript Converter – Generate interfaces and types from JSON, or JSON from types.
- TypeScript Formatter & Validator – Format TypeScript and TSX and check them for syntax errors.
- Diff Checker – Compare two versions of text or code line by line.