Understanding the N+1 Query Problem

The N+1 problem occurs when resolving a list of parent objects causes one additional database query for every parent. For example, loading 100 posts and then querying the author separately for every post can result in 1 query for posts plus 100 author queries.

GraphQL makes this problem easy to introduce because nested fields are resolved independently. The API may look elegant to the client while the server performs hundreds or thousands of database operations.

A production GraphQL implementation must therefore treat resolver design and data access as closely related concerns.