Lesson 19 of 30
REST fixes what shape of data a URL returns; GraphQL lets the client ask for exactly the fields it needs — trading server-side simplicity for client-side precision, not a strict upgrade.
13 min read
Every option explains itself — why the right one is right, and why each wrong one is wrong. Miss one and it comes back later on a spaced-repetition schedule.
Question 1 of 2
A screen needs a user's name and their last 3 orders. With a REST API where /users/:id and /users/:id/orders are separate endpoints, how many requests does this typically need? How does GraphQL change that?
Hints without spoilers, and a plain explanation of why a wrong answer was wrong — answered only from this lesson. Free account, no card.
Sign up freeWhat interviewers actually ask about this, and what a strong answer has to cover.
A strong answer covers
Likely follow-ups
A REST endpoint returns a fixed shape: GET /users/42 gives you whatever fields that endpoint was built to return, whether your screen needs all of them or not. Need a user's name and their last 3 orders? That's often two separate requests (/users/42, /users/42/orders) — or a new custom endpoint someone has to build.
GraphQL exposes one endpoint and lets the client describe exactly what it needs, in one request:
query {
user(id: 42) {
name
orders(limit: 3) {
total
date
}
}
}
The server returns exactly (and only) the shape asked for — no unused fields sent over the wire, and no second request needed for related data that a REST endpoint didn't happen to include.
REST: GET /users/42 returns the WHOLE user object, whether you need all of it or not — over-fetching.
POST to the same single URL with a different body, which breaks the URL-based caching REST naturally gets — GraphQL clients (Apollo, Relay) implement their own object-level caching instead."When would you choose GraphQL over REST?" is a real architecture question with a real tradeoff-based answer — a strong response names over/under-fetching as the specific problem GraphQL solves, and the real costs (caching complexity, N+1 queries) it introduces in exchange.