GraphQL Formatter

Pretty-print or minify GraphQL queries, fragments and schema SDL.

About this tool

Paste a GraphQL query, mutation, subscription, fragment or schema (SDL) and get it neatly indented, or minified for the smallest request body. Choose 2 spaces, 4 spaces or tabs. Unbalanced braces and broken strings are flagged.

How the formatting works

GraphQL copied from browser dev tools, logs or code is often a single long line. The formatter breaks it into one field per line, indents nested selection sets, and keeps arguments, variables, default values and inline input objects on one line, as in posts(first: $first, orderBy: {field: CREATED_AT, direction: DESC}). Aliases (name: displayName), fragment spreads (...PostMeta), inline fragments (... on User) and directives (@include(if: true)) are laid out consistently, with a blank line between operations or type definitions. Comments and """ block strings (schema descriptions) are kept. Commas are optional in GraphQL, so they're removed between fields and kept between arguments. Minify strips comments, commas and extra whitespace while keeping the query valid, which is useful for GET requests and persisted queries. Honest limits: this is a formatter, not a validator. It doesn't check field names against your schema and won't catch every syntax error, though it flags unbalanced braces and unterminated strings. JSON to GraphQL, the JSON formatter and the SQL formatter are related.

Frequently asked questions

How do I format a GraphQL query?

Paste it here and copy the indented result.

Can it minify GraphQL?

Yes. Choose Minify to strip comments, commas and whitespace.

Does it validate my query?

No. It formats structure but doesn't check fields against a schema.

Is my data uploaded?

No. Everything runs in your browser and nothing is stored or sent.