GraphQL Minifier - Compress GraphQL Queries Online
Free online GraphQL minifier to compress and optimize GraphQL queries by removing whitespace and comments for production use.
Loading GraphQL Minifier...
How to Minify GraphQL Queries - Step by Step Guide
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:
Example: Original GraphQL Query
Here's a GraphQL query with comments and whitespace:
# Get user details
query GetUser {
user(id: "123") {
name
email
}
}Automatic Minification
The tool automatically compresses your GraphQL by:
Example: Minified Output
The same query, now compressed to a single line:
query GetUser{user(id:"123"){name email}}Review Size Reduction
See exactly how much space you've saved:
Use in Production
Export and use your minified GraphQL:
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.
Related Tools
GraphQL Query Formatter
Format and beautify GraphQL queries and schemas with syntax highlighting
GraphQL Schema Validator
Validate GraphQL schemas with syntax and structure checking
GraphQL Fixer
Fix broken GraphQL queries and schemas automatically, repair syntax errors and malformed types
GraphQL to TypeScript
Generate TypeScript types from GraphQL schemas and queries
GraphQL to JSON Schema
Convert GraphQL schemas to JSON Schema format
GraphQL to JSON
Convert GraphQL schemas and queries to JSON format