Loading GraphQL Minifier...

How to Minify GraphQL Queries - Step by Step Guide

Step 1

Input Your GraphQL Query

Start with your GraphQL query or schema. Whether you're optimizing for Apollo Client, need to reduce bundle size, or want to format GraphQL first, you have several options:

•
Paste directly: Copy your GraphQL query and paste it into the input editor
•
Upload a file: Click "Upload" to select a .graphql or .gql file
•
Try the sample: Click "Sample" to see minification in action

Example: Original GraphQL Query

Here's a GraphQL query with comments and whitespace:

# Get user details
query GetUser {
  user(id: "123") {
    name
    email
  }
}
Step 2

Automatic Minification

The tool automatically compresses your GraphQL by:

•
Removing comments: Drops every # comment, including ones at the end of a line
•
Compressing whitespace: Removes spaces, tabs, line breaks and commas between tokens
•
Leaving values alone: Text inside strings and block strings, descriptions and numbers stay exactly as typed, following the GraphQL spec

Example: Minified Output

The same query, now compressed to a single line:

query GetUser{user(id:"123"){name email}}
✓ Reduced from 79 to 41 bytes (48% smaller)
Step 3

Review Size Reduction

See exactly how much space you've saved:

•
Size comparison: The badge above the output shows the size before and after in bytes and the percentage saved (phones show the percentage only)
•
Syntax check: Output only appears for GraphQL that parses; otherwise you get the error with its line and column
•
Same document: The minified text parses to exactly the same query or schema as your original
Step 4

Use in Production

Export and use your minified GraphQL:

•
Copy to clipboard: One-click copy for pasting into your code
•
Download file: Save as .graphql file for your project
•
Bundle optimization: Reduce bundle size in your application

Frequently Asked Questions

Why should I minify GraphQL queries?

Every query your app sends travels in the request body, and queries baked into a JavaScript bundle add to its size too. Taking out comments, indentation, line breaks and commas shrinks both. It matters most for apps that send a lot of queries over slow mobile connections, or that keep long queries in the bundle.

Does minification change what my query does?

No. The minifier first parses your document with graphql-js, the reference GraphQL implementation, and refuses to produce output if it doesn't parse. It then removes only what GraphQL itself ignores: whitespace, commas and # comments between tokens. String values, block strings, descriptions and numbers are copied exactly as you wrote them, so "a b" keeps both spaces and 8901240544102066246 keeps every digit.

How much space can I save by minifying?

It depends on how the query is written. A neatly indented query with a few comments usually shrinks by somewhere between a third and a half, while a query that is already compact may only lose a few bytes. The badge above the output shows the exact before and after size in bytes for your input. For API responses, JSON minification does the same job.

Can I minify GraphQL schemas as well as queries?

Yes. Anything graphql-js can parse works: queries, mutations, subscriptions, fragments, and schema files written in SDL with types, enums, inputs, directives and descriptions. Descriptions are kept, since they are part of the schema rather than comments; # comments are dropped.

Will Apollo, Relay or urql accept the minified query?

They should. The output is still standard GraphQL that parses to the same document, which is what any spec-compliant client or server reads. Keep in mind that a block string ("""…""") keeps its line breaks, so a document with one may span a few lines. If you need to read the query again later, you can format it back for development.

Is the GraphQL minifier free to use?

Yes, it's free and there's nothing to sign up for. Minifying happens in your browser, so your queries are not uploaded anywhere. Very large schema files work too, though the editor can take a moment to show them.