GraphQL
GraphQL is a way for the client to describe exactly the data it wants in one request, and get back that shape and nothing else. Facebook built it in 2012 for its mobile apps. It comes up in interviews when several apps or screens need different slices of the same data, and the follow-up questions are always about what it costs the server.
A personal shopper
Instead of walking to the baker, the butcher and the greengrocer yourself, you hand a personal shopper one list: a sliced loaf, 500 g of mince, six eggs. The shopper visits each shop and brings back exactly what's on the list, nothing extra. You made one trip, but the shopper still visited three shops, and a careless one walks back to the butcher separately for every item.
- the list → the query: the fields you want, nested
- the shopper → the GraphQL server: one endpoint, usually
POST /graphql - each shop → a service or database that holds part of the answer
- each visit to a shop → a resolver call: a small function per field that fetches it
- what the shops sell → the schema: every type and field on offer, with its type
- walking back for every item → the N+1 problem, the thing interviewers probe