ConfigsApr 11, 2026·2 min read

Apollo Client — Industry-Leading GraphQL Client for TS/JS

Apollo Client is the industry-leading GraphQL client for TypeScript, JavaScript, React, Vue, Angular, and more. Powerful caching with normalized store, intuitive APIs, optimistic UI, subscriptions, and comprehensive developer tools.

TL;DR
Apollo Client manages remote and local state for GraphQL apps with a normalized cache, optimistic UI, and real-time subscriptions.
§01

What it is

Apollo Client is a comprehensive GraphQL client for TypeScript and JavaScript applications. It provides a normalized in-memory cache, declarative data fetching via hooks, optimistic UI updates, real-time subscriptions, and browser devtools for inspecting cache state.

Frontend developers building React, Vue, or Angular apps that consume GraphQL APIs use Apollo Client to handle data fetching, caching, and state management in one layer rather than juggling multiple libraries.

§02

How it saves time or tokens

Apollo Client's normalized cache eliminates redundant network requests. When a query fetches an entity by ID, subsequent queries referencing the same entity read from cache instead of hitting the server. This reduces both API call volume and latency.

Optimistic UI lets you update the interface before the server confirms a mutation, making the app feel instant. Combined with automatic cache updates, this replaces manual state synchronization code that would otherwise take hundreds of lines.

§03

How to use

  1. Install Apollo Client and GraphQL:
npm i @apollo/client graphql
  1. Create a client instance pointing to your GraphQL endpoint and wrap your app with ApolloProvider.
  1. Use the useQuery hook in any component to fetch data:
import { useQuery, gql } from '@apollo/client';

const GET_USERS = gql`
  query GetUsers {
    users { id name email }
  }
`;

function UserList() {
  const { loading, error, data } = useQuery(GET_USERS);
  if (loading) return <p>Loading...</p>;
  if (error) return <p>Error: {error.message}</p>;
  return (
    <ul>
      {data.users.map((u: any) => (
        <li key={u.id}>{u.name}</li>
      ))}
    </ul>
  );
}
§04

Example

Setting up an Apollo Client with InMemoryCache:

import { ApolloClient, InMemoryCache } from '@apollo/client';

const client = new ApolloClient({
  uri: 'https://api.example.com/graphql',
  cache: new InMemoryCache({
    typePolicies: {
      User: { keyFields: ['id'] },
    },
  }),
});

The typePolicies config tells the cache how to normalize entities by their unique key fields.

§05

Related on TokRepo

  • Coding Tools -- Developer tools for building and debugging web applications
  • Automation Tools -- Automate GraphQL schema generation and testing pipelines
§06

Common pitfalls

  • Cache normalization requires unique id or _id fields on every type. If your schema uses non-standard key fields, configure typePolicies.keyFields or queries will not merge correctly.
  • Over-fetching with deeply nested queries can bloat the cache. Use fragments and field policies to keep cache size manageable.
  • Subscriptions require a separate WebSocket link. Forgetting to configure split between HTTP and WS links is a frequent setup error.

Frequently Asked Questions

Does Apollo Client work with frameworks other than React?+

Yes. Apollo Client has official integrations for Vue (@vue/apollo-composable) and Angular (apollo-angular). The core client is framework-agnostic; the framework-specific packages provide hooks or services that wrap the core API.

What is the normalized cache and why does it matter?+

Apollo Client stores GraphQL responses as flat, deduplicated entities keyed by type and ID. When two queries return the same User, the cache holds one copy. Updates to that user propagate to every component reading it, eliminating stale data without manual refetching.

How do I handle authentication with Apollo Client?+

Use Apollo Link to add an authorization header to every request. Create an authLink that reads your token from localStorage or a cookie and sets the Authorization header, then chain it with the httpLink using concat or from.

Can Apollo Client manage local state?+

Yes. You can define client-side fields using the @client directive and resolve them with local resolvers or reactive variables. This lets you use Apollo as your single state management layer for both remote and local data.

How does Apollo Client compare to urql or Relay?+

Relay is optimized for large-scale apps with strict schema conventions and compiler-based optimizations. urql is lighter and more modular. Apollo Client sits between them with a rich feature set, large community, and flexible cache configuration.

Citations (3)

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets