You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
However, this only works if your detail will fetch the record by the id (or the same field as the cacheKey), but you might encounter situations where the detail won't be fetched by the id (e.g. fetching by a slug or path, or similar)
its not possible to use cache directs (the read function) in this situation.
in the discussion above i mention a workaround, but it involves internal api as well as a O(n) lookup (basically iterating through all cache objects).
So we should have:
a way to define alternate keyFields, for example keyAliasesFields (or any better name), that work similarly to keyFields, but there can be multiple of them.
in the read function in the policies we should be able to lookup cache entries by these additional fields (in an eficient way)
Additional context
Apollo client could also warn about these situations, e.g. whenever it does a network request, but the result is already fully in the cache. In these cases you can use cache redirects
The text was updated successfully, but these errors were encountered:
Problem
When fetching a list and than the detail, you might be able to use cache redirects: https://www.apollographql.com/docs/react/caching/advanced-topics/#cache-redirects-using-field-policy-read-functions
However, this only works if your detail will fetch the record by the id (or the same field as the cacheKey), but you might encounter situations where the detail won't be fetched by the id (e.g. fetching by a slug or path, or similar)
its not possible to use cache directs (the
read
function) in this situation.See also this disscussion :https://github.com/apollographql/apollo-client/discussions/7574
Possible Solution
in the discussion above i mention a workaround, but it involves internal api as well as a O(n) lookup (basically iterating through all cache objects).
So we should have:
keyAliasesFields
(or any better name), that work similarly tokeyFields
, but there can be multiple of them.read
function in the policies we should be able to lookup cache entries by these additional fields (in an eficient way)Additional context
Apollo client could also warn about these situations, e.g. whenever it does a network request, but the result is already fully in the cache. In these cases you can use cache redirects
The text was updated successfully, but these errors were encountered: