GraphQL Reference

This section documents the current GraphQL specification (October 2021), plus the working draft for @defer/@stream/@oneOf, and the GraphQL-over-HTTP specification, as published at graphql.org and spec.graphql.org — which are the references these pages are written and verified against — and, for the integration pages, against Spring for GraphQL (2.0.x), Strawberry, Ariadne, and the client docs for Apollo Client / urql / Relay. No specific patch version is pinned. Some surfaces (Apollo Router/managed federation, graphql-ws internals, the Relay compiler internals, GraalVM native) are linked rather than documented in depth.

This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production, as GraphQL tooling iterates quickly.

Welcome to the GraphQL reference. GraphQL is a query language and runtime for APIs, defined by an open specification: clients describe exactly the data they need in a single request, servers expose a strongly typed schema of the objects and operations that request can traverse, and a resolver function runs for each field to produce the response. This section documents the query language, the schema and type system, execution and resolvers, running and operating a server, integrating a Spring Boot or Python backend, and configuring the common client libraries, plus a downloadable cheat sheet.

If you are new to GraphQL, read Getting Started with GraphQL first, then Queries and Fields, Schema and Type System and Execution & Resolvers. Everything after that builds on those foundations.

For the REST, gRPC and ORM baselines this section is used alongside, see the sibling Hibernate Reference and SpringBoot Reference.

What’s covered

Getting started

  • Getting Started with GraphQL — what GraphQL is, the specification it follows, how it differs from REST, and running a first schema and query.

The query language

  • Queries and Fields — the query operation, selecting fields, aliases, nested selections, and arguments.

  • Variables, Directives & Fragments — parameterizing queries with variables, the built-in @include/@skip directives, and reusing selections with fragments.

  • Mutations — the mutation operation, input types, and sequential execution of top-level mutation fields.

  • Subscriptions — the subscription operation, event streams, and transports for pushing incremental updates to clients.

  • Introspection — querying a schema’s own type system through the schema and type meta-fields.

Designing the schema

  • Schema and Type System — the type system (scalars, objects, enums, lists, non-null), the schema definition language, and the root operation types.

  • Interfaces, Unions & Inputs — abstract types for polymorphic results and structured input types for arguments.

  • Directives — declaring and using custom schema and query directives, including the working-draft @defer/@stream and @oneOf directives.

  • GraphQL Schema Design — naming conventions, nullability choices, connection-style pagination, and evolving a schema without breaking clients.

Execution & operating a server

  • Execution & Resolvers — how a query is executed field by field, resolver functions, default resolvers, and resolver arguments.

  • Validation — validating a request document against the schema before execution begins.

  • Response and Error Handling — the response envelope, partial results, and the errors array and its extensions.

  • Serving GraphQL over HTTP — the GraphQL-over-HTTP conventions for request and response encoding, status codes, and content negotiation.

  • Pagination — offset and cursor-based pagination patterns and the connection model, and how it compares to keyset pagination in SQL and NoSQL stores.

  • Global Object Identification — the Node interface and globally unique object identifiers.

  • GraphQL Caching — caching strategies for a query language without cacheable URLs, from normalized client caches to persisted queries.

  • Performance & N+1 — the N+1 resolver problem and batching it away with the DataLoader pattern.

  • Security and Demand Control — query depth and complexity limits, rate limiting, and guarding against expensive or malicious queries.

  • Authorization — enforcing field- and object-level access control from within resolvers and directives.

  • Federation — composing multiple subgraphs into a single supergraph.

Choosing between GraphQL and REST

Spring Boot integration

Python integration

Configuring clients

Cheat sheet

  • GraphQL Cheat Sheet — a single-page, printable summary of everything in this section, with a downloadable PDF.

Bibliography

  • Specifications & official documentation (primary source for every page): the GraphQL learn site with its per-topic sub-pages (queries, mutations, subscriptions, schema, schema design, execution, validation, introspection, response, serving over HTTP, authorization, pagination, global object identification, caching, performance, security, federation, best practices); the October 2021 spec and the working draft; the GraphQL-over-HTTP spec; the Relay Cursor Connections spec; the GraphQL Foundation.

  • Framework & client documentation (primary source for the integration pages): Spring for GraphQL (controllers, request-execution, data, transports, security, testing, observability, federation, client) and Spring Boot’s GraphQL support; Strawberry (FastAPI, subscriptions, permissions, dataloaders, relay); Ariadne (FastAPI integration, ASGI); graphql-core; graphql-java; Apollo Client (networking, caching, pagination); urql; Relay; the Python gql client; GraphQL Code Generator; the DataLoader pattern.

  • Consulted reference books (bibliography only — not the primary or main source for any page): Porcello, Eve; Banks, Alex. Learning GraphQL: Declarative Data Fetching for Modern Web Apps. O’Reilly Media, 2018. ISBN 978-1-492-03071-3 — its code targets the 2018 JavaScript ecosystem (apollo-server 2.x, react-apollo, subscriptions-transport-ws) and does not cover Spring Boot, Python, the GraphQL-over-HTTP spec, @defer/@stream, @oneOf, trusted documents, graphql-ws, or modern federation, so where it and the official documentation disagree the official documentation is authoritative and the difference is noted; publisher page: https://www.oreilly.com/library/view/learning-graphql/9781492030706/. Buna, Samer. Learning GraphQL and Relay. Packt Publishing, 2016. ISBN 978-1-78646-575-7 — its code targets 2016-era graphql ~0.6 and Relay Classic, so only its language-agnostic material (query language, type system, the resolve function, object identification, the connection model) informs this section and its Relay-Classic chapters are treated as superseded background; no longer listed on Packt’s own site, so linking its retailer page instead: https://www.amazon.com/Learning-GraphQL-Relay-Samer-Buna/dp/1786465752.

  • Both books above are consulted bibliography references only. They are not the primary reference for any page, and where they and the official GraphQL specification and documentation disagree, the official specification and documentation are authoritative.