Home › Developer Tools › GraphQL Formatter

GraphQL Formatter

Paste a messy GraphQL query, mutation or schema and get clean, consistently indented code, or a minified one-liner. It runs entirely in your browser, so private APIs and schemas never leave your device.

Last updated:

Tip: press Ctrl + Enter in the input to format. Everything runs in your browser; your schema never leaves this page.

Advertisement

How to use the GraphQL Formatter

  1. Paste your GraphQL query, mutation, fragment or schema into the input box, or open a .graphql file.
  2. Choose the indentation (2 spaces, 4 spaces or tabs) and whether to keep # comments.
  3. Press Format GraphQL (or Ctrl + Enter). With Format as I type on, the output updates while you edit.
  4. Fix errors: if the syntax is invalid you see the line and column with a caret; press Show in input to jump there.
  5. Copy or download the result, or press Minify to get a compact single-line version for requests.

Before and after formatting

GraphQL ignores whitespace and commas, so queries copied from logs, network tabs or code generators are often a single dense line. The formatter rebuilds them with one field per line and one level of indentation per selection set:

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

GraphQL syntax cheat sheet

ConstructExampleNotes
Aliassmall: avatar(size: 32)Rename a field in the response; lets you request the same field twice.
Variablesquery Q($first: Int = 10)Typed, optional default value; ! marks a required (non-null) type.
Fragmentfragment F on User { id } + ...FReusable selection set with a type condition.
Inline fragment... on Admin { permissions }Select fields only for a concrete type of an interface or union.
Directives@include(if: $x), @skip, @deprecatedAnnotate fields, fragments, operations or schema elements.
Input object valueorderBy: { field: NAME, direction: ASC }Kept inline; enums are written without quotes.
Block string"""Multi-line description"""Common indentation is removed, so the formatter can re-indent it safely.
Comment# noteRuns to the end of the line; ignored by the server.

Common GraphQL syntax errors

  • Expected Name, found "}": an empty selection set such as user { }, or a missing field after a comma or alias colon.
  • Expected "on": a fragment definition needs a type condition, for example fragment UserFields on User.
  • Unterminated string: a regular "string" cannot span lines; use a """block string""" instead.
  • Unexpected character: smart quotes (“ ”) pasted from documents or chat apps are not valid. Replace them with straight quotes.
  • Variables are not allowed in constant values: default values and directives in a schema cannot use $variables.

Working with the JSON responses too? Tidy them with the JSON Formatter, or compare two versions of a schema with the Code Diff Checker.

Frequently asked questions

Does this GraphQL formatter send my query or schema to a server?

No. The tokenizer, parser and printer are plain JavaScript running in your browser tab. Nothing you paste is uploaded or stored, so it is safe for internal schemas and queries containing IDs.

Does it validate my query against a schema?

It checks GraphQL syntax only: brackets, strings, names, arguments, directives and definition structure, following the GraphQL specification grammar. It does not know your server's schema, so it cannot tell you that a field or type does not exist.

Can it format SDL schema files?

Yes. Type, interface, input, enum, union, scalar, schema and directive definitions are supported, as well as extend type and other extensions, descriptions in quotes or triple-quoted block strings, implements A & B, default values and repeatable directives.

What happens to commas in GraphQL?

In GraphQL commas are insignificant, like whitespace. The formatter separates inline arguments and list items with a comma and a space for readability, and removes them when arguments are split over several lines or when you minify.

Are comments preserved?

Yes, # comments are kept on their own line before the item they precede, and a comment that ended a line stays at the end of that line. Untick Keep # comments to remove them. Minify always removes comments, because they are not needed by the server.

Why minify a GraphQL query?

A minified query is smaller in HTTP requests, persisted-query maps and URLs for GET requests. The server parses it exactly the same as the formatted version, because whitespace, commas and comments carry no meaning.

How are long lines handled?

If a field's arguments, an operation's variables or a field definition's arguments would make a line longer than 80 characters, each item is placed on its own line, similar to Prettier and graphql-js print.

