GraphQL Formatter
Format or minify GraphQL queries, mutations, fragments and SDL schemas. Preserves block strings and comments, and reports the line of any unbalanced brace.
Formatted GraphQL
What is the GraphQL Formatter?
Paste a GraphQL query, mutation, fragment or SDL schema and this tool reformats it with clean two-space indentation, matching the output style of the reference GraphQL printer.
- Pretty-print and minify modes with selectable 2, 4 or 8 space indentation
- Block strings ("""…""") and string literals preserved exactly, and re-indented cleanly
- Handles queries, mutations, fragments, inline fragments, directives and full SDL schemas
- Reports the line number of any unbalanced brace, bracket or parenthesis
- Character counts and a size-saved percentage for minified output
- 100% client-side — your schema and queries are never uploaded
How to use the GraphQL Formatter
- 1
Paste your GraphQL document into the input box.
- 2
Choose Pretty-print or Minify, and pick an indent size of 2, 4 or 8 spaces.
- 3
In pretty mode, decide whether to keep # comments.
- 4
Check the character counts and, for minify, the percentage saved.
- 5
Copy the result, download it, or click Replace input to keep working on the formatted version.
About the GraphQL Formatter
Paste a GraphQL query, mutation, fragment or SDL schema and this tool reformats it with clean two-space indentation, matching the output style of the reference GraphQL printer. Selection sets are expanded one field per line, while argument lists and object values stay inline where they read better.
A hand-written tokeniser keeps string and block-string literals completely intact, preserves # comments in pretty mode, and understands that commas are insignificant in GraphQL — so they are dropped between fields but kept between arguments where they aid readability.
Minify mode strips comments, commas and all optional whitespace for sending queries over the wire. If a brace, bracket or parenthesis is unbalanced you get the line number rather than mangled output. Everything runs locally in your browser.
Frequently asked questions
How do I format a GraphQL query?
Paste it in and choose Pretty-print. Each field in a selection set moves onto its own line with two-space indentation, while arguments and object values stay inline, which is the same layout the standard GraphQL printer produces.
Are commas required in GraphQL?
No. GraphQL treats commas as insignificant whitespace, so they are optional everywhere. This formatter drops them between fields in a selection set and keeps them between arguments and object fields, which is the usual convention.
Does minifying a GraphQL query change its meaning?
No. Minifying only removes comments, commas and optional whitespace, all of which the parser ignores. The resulting document requests exactly the same data, just in fewer bytes.
Can it format an SDL schema as well as queries?
Yes. Type, interface, input, enum, union, scalar and directive definitions are all handled, including descriptions written as block strings and field arguments with default values.
What happens if my query has a syntax error?
Unbalanced braces, brackets and parentheses are reported with the line where the offending bracket was opened, and unterminated strings are named explicitly. The tool never emits half-formatted output for a broken document.
Is my GraphQL schema sent to a server?
No. Tokenising and formatting happen entirely in your browser, so internal schemas and queries containing field names you would rather not share stay private.
Related tools
JSON Formatter
Format, beautify and minify JSON online with 2-space, 4-space or tab indentation. Sort keys alphabetically and catch syntax errors instantly — free and private.
Postman Collection to cURL Converter
Convert an exported Postman collection into curl commands. Walks nested folders, substitutes {{variables}} and handles raw, form-data and urlencoded bodies.
CSS Formatter
Format and beautify CSS online: one declaration per line, tidy indentation, spaces after colons and support for nested at-rules. Free and 100% private.
JavaScript Formatter
Beautify JavaScript online with token-aware indentation. Respects strings, template literals, regex and comments. A quick, private, in-browser JS formatter.