Shopify
Shopify logoShopify · Feature trail

Apollo Client Cache Management

1 post · Nov 2022

What this trail covers

Shopify has evolved its understanding and utilization of the Apollo GraphQL client cache. This post details the internal workings of the InMemoryCache, including data fetching policies, normalization strategies (object breakdown, unique cache identifiers using `__typename` and `id` or custom `keyFields`, and flattening into a hash map), and the lifecycle of cached objects. It explains how the cache updates automatically when single entities or entire collections are edited and returned in mutation responses, and outlines scenarios where manual update functions or refetches are necessary for UI updates, such as when query responses are unrelated to cache changes, entire sets of changed objects cannot be returned, the order of response sets differs from the cached one, or items are added/removed from a list without returning the full list. The post also revisits an initial query example to illustrate a common cache misuse scenario related to missing fields.

All Shopify trails