Free GraphQL Formatter
Beautify GraphQL queries, mutations, and schemas into clean, readable code. This formatter re-indents nested selection sets, normalizes spacing, and keeps arguments and directives tidy so long queries become easy to scan.
Schema work continues with the JSON Schema Generator, and the payloads it returns are read with the JSON Formatter & Beautifier. For the REST equivalent of the same request, the Curl Command Builder is the tool.
How to use the GraphQL Formatter
- 1 Paste your query, mutation or schema.
- 2 Format. Fields are indented by nesting depth and arguments are grouped.
- 3 Check the reported error for an unbalanced brace, which is the usual cause of a failure.
- 4 Copy the formatted result.
Reading a schema
GraphQL's strong point is that the schema describes the available data completely. A formatter makes that description legible: types, the fields they expose, which are required, and how they relate to other types. That is the reference you use to write a query.
The nesting is the thing to watch. Every field in a selection set must exist on the type returned by its parent, and a formatter's indentation mirrors that relationship. When a query fails validation, the misindented field is usually the one naming a field that does not exist at that level.
- One field per line, indented by selection depth.
- Arguments follow the field on the same line where short.
- Fragments and directives are preserved.
- The schema definition language uses the same conventions.
What is GraphQL?
GraphQL is a query language for APIs that lets a client request exactly the fields it needs. A query is written as a set of nested selection sets surrounded by braces; this formatter walks that structure and re-emits it with consistent indentation, which makes complex queries with deep nesting far easier to review.
Frequently asked questions
Why does GraphQL need its own formatter?
Because it has its own syntax. It is not JSON and not JavaScript, so neither formatter understands it. GraphQL has queries, mutations, fragments, variables with type annotations, directives, and schema definition language, all with their own indentation conventions that a generic tool will mangle.
What is the difference between a query and a mutation?
Semantically, a query reads and a mutation writes. Syntactically they are nearly identical. The distinction matters to the server's execution model: fields within a query may be resolved in parallel, whereas top-level mutation fields are guaranteed to execute in the order written, which is why mutations that depend on each other must be sequenced.
How should I format a query with variables?
Keep the operation signature on its own line with the variable definitions, then a blank line, then the selection set. Variables are declared with their types and can be marked required. Keeping the declaration separate from the body makes it obvious what the caller must supply.
Related Developer Tools
You might also need
Tools from other categories that people pair with the GraphQL Formatter: