One Endpoint, Fetching Only the Fields You Want Across Resources

A REST API exposes many endpoints, each returning a fixed shape. To get an order's line items together with the customer's name, the client may need two separate requests, or may use an endpoint that always returns fields that screen doesn't need.

GraphQL exposes a single endpoint. In one request, the client sends a query that names exactly the fields it wants, across related resources. This avoids the extra round trips and the unused fields.

But GraphQL doesn't eliminate N+1 automatically. For example, a query asking for 10 orders and each order's customer name can make the server do 11 fetches in total: one for the order list, plus one per order for its customer. That's what happens unless the server is built to fetch the customers together. The client's ability to choose fields is a separate matter from how the server actually fetches the data.

GOAL

Explain how GraphQL lets a client specify exactly which fields it wants, and why N+1 can still happen even though GraphQL was partly designed to avoid overfetching.

A GraphQL query asks for 10 orders and each order's customer name, resolved naively without batching. How many underlying lookups does the server end up making?