All tools

GraphQL Formatter

Format and minify GraphQL

Pretty-print or minify GraphQL queries and schemas, with syntax errors shown at the exact line and column.

How to use GraphQL Formatter

  1. Paste a query, mutation, fragment or schema into Input GraphQL, drop a .graphql file on it, use Open file, or Try an example.
  2. Format pretty-prints with the Indent you choose (2 spaces, 4 spaces or tab). Minify removes everything that isn’t needed.
  3. If the input is invalid, the error shows its line and column with a caret, and Jump to error in input selects the spot.
  4. Copy the result, Download it or Send to… another tool.

How it works

A lexer turns the text into tokens (names, numbers, strings, block strings, punctuators; commas and whitespace are insignificant) and a recursive-descent parser checks them against the GraphQL grammar for executable documents and schema definitions: operations, variables and defaults, aliases, arguments, fragments, inline fragments, directives, descriptions, type, interface, union, enum, input, scalar, schema and directive definitions, and extend. The printer then lays the document out again. Argument lists and unions that don’t fit in 80 columns are broken over several lines, and block-string descriptions are re-indented. Minify drops comments and commas and keeps a space only where two tokens would merge. Everything runs in your browser, with no GraphQL library.

Limits

  • Input can be up to 5,000,000 characters (about 5 MB).
  • Comments are kept before definitions, fields and members, and before a closing brace. Comments anywhere else (for example inside an argument list) are removed, and the page tells you how many.
  • Syntax is checked, not meaning: unknown types, fields or fragments, and variables used where constants are required, aren’t reported.
  • Minify keeps string and block-string contents exactly as written.

Privacy

Your GraphQL is formatted in your browser and never uploaded or stored. Share puts the input and options in the link’s # fragment, which browsers don’t send to servers; long inputs show Too large to share. Text sent here or from here with Send to… passes through this tab’s session storage and is removed as soon as the receiving tool reads it.

Frequently asked questions

Does it format schemas as well as queries?

Yes: type definitions, descriptions, directives definitions and extend are all supported, alone or mixed with operations.

Will formatting change what my query does?

No. Only whitespace, commas and the layout of descriptions change; names, values and strings are kept.

Why was a comment removed?

Comments are kept only where they sit before a definition, field or member. A notice shows how many couldn’t be placed.

How are errors reported?

With the message, line and column of the first problem, such as Expected "}" or an unterminated string.

More tools