Are all the tools on FreeToolCabin tested for quality and accuracy?

Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.

Related tools

JSON FormatterBeautify, minify and validate JSON, with a collapsible tree view.SQL Formatter & BeautifierFormat, beautify or minify SQL queries for MySQL, PostgreSQL and more.JavaScript BeautifierFormat and beautify messy or minified JavaScript, or minify it.Code Diff CheckerCompare two code files side by side or unified, with syntax colors and changes highlighted.HTML FormatterBeautify and indent HTML code with a live preview.CSS FormatterBeautify CSS with indent controls and optional property sorting.XML FormatterBeautify, validate and minify XML with a collapsible tree view.ZIP File CreatorCompress files and folders into a ZIP.YAML Validator & FormatterValidate, format and minify YAML, and convert YAML to JSON or back.HTML MinifierMinify HTML: strip comments and whitespace safely and see how many bytes you save.CSS MinifierMinify CSS with csso or a built-in engine and see the size saved instantly.JavaScript MinifierMinify JavaScript with Terser: compress, mangle and see how many bytes you save.JSON MinifierMinify and validate JSON, sort keys and see exactly how many bytes you save.IPv6 Expander & CompressorExpand IPv6 addresses to full form or compress them per RFC 5952, one or many at once.CSS ValidatorValidate CSS: syntax errors, unknown properties and invalid values by line, plus auto-fix.Gzip Compress / DecompressGzip or deflate text and files, get Base64 output, and decompress Base64 or .gz files.IBAN ValidatorCheck an IBAN's mod-97 checksum, country and length, and see its bank code and account parts.JavaScript Syntax CheckerCheck JavaScript for syntax errors with line and column, for any ES version, script or module.JSON Schema ValidatorValidate JSON against a JSON Schema (draft-07, 2019-09, 2020-12) with clickable error paths.Markdown FormatterBeautify Markdown with Prettier: list markers, prose wrap, aligned tables and live preview.PHP FormatterBeautify PHP code with Prettier PHP: PSR-12 style, indent and brace options, syntax errors.TypeScript FormatterFormat TypeScript and TSX code with Prettier: width, tabs, semicolons and quotes options.XML MinifierMinify and validate XML: strip whitespace and comments, keep CDATA, see the size savings.C# FormatterBeautify C# code online: Allman or K&R braces, indent size and line width, clang-format option.HTML ValidatorCheck HTML for errors and warnings with line numbers, locally or with the W3C Nu checker.Java FormatterBeautify Java code online: indent size, brace style and line width, with clang-format option.JavaScript ObfuscatorObfuscate JavaScript with string encoding, renaming and control-flow flattening presets.Phone Number FormatterFormat and validate lists of phone numbers to E.164, international or national style.Python FormatterFormat Python code in Black/Ruff style: line length, quote style, indent, copy or download.Responsive Design CheckerPreview any website at phone, tablet, laptop and desktop sizes side by side, with rotate and zoom.Browser Compatibility CheckerSearch CSS, JavaScript and HTML features and see which browser versions support them.Core Web Vitals CheckerCheck real-user LCP, INP and CLS for any URL or site and see if it passes Core Web Vitals.Heading Structure CheckerPaste HTML to see its H1-H6 outline and catch missing H1s, multiple H1s and skipped levels.Website Hosting CheckerFind out who hosts a website: hosting provider, IP addresses, ASN, network owner and location.Routing Number ValidatorCheck a US ABA routing number's checksum and format and see its Federal Reserve district.Spam Word CheckerScan an email subject and body for spam trigger words, excess caps, exclamation marks and risky links.Check Digit CalculatorCalculate or validate check digits for UPC, EAN, GTIN, SSCC, ISBN, ISSN and mod 11 codes.Luhn Algorithm CheckerValidate numbers with the Luhn mod 10 check or calculate the missing check digit, step by step.XSD ValidatorValidate XML against an XSD schema in your browser and see each error with its line number.Strftime Format BuilderBuild Python and C strftime format strings by clicking tokens, with a live preview and reference.
See all 41 Code Formatters & Validators →