Understanding Apollo Client

Apollo Client is a client-side GraphQL library that helps React applications execute operations and manage GraphQL data.

A GraphQL client is responsible for more than sending HTTP requests. Apollo Client can provide:

  • Query execution
  • Mutation execution
  • Request state management
  • Normalized caching
  • Cache updates
  • Optimistic UI
  • Polling
  • Refetching
  • Pagination helpers
  • Error handling

A useful mental model is:

React Component
      ↓
Apollo Client
      ↓
Cache ────────┐
      ↓       │
GraphQL Link │
      ↓       │
GraphQL API  │
      ↓       │
Response ────┘

Apollo Client can first satisfy a query from its cache depending on the configured fetch policy and then communicate with the server when required.

This is one of the major differences between using a raw fetch() call and using a full GraphQL client library.

Apollo Client Request Flow
Key Takeaways
  • Apollo Client is more than a GraphQL HTTP wrapper.

  • It can manage server data and a normalized client cache.

  • Fetch policies determine how cache and network are combined.

  • React components can subscribe to GraphQL query results.

Knowledge Check

Which capability distinguishes Apollo Client from simply using fetch() for GraphQL requests?