GraphQL in Production · GraphQL Fundamentals for API Designers
How GraphQL Works
Schemas, operations, resolvers and the GraphQL-over-HTTP conventions.
GraphQL is a query language and runtime: the server publishes a strongly typed schema; clients send operations (queries, mutations, subscriptions) selecting exactly the fields they need; the server validates the operation against the schema and executes resolvers field by field. Everything usually goes through one endpoint (/graphql). The GraphQL over HTTP specification standardizes transport: GET for queries (cacheable), POST for any operation, and the application/graphql-response+json media type with meaningful HTTP status codes.
REST vs GraphQL at a glance
| Criterion | REST | GraphQL |
|---|---|---|
| Endpoints | Many resource URLs | Usually one /graphql |
| Response shape | Server-defined | Client-selected fields |
| Over/under-fetching | Common; mitigated with fields/expand | Minimal by design |
| HTTP caching | Natural (GET URLs) | Needs persisted GET queries |
| Typing / introspection | Via OpenAPI | Built-in schema + introspection |
| Error model | HTTP status + problem JSON | errors[] array, partial data |
| Server complexity | Lower | Higher (resolvers, cost limits, N+1) |
# Operation sent by a client
query OrderPage($id: ID!) {
order(id: $id) {
id
status
total { amount currency }
items { quantity product { name imageUrl } }
}
}
# Response
# { "data": { "order": { "id": "ord_1", "status": "PAID", ... } } }
Common pitfalls
- Treating GraphQL as a thin layer over database tables.
- Ignoring HTTP semantics entirely (everything POST, always 200).
- Exposing an untested, unlimited schema publicly.
Key points
- Typed schema + client-selected fields
- Resolvers execute per field
- Follow the GraphQL-over-HTTP spec
Further reading: GraphQL over HTTP specification
Practice questions
Why can GraphQL responses be harder to cache with HTTP caches?
Answer
Operations are often sent via POST to a single URL, so caches can't key on the URL; persisted queries sent via GET restore cacheability.
What does a resolver do?
Answer
It returns the value for one field of one type, given its parent object, arguments and request context; the executor calls resolvers for every selected field.
Open in the app to mark lessons complete, take notes and track your progress.