Shaf Lab

GraphQL

A query language for APIs that lets clients ask for exactly the fields they need.

GraphQL is a query language for APIs that lets a client ask for exactly the fields it needs, rather than taking a fixed REST payload. The server publishes a schema of types and fields, and the client sends a query that walks that graph. It can reduce over-fetching, and it can also hide a lot of work behind a single request.

The usual pitfalls are unbounded nested queries, N-plus-one data fetches, and a schema that mirrors the database too closely. Put a cost or depth limit on queries, batch or cache the resolvers, and design types around the product, not around tables. Mutations should be explicit and idempotent where you can make them so.

Versioning is different from REST. You add fields more often than you remove them, and you deprecate slowly. A breaking change in a shared schema will surprise every client at once, including ones you forgot.

Choose GraphQL when many clients need different slices of the same graph. If you have one client and a handful of endpoints, a plain HTTP API is often clearer and easier to cache.