Skip to content
BENIBIX Learn

GraphQL

Development🔌 APIsAPI Architecture Styles

Also known as GraphQL API, Graph Query Language

A way to ask an API for just the fields you want, in one go.

Think of it like

Think of it like a buffet. You fill your plate with just the dishes you want, in one trip.

Example

Lucy's phone app needs a user's name and their last 3 orders. One GraphQL query fetches both, with no extra fields.

Why it matters

Apps on slow phone networks can fetch just what one screen needs in a single trip.

Definition

GraphQL is a query language that lets a client ask for exactly the fields it wants. All requests go to one address, and each one says the shape of the answer it expects. One request can gather data that a REST API would spread across several calls. The server publishes a schema that lists every type and field you can ask for. Facebook built it and released it to the public in 2015.

Example code

graphql
{
  user(id: 42) {
    name
    orders(last: 3) { total }
  }
}
Ask for a name and three order totals, and get exactly that back.

Common mistake

Letting clients ask for deeply nested data with no limits. One query can then ask for millions of rows.

Key takeaways

  1. 1
    Ask for exact fields. No more, no less.
  2. 2
    One address. Every query goes there.
  3. 3
    A schema lists it all. Every type and field.

Compare