GraphQL: Schema, Queries and Resolvers Reference Guide
By DevShelfHub
Schema, types, queries, mutations, subscriptions, resolvers, pagination, federation — the API design surface.
91 items
◷ 7 min
Schema
Resolvers
Federation
Start hereQuick start · 6 you’ll reach for daily
Schematype Post { id: ID! }
Query{ posts { id title } }
Mutationmutation { create(input: …) }
Resolver(parent, args, ctx) => …
Batchnew DataLoader(…)
Codegengraphql-codegen --config …
spec & toolingVersions
Targets:graphql spec: October 2021@apollo/server ≥ 4graphql-js ≥ 16
Snippets use Apollo Server because it’s the most widely deployed Node implementation; concepts map
cleanly to graphql-yoga,
Strawberry, and
Hot Chocolate.
Subscriptions assume graphql-ws transport (the WebSocket
protocol that replaced subscriptions-transport-ws in 2021).
Wrap every mutation result in a payload type.createPost: Post! looks tidy but leaves you no place to put
user-facing validation errors. createPost: CreatePostPayload! with
post + errors ages well.
Use DataLoader per-request, not globally.
Build them in your context() function. Sharing across requests = a
cache-poisoning bug waiting to happen.
Generate types from your schema.graphql-codegen on the client (typed hooks) and on the server (typed
resolvers) eliminates an entire class of “works in dev, fails in prod” bugs.
Common trapsWatch out for
No query budget = DoS risk.posts(first: 999999) { author { posts { author … } } } can blow up
the server. Add depth + cost limits before exposing publicly.
Non-null fields propagate failure.
One error in a deeply nested non-null field bubbles up and nulls a much larger slice of the response.
Make “might fail” fields nullable.
Schema breaking changes are expensive.
Once clients ship, you can’t remove a non-null field or change a return type. Use
@deprecated, add new fields, retire later. Plug a schema registry into CI.
GraphQL is a query language and runtime for APIs that lets clients request exactly the data they need. Unlike REST, a single GraphQL endpoint handles queries for reading data, mutations for writing data, and subscriptions for real-time updates — all in one request.
What is the difference between GraphQL queries and mutations?
Queries fetch data and are read-only; mutations modify server-side data (create, update, delete). Both follow the same typed schema, but mutations carry the semantic meaning that something will change, which affects caching behavior and allows optimistic updates in clients.
What is a GraphQL resolver?
A resolver is a function that returns the value for one field in the schema. It receives the parent object, the field arguments, and a context object. Resolvers can call a database, another API, or a DataLoader to batch and deduplicate requests.
How does GraphQL federation work?
Federation lets you split a GraphQL schema across multiple independent services called subgraphs. Each subgraph owns a slice of the schema and a router (Apollo Router or graphql-mesh) merges them into a single supergraph. This enables team autonomy without a monolithic schema file.
Is GraphQL better than REST?
GraphQL and REST solve different problems. GraphQL excels when clients need flexible data shapes, when you want to reduce over-fetching, or when building a single API consumed by multiple front-end clients. REST is simpler, cacheable at the HTTP layer, and better documented by default.