query GetUser($id: ID!)
{
user(id: $id)
{
id name email posts
{
id title
}
}
}GraphQL Formatting and Beautifying
GraphQL queries can become hard to read when minified or poorly indented. A formatter adds consistent indentation (typically 2 spaces), places opening braces on their own lines, and nests field selections for clarity. This makes it easier to review queries, spot missing fields, and collaborate with teammates.
This tool supports queries, mutations, subscriptions, fragments, variables, and directives. Comments (# single-line and """ block) are preserved in format mode. Minify mode removes all whitespace for production use or embedding in code.
GraphQL Query Structure
A GraphQL document has operations (query, mutation, subscription) and optionally fragments. Each operation can have a name and variable definitions. The selection set uses curly braces; nested fields increase nesting depth. The tool reports field count (approximate number of field selections), nesting depth (maximum brace depth), and estimated complexity.
Deeply nested queries can be expensive. Use the stats to identify queries that might benefit from pagination, field limits, or restructuring. Many GraphQL servers enforce complexity limits to prevent abuse.
When to Format vs. Minify
Format (beautify) when you're writing, debugging, or sharing queries. Readable formatting helps catch typos and understand structure. Minify when you need to send a query in a single line (e.g., in a URL, log, or compact payload). Some clients minify automatically; this tool lets you do it manually for documentation or testing.
Copy the formatted or minified output with one click. Use it in GraphQL clients like Apollo, Relay, or urql, or paste into API documentation.
Frequently Asked Questions
Related Tools
Explore More Tools
Find this tool useful? Buy us a coffee to keep DuskTools free and ad-light.