Skip to content
⚠ TESTING ENVIRONMENT You are viewing a testing copy of Tolioo. Changes here do not affect the live website.

GraphQL Query Formatter

Format and beautify GraphQL queries, mutations, fragments and schemas with clean indentation. Fast, free and no signup.

  • 100% free
  • No Signup
  • Runs in your browser

Your GraphQL

0 B
ADVERTISEMENT
Demo Ad 728 x 90

Format GraphQL in 3 simple steps

  1. 1

    Paste or upload

    Paste your query or schema, or upload a .graphql file.

  2. 2

    Choose your settings

    Pick the indent, argument wrapping and how comments are handled.

  3. 3

    Copy or download

    Copy the clean GraphQL or save it as a .graphql file.

GRAPHQL FORMATTER GUIDE

GraphQL Query Formatter – Format and Beautify GraphQL Online

Looking for a free GraphQL query formatter? Paste a messy, minified or copied GraphQL query and get clean, readable code in one click. Our online GraphQL formatter, also known as a GraphQL beautifier or GraphQL prettifier, adds consistent indentation, puts every field on its own line and wraps long arguments so your queries, mutations, fragments and schemas are easy to read. There is nothing to install and no account to create. Whether you are debugging an API request, cleaning up a query from your browser's network tab, or tidying a schema before a code review, this tool formats your GraphQL directly in your browser. Copy the result or download it as a .graphql file.

People search for this tool as a graphql formatter, graphql beautifier, graphql prettifier, format graphql query online or graphql schema formatter. The need is always the same: a query that arrives on one line, with odd spacing or copied from a log, and you want to read it. This free GraphQL pretty print tool lays out queries, mutations, subscriptions, fragments and schema definitions with clean indentation. It runs in your browser on Windows, Mac, Linux, Android and iPhone, so you can fix a query from your phone as easily as from your desk.

Format GraphQL Queries Online

Turn a one-line query into a neatly indented document. Queries, mutations, subscriptions, variables, aliases, fragments and directives are all formatted correctly.

GraphQL Schema (SDL) Support

Beautify type definitions, interfaces, enums, inputs, unions and directives as well. Descriptions and block strings keep their meaning and are placed neatly above each field.

Smart Argument Wrapping

Short arguments stay on one line, and long argument lists are split across lines at the width you choose, so even complex queries stay readable.

How to Format a GraphQL Query Online

You do not need an editor plugin or a command line tool to format GraphQL. Follow these simple steps.

  1. Add your GraphQL: Paste your query, mutation or schema into the editor, or upload a .graphql or .gql file.
  2. Choose your indentation: Select 2 spaces, 4 spaces or tabs. Two spaces is the most common style in GraphQL projects.
  3. Set the wrap width: Choose 80 or 120 characters, or turn wrapping off to keep arguments on one line.
  4. Pick your options: Decide whether to keep comments, add blank lines between definitions and preserve the blank lines you wrote inside blocks.
  5. Format: Click the format button, then copy the result or download it as a .graphql file.

If your GraphQL has a problem, such as a missing closing brace or an unclosed string, the tool shows an error message with the line number so you can fix it quickly.

What Is GraphQL?

GraphQL is a query language for APIs and a runtime for answering those queries with your existing data. It was developed at Facebook and released as an open standard in 2015. Instead of calling many fixed endpoints, a client sends one request that describes exactly which fields it needs, and the server returns data in the same shape. This avoids over-fetching and under-fetching, which is one reason GraphQL is popular for web and mobile applications.

What Is a GraphQL Query Formatter?

A GraphQL query formatter rewrites GraphQL code so that people can read it easily. It does not change what the query asks for. It only changes the layout: indentation, line breaks and spacing. Here is a query before formatting:

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

And the same query after using the GraphQL formatter:

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

The same works for schemas. Here is a GraphQL schema type before and after formatting:

type User implements Node{id:ID! name:String posts(first:Int=10):[Post!]!}
type User implements Node {
  id: ID!
  name: String
  posts(first: Int = 10): [Post!]!
}

