GraphQL Reference
|
This section documents the current GraphQL specification (October 2021), plus the working draft for
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/@skipdirectives, 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
schemaandtypemeta-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/@streamand@oneOfdirectives. -
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
errorsarray 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
Nodeinterface 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
-
Tips: When to Use GraphQL or a Typical REST API — a decision-oriented comparison of GraphQL and a typical REST API, including query-plan cost and index coverage, and when to deploy each.
Spring Boot integration
-
Spring Boot: Getting Started with GraphQL — adding Spring for GraphQL to a Spring Boot application and serving a first schema.
-
Spring Boot: Annotated Controllers — mapping queries, mutations, and subscriptions to
@Controllerhandler methods. -
Spring Boot: Data Loading & Integration — batch loading with
BatchLoaderRegistry, and integrating a data layer behind resolvers. -
Spring for GraphQL: Transports, Security, and Testing — HTTP, WebSocket and RSocket transports, securing endpoints, and testing with
GraphQlTester.
Python integration
-
Python: Getting Started — the Python GraphQL ecosystem and choosing between the Strawberry and Ariadne approaches.
-
Strawberry with FastAPI — mounting a Strawberry schema onto a FastAPI application.
-
Strawberry — Schema and Features — defining a schema with Strawberry’s type annotations, and its subscriptions, permissions, and dataloader support.
-
Ariadne: Schema-First GraphQL — the schema-first approach with Ariadne and its ASGI/FastAPI integration.
Configuring clients
-
GraphQL Clients: Choosing an Approach — what a GraphQL client adds over a plain HTTP request, and choosing among the major client libraries.
-
Apollo Client Configuration — configuring Apollo Client’s networking, normalized cache, and pagination helpers.
-
Other GraphQL Clients: urql, Relay, JVM, and Python — urql, Relay, JVM clients such as graphql-java, and the Python
gqlclient.
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
gqlclient; 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-server2.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-eragraphql~0.6 and Relay Classic, so only its language-agnostic material (query language, type system, theresolvefunction, 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.