Back to roadmap
Module 5 · APIs & Application LayerDay 04025 min

GraphQL — Strengths and Pitfalls

Ask for exactly what you need — and own the cost.

Day 040

GraphQL — Strengths and Pitfalls

Client
client
GraphQL
service
Users
datastore
Orders
datastore
Signal path
GraphQL request shape
Client
client
flow
GraphQL
service
GraphQL
service
flow
Users
datastore
GraphQL
service
flow
Orders
datastore
Memory hook

GraphQL — Strengths and Pitfalls: ask for exactly what you need

Mental model

turn boundaries into contracts

Design lens

Client gets exactly what it needs.

Recall anchors
WinsCostsTools

Why it matters

GraphQL exposes a typed schema and lets clients fetch exactly the fields they want in one request. It excels at graph-shaped data but shifts complexity to the server.

Deep dive

Resolvers fetch fields; naïve resolvers cause N+1 (one DB call per node). Dataloader batches.

Persisted queries: client sends an ID, server has the canonical query — cacheable, audited, safer.

Cost limiting (depth, complexity scoring) is required to prevent expensive queries.

Demo / scenario

Mobile screen needs user, their last 10 orders, and items per order.

  1. REST: 1 + 1 + 10 round trips.
  2. GraphQL: one query returns it all.
  3. Server uses dataloader to batch order item fetches.
  4. Persist query → enable CDN caching by query ID.

Tradeoffs

  • Client gets exactly what it needs.
  • Server complexity grows; logging/auth/cost limiting needed.
  • Caching is harder than REST (no obvious URL).

Diagram

Client
GraphQL
Users
Orders
GraphQL request shape.

Mind map

Check yourself

Loading quiz…

Sources & further reading