GraphQL Syntax Cheat Sheet

This quick reference covers the main parts of GraphQL syntax. All of them are supported by the formatter above.

ConceptExampleWhat it does
Queryquery { user { name } }Reads data from the API
Mutationmutation { deleteUser(id: 1) { id } }Creates, updates or deletes data
Subscriptionsubscription { messageAdded { text } }Receives real-time updates
Argumentsuser(id: 1)Passes values to a field
Aliasadmin: user(id: 1)Renames a field in the result
Variablesquery($id: ID!) { user(id: $id) { name } }Passes dynamic values safely
Fragmentfragment F on User { name } and ...FReuses a group of fields
Inline fragment... on Admin { role }Selects fields for a specific type
Directivename @include(if: $show)Includes or skips a field conditionally
Comment# this is a commentAdds a note that the server ignores

What This GraphQL Formatter Supports

  • Operations: Queries, mutations and subscriptions, including anonymous operations written as a single selection set.
  • Variables and arguments: Variable definitions with default values, nested objects and lists.
  • Fragments: Named fragments, fragment spreads and inline fragments with type conditions.
  • Directives: Directives with arguments on fields, fragments and operations.
  • Schema definitions: Types, interfaces, unions, enums, input types, scalars, directive definitions and extensions.
  • Descriptions and comments: String and block string descriptions are kept, and hash comments can be kept or removed.
  • Strings and values: Strings, numbers, booleans, enums and null values are left exactly as written.

Why Should You Format GraphQL Queries?

  • Easier debugging: A clear structure shows which field belongs to which parent, so mistakes are easier to find.
  • Readable network requests: Queries copied from browser developer tools or API clients are often minified. Formatting makes them readable in seconds.
  • Cleaner code reviews: A consistent layout keeps reviews focused on what changed instead of spacing.
  • Better documentation: Neatly formatted examples are easier to share in tickets, wikis and pull requests.
  • Faster learning: Beginners understand nested selections much faster when the indentation matches the structure.

How to Format a Query from Your Browser or API Client

Open your browser's developer tools, go to the network tab and find the GraphQL request. Copy the query and paste it into the editor. If you copy the whole JSON request body that contains a query field, this tool detects it and formats the query inside automatically. The same works for queries copied from API clients and from logs.

Need to inspect the rest of the JSON body, such as the variables? Use our JSON formatter to read it clearly.

GraphQL Formatting Best Practices

  • Give every operation a name, such as GetUser, so it is easy to find in logs and monitoring tools.
  • Use variables instead of putting values directly in the query. It is safer and makes queries reusable.
  • Put one field on each line and indent nested selections by one level.
  • Move repeated groups of fields into fragments to keep queries short.
  • Write descriptions for types and fields in your schema, because they appear in documentation and editors.
  • Agree on one style, such as two-space indentation, and format every file the same way.

Common GraphQL Syntax Errors and How to Fix Them

  • Missing closing brace: Every opening curly brace needs a matching closing brace. The formatter reports where the unmatched brace starts.
  • Unclosed string: A quoted string must end on the same line unless you use a block string with triple quotes.
  • Unexpected character: Characters such as a stray semicolon are not valid in GraphQL. The error message shows the line.
  • Mismatched brackets: A square bracket closed by a parenthesis is reported with its line number.
  • Commas: Commas are optional whitespace in GraphQL, so the formatter removes them between fields and keeps neat separators inside arguments and lists.

Remember that a formatter checks the structure and punctuation of your code. It does not check your query against a schema, so a field name that does not exist is not reported.

Who Uses a GraphQL Formatter?

Front-end developers use it to clean up queries before adding them to React, Vue or mobile apps. Back-end developers use it to tidy schemas and resolvers documentation. QA engineers use it to read requests captured during testing, and technical writers use it to prepare clear API examples. Anyone who works with a GraphQL API can save time with a reliable online GraphQL query formatter.

More Free Developer Tools

Working with APIs? Try these related tools: the JSON Formatter, the URL Encoder / Decoder, the Base64 Encode / Decode tool and the Regex Tester. You can also browse all of our free online tools.

