How can I resolve a reference?

Hey there,

I am extracting my apollo cache with the following function: this.apollo.client.extract();
`
It returns an object with all the apollo cache entries. Nested objects though only contain the __ref property.
Screenshot 2022-02-08 224905

Is there an easy way to resolve those references? Couldn’t find anything in the documentation or in other posts.

I think I could use readFragment or readQuery with the __ref value since that is the cache id of the object that I need. But I want to resolve all those references when I use extract without having to need to create a query or fragment for every single __typename.

Hello! The cache object you obtain from cache.extract() should contain those referenced objects as other top-level keys. Which is to say, any time you encounter a __ref, you can index into that same cache object to resolve it:

const cacheRepresentation = cache.extract();
const deviceCategory = cacheRepresentation["DeviceCategory:/api..."];

Is this helpful, or do you need to use references from your extracted object to read into the actual InMemoryCache?

Also keep in mind the following:

  • Sometimes dangling references exist in the cache if the referenced object has been evicted.
  • The resolved object might also contain unresolved references.
  • Circular references can and often do occur within the cache (because they often occur in GraphQL).