GraphQL
GraphQL is a query language for APIs that lets a client request exactly the data it needs in a single call, instead of fetching fixed data structures from multiple REST endpoints. It was created by Facebook in 2012 and open-sourced in 2015, and is now used by companies like GitHub, Shopify and Twitter to serve mobile and web clients from one flexible API layer.
What is GraphQL?
GraphQL is both a query language and a runtime for executing those queries against a schema that describes an API's data and relationships. Unlike a typical REST API, where each endpoint returns a fixed shape of data, a GraphQL API exposes a single endpoint and lets the client describe the exact fields it wants, nested across related objects, in one request.
How a GraphQL query works
A client sends a query that mirrors the shape of the response it wants:
query {
user(id: "42") {
name
email
orders {
id
total
}
}
}
The server resolves each field through a function called a resolver, and returns a JSON response shaped exactly like the query, no more, no less. Writing data works the same way through a mutation, a named operation that changes state and returns the updated fields the client asked for.
Core building blocks
- Schema: the contract that defines every type, field and relationship available in the API.
- Query: a read operation that fetches data without changing anything on the server.
- Mutation: a write operation that creates, updates or deletes data.
- Subscription: a persistent connection that pushes updates to the client in real time.
- Resolver: the server-side function that fetches the actual value for one field of the schema.
GraphQL vs REST API
| Aspect | GraphQL | REST API |
|---|---|---|
| Endpoints | A single endpoint for all operations | Typically one endpoint per resource |
| Data fetching | Client selects the exact fields it needs | Server defines a fixed response shape per endpoint |
| Over/under-fetching | Avoided by design | Common, extra calls or unused fields |
| Versioning | Schema evolves, fields get deprecated in place | Usually versioned URLs (/v1, /v2) |
| Caching | Requires dedicated tooling | Simple with standard HTTP caching |
When to use GraphQL
GraphQL earns its complexity when a client needs nested, related data in one round trip, when several client types (web, iOS, Android) need different slices of the same data, or when bandwidth is limited and over-fetching is costly. It is usually overkill for a simple CRUD app with one client and a handful of flat resources, since a plain REST API or a backend-as-a-service like Supabase or Firebase gets there faster. The most common pitfall is the N+1 query problem, where a naive resolver setup triggers one database query per nested field; it is solved with batching tools such as DataLoader. Caching also needs dedicated tooling, since a single GraphQL endpoint cannot rely on simple HTTP caching the way distinct REST URLs can. A team adopting GraphQL should also budget time for schema design, since a poorly modelled schema is harder to fix later than a rushed REST endpoint, precisely because clients start depending on its exact shape from day one.
GraphQL at BeBranded
We reach for GraphQL when a web application serves several clients from the same data, a dashboard, a mobile app, a public API, and needs each of them to pull only what it uses without multiplying endpoints. It usually sits on top of a database such as Supabase or Firebase, which handles storage while GraphQL shapes how each client talks to it.