Apollo Client

Industry-leading GraphQL client with normalized caching for TypeScript and React

Library
npm
v4.3.1
19,803 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
95 /100 Excellent
Development Activity 100
Maintenance 96
Community 84
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
83 /100 Excellent
Architecture 90
Code Quality 90
Innovation 85
Learning Curve 68

Apollo Client is a comprehensive GraphQL client for TypeScript, JavaScript, React, Vue, Angular, and other frameworks, providing everything an application needs to fetch, cache, and update data from a GraphQL API. Its centerpiece is a normalized, in-memory cache that automatically keeps every query and mutation result consistent — updating any component observing affected data as soon as a mutation or subscription changes it, without manual cache-busting.

Beyond data fetching, Apollo Client bundles a link-based network layer (for batching, retries, auth, and error handling), optimistic UI helpers, local-state management, and official React hooks (useQuery, useMutation, useSubscription) that integrate cache state directly into component render cycles. It’s maintained by Apollo GraphQL and is one of the two dominant GraphQL client choices (alongside Relay) for production JavaScript applications.

What You Get

  • A normalized in-memory cache (InMemoryCache) that deduplicates and keeps entities consistent across every query/mutation
  • React hooks (useQuery, useMutation, useSubscription, useLazyQuery) with built-in loading/error state
  • A composable ApolloLink network layer for auth headers, batching, retries, and error handling
  • Optimistic UI updates and automatic cache updates after mutations
  • Local-state management for combining client-only state with remote GraphQL data in the same cache
  • Official bindings/adapters beyond React, plus first-class TypeScript types generated from your schema

Common Use Cases

  • Fetching and caching data from a GraphQL API in a React (or Vue/Angular) single-page application
  • Building optimistic UI flows where mutations update the interface instantly before server confirmation
  • Keeping multiple components in sync automatically when shared data changes via mutations or subscriptions
  • Combining local client-only state (UI flags, drafts) with server data through the same query/cache layer

Under The Hood

Architecture The client is organized around src/core/ (including QueryManager.ts at ~1,840 lines, the central orchestrator that tracks in-flight queries, deduplicates requests, and notifies observers of cache changes) and src/cache/inmemory/inMemoryCache.ts (~610 lines), which implements the normalized cache using object identity fields (id/__typename by default, or custom keyFields) to store every entity once regardless of how many queries touched it. src/link/ implements the Apollo Link architecture — a chain-of-responsibility pattern where each link (HTTP, retry, error, auth) can inspect or transform the operation before passing it to the next link, terminating in an HTTP link that performs the actual network request. src/react/ layers hooks and context providers on top of this core, subscribing components to cache changes so useQuery results update reactively, while src/local-state/ and src/masking/ implement client-only fields and fragment data masking respectively. Tech Stack TypeScript, published as @apollo/client (a scoped package superseding the legacy unscoped apollo-client), with graphql as a peer dependency and Zen Observable/RxJS-adjacent observables internally for the subscription/link pipeline; the monorepo uses a private root package with per-target build outputs (CJS, ESM) under dist/. Code Quality Test coverage is extensive with 136+ .test.ts files under src/, covering the cache, query manager, links, and React hooks individually, backed by CI (CircleCI badge in the README) and a documented issue triage/community process (Discourse community link). API Design The hook-based API (useQuery(GET_ITEMS)) is deliberately close to native GraphQL syntax and requires minimal boilerplate to get a query rendering with loading/error handling, though correctly configuring cache normalization (keyFields, type policies) for complex schemas is where the learning curve rises.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers