Will my combined graphql queries in apollo-client cache correctly? And if not, how can I make it possible?

Viewed 41

My page requests json files from my backend. Often more than 10 files are queried at the same moment. My current setup uses a query that looks like this:

query
{
  someFiles(ids: [ 'id1', 'id2', 'id3', '...' ]
  {
    data
  }
}

My page would greatly benefit from caching these requests. However, I'm not sure if the resulting files will be cached correctly if I request new data with e.g. a different order of ID's. How can I request multiple files at once and still benefit from client side caching of each seperate file/id combination?

1 Answers

When reading/writing to Apollo Client cache you can use GraphQL fragments to use a more "random access" to your cached data than readQuery/writeQuery, the Apollo doc on Reading and writing data to the cache has more info on readFragment/writeFragment.

Related