GraphQL Formatter.
Format or minify GraphQL queries, fragments and SDL schemas; syntax errors are shown with line and column.
Runs in your browserAbout GraphQL Formatter
The GraphQL Formatter parses your document with a full GraphQL parser and prints it back in the layout most teams use: one field per line, two-space indentation, a blank line between definitions and arguments on one line until they get too long. It understands everything in the October 2021 specification, including queries, mutations, subscriptions, fragments, variables with default values, directives, block-string descriptions and every type-system definition and extension: schema, scalar, type, interface, union, enum, input and directive. Comments are not thrown away. A comment on its own line stays above the field it describes, and a comment at the end of a line, such as "email # shown in the header", stays on that line. Commas, which GraphQL treats as whitespace, are removed. Minify mode strips comments and all optional whitespace, which is handy for persisted queries or for pasting a query into a URL or a curl command. Because the input is really parsed, mistakes are caught with a precise position: a missing closing brace, an argument without a value as in user(id: ), a string that is not closed, or a stray character. The formatted output is tokenised again and compared with the input, so names, values and strings are guaranteed to be unchanged. For example, "{ me { id name } }" becomes a three-level indented selection set, and a long field such as users(filter: …, first: 20, after: …) is broken into one argument per line. The formatter does not validate your document against a schema. Nothing is uploaded; it runs in your browser.
How to Use
- Paste a query, mutation, fragment or schema.
- Choose Format or Minify and the indentation.
- Copy the result or download it as a .graphql file.
Frequently Asked Questions
Does it check my query against a schema?
No. It checks that the document is valid GraphQL syntax and formats it. Whether a field exists on a type depends on your server's schema, which the tool does not have.
Are comments preserved?
Yes, when formatting. Comments on their own line stay above the next field or definition and end-of-line comments stay on their line. Minify mode removes comments because they would need line breaks.
When are arguments split over several lines?
When the field and its arguments would be longer than 80 characters, or when an argument has a comment or a description. Otherwise they stay on one line.
Is my query sent to a server?
No. Parsing and formatting happen in your browser.
Related Tools
Pretty print, minify, and validate JSON.
Format and beautify SQL queries.
Build HTTP requests and generate code in cURL, PHP, JS, and Python.
Generate typed code from JSON data.
Convert curl commands to PHP, JavaScript, or Python code.
Create fake API endpoints that return the status, headers and JSON body you define.