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.
Format and beautify GraphQL queries, mutations, fragments and schemas with clean indentation. Fast, free and no signup.
Paste your query or schema, or upload a .graphql file.
Pick the indent, argument wrapping and how comments are handled.
Copy the clean GraphQL or save it as a .graphql file.
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.
Turn a one-line query into a neatly indented document. Queries, mutations, subscriptions, variables, aliases, fragments and directives are all formatted correctly.
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.
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.
You do not need an editor plugin or a command line tool to format GraphQL. Follow these simple steps.
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.
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.
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!]!
}
This quick reference covers the main parts of GraphQL syntax. All of them are supported by the formatter above.
| Concept | Example | What it does |
|---|---|---|
| Query | query { user { name } } | Reads data from the API |
| Mutation | mutation { deleteUser(id: 1) { id } } | Creates, updates or deletes data |
| Subscription | subscription { messageAdded { text } } | Receives real-time updates |
| Arguments | user(id: 1) | Passes values to a field |
| Alias | admin: user(id: 1) | Renames a field in the result |
| Variables | query($id: ID!) { user(id: $id) { name } } | Passes dynamic values safely |
| Fragment | fragment F on User { name } and ...F | Reuses a group of fields |
| Inline fragment | ... on Admin { role } | Selects fields for a specific type |
| Directive | name @include(if: $show) | Includes or skips a field conditionally |
| Comment | # this is a comment | Adds a note that the server ignores |
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.
GetUser, so it is easy to find in logs and monitoring tools.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.
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.
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.
Each setting changes the layout of your GraphQL only. The fields, arguments and values stay exactly the same.
| 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 |
If the result is not what you expected, check these points first.
| 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 |
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.
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.
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.
Find answers to common questions about formatting GraphQL queries, schemas and requests.
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.
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.
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.
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.
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.
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.
No. The formatting runs inside your browser, so your code stays on your device and is not uploaded or stored by this tool.
Format GraphQL here, then format JSON, convert cURL to code, decode a JWT or encode a URL in seconds. Explore free developer tools to format, convert and debug your API work in one place.
Explore All Developer Tools →