GraphQL in production · mid
Authorization and caching in GraphQL
REST gives you one check per route and a cache per URL. GraphQL has one endpoint and many paths to the same object, so you check access on each field or object and you rebuild caching with persisted queries and cache hints.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- Checking only at the entry point is the common bug. A user can reach another user's phone or saved cards through restaurant { reviews { author { phone } } }. Check access on the type or field, in one authorization layer that every resolver calls.
- Object-level authorization: a mutation such as cancelOrder must check that the order belongs to the caller. Otherwise any logged-in user can cancel any order by id (broken object-level authorization).
- Return the same answer for not found and not yours so ids cannot be probed. Do not let a TypeError message from a null object reach the client.
- GraphQL over HTTP is usually POST, and a POST response is not cached by HTTP caches. A query can use GET with the query in the URL, but long documents hit URL size limits.
- Persisted queries: the client sends an id or hash instead of the document. With GET and a short id, a CDN can cache by URL, and the server can refuse unknown queries.
- Cache hints: the server builds Cache-Control from per-field hints. The shortest max-age wins, and a single private field makes the whole response private.
- Split screens: a public query (restaurants for a city) cached at the CDN for a short time, and a separate personal query that is never shared.
The red pen
Common traps: mistake → fix
Mistake: I check the user at the top of the query, so everything below is safe
Fix: Nested paths reach the same objects. Check at the field or type.
Mistake: GraphQL cannot use a CDN
Fix: With persisted queries over GET and cache hints it can, for public data.
Mistake: A scope or role check is enough for a mutation
Fix: It must also check that this object belongs to this user.
Easy to hard
Questions interviewers ask, easy to hard
- Where should authorization checks live in a GraphQL server and why?
- Why is cancelOrder(id) dangerous without an ownership check?
- Why are GraphQL POST requests not cached, and what are the options?
- One field in a response is private and the rest is public. What Cache-Control does the response get?
- Review a set of resolvers and list every authorization and error-handling problem.
Practise
Practise with these questions
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.