GraphQL is a query language for APIs and a runtime that answers those queries against a typed schema. The client sends one request describing exactly the fields it wants, and the server returns exactly that shape — no more, no less.
GraphQL is a query language for APIs and a runtime that answers those queries against a typed schema. The client sends one request describing exactly the fields it wants, and the server returns exactly that shape — no more, no less.
/users, /users/1/posts); GraphQL exposes a single /graphql endpoint and you select data with the query body.# One request fetches a user AND their posts' titles — no second round trip
query {
user(id: "1") { # pick the user by id
name # only the fields we list come back
posts { # nested: follow the relationship in the same query
title
}
}
}
The response mirrors the query exactly: { "data": { "user": { "name": "...", "posts": [{ "title": "..." }] } } }.
Interviewers ask this to see if you understand the core trade-off: GraphQL removes over/under-fetching and gives clients flexibility, at the cost of more server-side complexity (resolvers, caching, query-cost control). Knowing why it exists — not just the syntax — signals you can pick the right tool.
A library of IT interview questions with detailed answers — from Junior to Senior.
Donate