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
- Paste a GraphQL query, mutation or schema.
- Set the indentation and print width.
- Check the output for the nested structure.
- Copy it back into your client or .graphql file.
Frequently asked questions
Does it validate my query against the schema?
graphql-inspector.Can I format a query from a JSON request body?
query field and unescape it (replace \n and \"). The JSON Formatter helps you read the body.