GraphQL Formatter

Format GraphQL operations and schema definitions so nested selections are easy to read. Useful for queries copied from logs or network tabs.

Loading tool…

About the GraphQL Formatter

GraphQL queries captured from browser dev tools or server logs usually arrive as a single line. This tool parses them with the reference graphql-js grammar (via Prettier's GraphQL plugin) and prints each field of a selection set on its own line, indented by depth. Arguments stay inline when they fit within the print width and break one per line when they do not; variable definitions follow the same rule.

It handles executable documents — queries, mutations, subscriptions, fragments, inline fragments (... on User), aliases (thumb: image(size: SMALL)) and directives like @include(if: $flag) — as well as schema definition language: type, interface, union, enum, input, scalar, extend and descriptions in triple-quoted strings. Several definitions in one document are separated by a blank line. Comments starting with # are kept.

The formatter checks syntax only; it does not validate field names against a schema. Syntax errors, such as a missing closing brace, are reported with line and column. Queries are processed locally, so it is safe to paste operations that expose internal field names.

How to use it

  1. Paste a GraphQL query, mutation or schema.
  2. Set the indentation and print width.
  3. Check the output for the nested structure.
  4. Copy it back into your client or .graphql file.

Frequently asked questions

Does it validate my query against the schema?
No. It only checks GraphQL syntax. Field and type validation needs the schema, for example via GraphiQL or graphql-inspector.
Can I format a query from a JSON request body?
Yes, but first copy the value of the query field and unescape it (replace \n and \"). The JSON Formatter helps you read the body.
Are commas required between fields?
No. Commas are insignificant in GraphQL. Prettier removes them between fields and uses them between arguments.

Related tools