Apollo Cache - Partially read from cache?

588 Views Asked by At

I'm trying to achieve optimistic updates with apollo client.

I already have it working in different places in the app however I'm facing a wall here.

I'm running

store.writeQuery({query, variables, data});

within the update mutation callback and I tried to store.read it, it works fine. However, I can't manage to get this data from something else in the app.

The data I write to the cache is this:

{
                    playlist: {
                      __typename: 'Playlist',
                      elements: [{
                        __typename: 'Element',
                        id: 'test',
                        rating: 3,
                      }],
                    },
},

However, in the component where I want to use this cached data, my query is way more complex and I fetch way more fields. Not only that, but I also expect most of playlist.elements to be fetched from the network, only this specific one I expect to be coming from cache.

Is there to get only the element with the id: 'test updated, and the others updated from network normally ? Currently, I only get data from network and this cache written data doesn't seem to affect my query result.

Thank you :)

0

There are 0 best solutions below