Naively, { posts { author { name } } } runs 1 query for posts and N queries for authors — the N+1 problem. DataLoader batches all load(id) calls made in the same tick into one batchFn(ids) call and caches results for the rest of the request. Rules Create new loaders per request (in the context) — the cache must not leak between users. The batch function must return results in the same order as the keys, with null/Error for missing ones. Use one loader per access pattern (userById, postsByAuthorId). Other performance tools: query complexity/depth limits, persisted queries, and response caching with @cacheControl.
Key Takeaways
Nested resolvers easily cause N+1 queries.
DataLoader batches loads from the same tick into one query.
Create loaders per request so caches never leak between users.