Format and beautify GraphQL queries and schema definitions — produce properly indented, readable GraphQL with consistent spacing and structure.
Enter your figures and click Calculate to see your results.
Paste your GraphQL query or schema, select the type (query/schema), choose indent size and click Format.
Click the Format button. Your code is processed instantly — all formatting runs in your browser with no data sent to servers.
The formatted output appears on the right. Click Copy to grab it, or Download to save as a file. Statistics like size reduction and line count are shown automatically.
GraphQL is a query language for APIs where clients specify exactly what data they need. Unlike REST (which has fixed endpoints returning fixed shapes), a GraphQL API has a single endpoint and clients send queries describing the shape of data they want. This eliminates over-fetching (getting unused fields) and under-fetching (needing multiple requests). GraphQL was created by Facebook in 2012 and open-sourced in 2015.
Queries (read data — equivalent to GET), Mutations (write/modify data — equivalent to POST/PUT/DELETE), and Subscriptions (real-time data — the server pushes updates to the client via WebSocket). Every GraphQL API must implement queries; mutations and subscriptions are optional. Operations can be named (query GetUser($id: ID!) { ... }) for debugging clarity.
A GraphQL schema defines the types, queries, mutations and subscriptions available in the API. Written in Schema Definition Language (SDL): type User { id: ID!, name: String!, email: String! }. Exclamation marks (!) indicate non-nullable fields. The schema is the contract between client and server — it is self-documenting and enables tools like GraphiQL and Apollo Studio to provide auto-complete and documentation automatically.
Fragments are reusable pieces of a query: fragment UserFields on User { id name email createdAt }. Used in queries with spread syntax: query { user(id: "1") { ...UserFields posts { ...PostFields } } }. Fragments avoid repetition in complex queries. Named fragments also appear as separate operations in query analysis, making performance monitoring easier. Inline fragments (...on SomeType { field }) are used for interface and union type selection.
The N+1 problem occurs when resolving a list of N items each triggers an additional database query. For example: fetching 10 users, then for each user fetching their posts, results in 1 + 10 = 11 queries. The DataLoader pattern (batching + caching) solves this by collecting all user IDs then making one batched query: SELECT * FROM posts WHERE user_id IN (1,2,3,...10). DataLoader is the standard solution and is included in most GraphQL server frameworks.
GraphQL APIs support introspection — querying the schema itself. The __schema and __type meta-fields allow clients to discover available types, fields, queries and mutations. This enables powerful tooling: GraphiQL (browser IDE with auto-complete), Apollo Studio, Postman, and code generators all use introspection to explore APIs and generate typed client code. Introspection can be disabled in production for security (to hide API structure from attackers).
Directives add conditional logic to queries. Built-in directives: @include(if: Boolean) — include field only if condition is true; @skip(if: Boolean) — skip field if condition is true; @deprecated(reason: String) — marks a field as deprecated in the schema. Custom directives can implement authorization (@auth), rate limiting (@rateLimit), caching (@cacheControl) and input transformation (@trim, @uppercase) directly in the schema.
Apollo is the most popular GraphQL platform: Apollo Client (React, Vue, Angular — state management + GraphQL queries), Apollo Server (Node.js GraphQL server), Apollo Studio (cloud platform for schema management, performance monitoring and collaborative development), and Apollo Federation (composing multiple GraphQL services into a supergraph). Apollo is optional — GraphQL has many alternative clients (urql, URQL, Relay) and servers (GraphQL Yoga, Pothos, Nexus).