GraphQL Formatter and Validator

Format GraphQL queries, mutations, and schema definitions into clean, consistent code, or minify them for sending. Syntax errors are reported with their line and column.

Updated
Runs in your browser. Your data is not uploaded.
Mode
Formats as you type for inputs up to 200 KB.

How to use the GraphQL Formatter

  1. Paste a query or schema into GraphQL input, or upload a .graphql file.
  2. Choose Beautify for readable code or Minify for the shortest form.
  3. Press Format. Copy the result, or fix the error shown under the input.

How it works

The input is parsed with graphql-js, the reference implementation of the GraphQL specification, into a syntax tree. That parse is the validation step: anything the specification's grammar doesn't allow is an error.

  • Beautify prints the tree with the reference printer: two-space indentation, one field per line, and consistent spacing in arguments and directives.
  • Minify removes every character the grammar ignores, including whitespace, commas, and comments, while keeping string contents.
  • The summary counts operations, fragments, and type definitions.

Examples

Input:

query GetUser($id:ID!){user(id:$id){id name posts(first:5){title}}}

Beautified:

query GetUser($id: ID!) {
  user(id: $id) {
    id
    name
    posts(first: 5) {
      title
    }
  }
}

A missing closing brace, as in { user { id }, gives: Syntax Error: Expected Name, found <EOF>, at the end of the input.

Limitations

  • Validation checks syntax only. Without your server's schema, the tool can't tell whether a field or argument exists.
  • Beautify removes comments, because the printer works from the syntax tree. Keep a copy if the comments matter.
  • Files are limited to 5 MB.

Frequently asked questions

Can this check my query against my API's schema?

No. It checks that the query is valid GraphQL syntax. To check field names and types, run it against your API or use your server's introspection in a GraphQL IDE.

Can I format schema files (SDL)?

Yes. Type definitions, interfaces, enums, inputs, unions, directives, and schema extensions are all formatted.

Why minify a GraphQL query?

Queries are sent in request bodies or URLs. Minifying makes them smaller, which helps with GET requests and persisted queries.

Is my query uploaded?

No. It is parsed and printed in your browser.

Often used together with the GraphQL Formatter & Validator.