Skip to main content
Web DevAPIs & NetworkingDiagramIntermediate

GraphQL

KO: GraphQL·EN: GraphQL·JA: GraphQL·Graph Query Language

A strongly typed API query language that lets clients request the exact data fields they need from a single endpoint, eliminating over- and under-fetching

Table of Contents

Structure Diagram

REST Multiple Endpoints vs GraphQL Single Query
RESTREST Multi-Request

Per-resource URLs · Fixed payloads

  • FetchingMultiple calls for nested relations
  • PayloadFixed shape can over-fetch fields
  • HTTP CachingNative URL-based CDN caching
GraphQLGraphQL Single Schema

Client-driven selection · Typed

  • FetchingFetch nested graph in 1 round-trip
  • PayloadReturns exact requested fields only
  • HTTP CachingRequires persisted queries / client cache
Quick Answer

What is GraphQL?

A strongly typed API query language that lets clients request the exact data fields they need from a single endpoint, eliminating over- and under-fetching. It is a core concept in APIs & Networking within Web Dev.

Core Principles

GraphQL is a strongly typed API query language and runtime originally created at Meta to eliminate multiple round-trips (under-fetching) and bloated JSON responses (over-fetching) on mobile networks.

The server exposes a typed schema describing entities and relationships, and clients send declarative queries specifying the exact fields they need—allowing web, iOS, and Android teams to evolve UI views independently without waiting for bespoke REST endpoints.

Practical Takeaways

  • Prevent N+1 queries with DataLoader: Nested resolvers can easily trigger dozens of redundant DB queries per request. Batch and cache lookups per request using DataLoader.
  • Harden against expensive queries: Enforce max query depth, query complexity budgets, and Persisted Queries in production to prevent Denial-of-Service via deeply nested graphs.
  • Observe GraphQL-level errors: Because GraphQL often returns HTTP 200 OK even when partial resolver errors occur, configure observability tools to inspect the response errors array rather than relying solely on HTTP status codes.

Notable Examples

  • GitHub API v4 & Shopify Storefront API: Allow integrators to pull complex relational graphs in a single request.
  • Federated BFF gateways (Apollo Federation): Unify dozens of underlying REST and gRPC microservices behind one discoverable product graph.