GraphQL

GraphQL is a query language for APIs, described by a typed schema: the client writes the exact shape of the data it wants, and the response has that shape, nothing more. The contrast with REST is enough to grasp it. A REST API exposes resources, usually one address per resource, and returns what the server decided. You call `GET /users/42` to show a name and an email: you also get the bio, the phone, the address and the settings, 1.8 KB when two fields would do (that is over-fetching). Need their products too? A second request. With GraphQL you usually go through a single address and describe in one go the user, the two fields you want and their products. REST exposes resources, GraphQL lets the client describe the shape of the data. What the client gains, the server pays for. Every field is resolved by its own function, and a product list requested for each user falls straight into the N+1 problem unless someone batches the calls (the official documentation points to DataLoader for that). A query the client composes freely caches less well than a fixed address, and with no depth or complexity limit, a single nested query can get very expensive.

Official site

View on Coeurdar