← Lessons

quiz vs the machine

Gold1480

Networking

The GraphQL Over HTTP

Client shaped queries against one endpoint and schema.

5 min read · core · beat Gold to climb

One Endpoint, Many Shapes

GraphQL is a query language for APIs. Instead of many fixed endpoints, the client sends a query to a single endpoint and asks for exactly the fields it wants.

How It Works

The server publishes a typed schema, and clients query against it.

  • A schema defines types and the fields each type exposes.
  • A query asks for a specific tree of fields.
  • The server returns JSON shaped exactly like the query.
  • A mutation is the same idea for writes.

Strengths And Pitfalls

The shape it wants approach solves real problems.

  • Clients avoid over fetching unneeded fields.
  • Clients avoid under fetching that forces extra round trips.
  • A single request can gather data from many sources.

The risks are on the server. A deeply nested query can be expensive, so servers add depth and cost limits. The classic backend trap is the N plus one problem, where one field triggers many database calls, usually solved with batching loaders. GraphQL trades a simple endpoint for a powerful but heavier query engine.

Key idea

GraphQL lets clients query a single typed endpoint for exactly the fields they need, ending over and under fetching, but shifts cost to the server which must guard against expensive nested queries and N plus one fetches.

Check yourself

Answer to earn rating on the learn ladder.

1. What problem does GraphQL field selection solve?

2. What is the N plus one problem in GraphQL?

3. How many endpoints does a typical GraphQL API expose?