GraphQL Formatter Settings Explained

Each setting changes the layout of your GraphQL only. The fields, arguments and values stay exactly the same.

GraphQL formatter settings
Setting Choices What it does
Indentation 2 spaces, 4 spaces or Tab Sets how far each nested selection is moved to the right
Wrap long arguments at 80, 120 or Never Moves arguments to separate lines when a line gets longer than the limit
Keep comments On or off Turn it off to remove every # comment from the output
Blank line between definitions On or off Separates queries, fragments and types with an empty line
Keep blank lines inside blocks On or off Preserves single empty lines that you added on purpose

Common GraphQL Formatting Problems and How to Fix Them

If the result is not what you expected, check these points first.

GraphQL formatting problems and fixes
Problem Likely cause How to fix it
A syntax error is shown A missing brace, parenthesis, quote or colon Count the opening and closing braces and check every argument list
Comments are gone Keep comments is turned off Turn the option on to keep # comments
Long arguments stay on one line Wrapping is set to Never or the limit is high Choose 80 or 120 for the wrap setting
Definitions run together The blank line option is off Turn on Blank line between definitions
Query looks right but fails on the server Formatting does not check your query against a schema Run it in your API client or a schema-aware tool
Pasted text contains \n characters The query was copied from a JSON string Copy only the query value and replace the escaped line breaks first

Format GraphQL on Mobile, Windows and Mac

Our GraphQL formatter runs in your web browser, so you can beautify a query on Android, iPhone, Windows, Mac and Linux without installing an editor extension or a command line tool. Open the page, paste your code, pick your settings and copy the result. It works the same way in Chrome, Edge, Firefox and Safari.

Is It Safe to Format GraphQL Online?

Your GraphQL is formatted inside your browser. It is not uploaded, saved or stored on a server, and it disappears when you close or refresh the page. Queries often contain real IDs, tokens in variables or internal field names, so as a general habit with any online tool, replace sensitive values with dummy data when you can.

Free GraphQL Query Formatter Online

Our free GraphQL query formatter helps you beautify GraphQL queries, mutations and schemas online without signup or a watermark. Your code is processed directly in your browser, so you can clean up GraphQL quickly and copy or download the result whenever you need it.

ADVERTISEMENT
Demo Ad 300 x 250
COMMON QUESTIONS

Frequently Asked Questions About the GraphQL Query Formatter

Find answers to common questions about formatting GraphQL queries, schemas and requests.

What is a GraphQL query formatter?

A GraphQL query formatter, also called a GraphQL beautifier or prettifier, rewrites GraphQL code with consistent indentation, line breaks and spacing. The query itself does not change. Only the layout does, so it is easier to read, edit and debug.

How do I format a GraphQL query online?

Paste your GraphQL into the editor or upload a .graphql file, choose your indentation and options, and click the format button. Then copy the formatted code or download it as a .graphql file.

Can it format a GraphQL schema as well as queries?

Yes. The formatter supports schema definitions such as types, interfaces, unions, enums, input types, scalars and directive definitions, as well as queries, mutations, subscriptions and fragments. Descriptions are kept and placed above the field they describe.

Will formatting change what my query does?

No. Formatting only changes whitespace and layout. Field names, arguments, variables and values stay the same, so the query returns the same result. If you turn on comment removal, comments are deleted, but comments never affect how a query runs.

What happens to commas and comments?

Commas are optional in GraphQL, so the formatter removes them between fields and adds clean separators inside argument lists. Comments that start with a hash symbol are kept in place by default, and you can switch them off with one option.

Can I paste a JSON request body that contains a query?

Yes. If your input is a JSON object with a query field, such as a request copied from the network tab, the tool extracts the query and formats it. Other fields in the JSON, such as variables, are not included in the output.

Is my GraphQL code uploaded to a server?

No. The formatting runs inside your browser, so your code stays on your device and is not uploaded or stored by this tool.

ADVERTISEMENT
Demo Ad 320 x 50