简体   繁体   English

我在 apollo-client 缓存中的组合 graphql 查询是否正确? 如果没有,我怎样才能使它成为可能?

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

My page requests json files from my backend.我的页面从我的后端请求 json 文件。 Often more than 10 files are queried at the same moment.通常同时查询超过 10 个文件。 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 eg a different order of ID's.但是,如果我请求具有不同 ID 顺序的新数据,我不确定生成的文件是否会被正确缓存。 How can I request multiple files at once and still benefit from client side caching of each seperate file/id combination?如何一次请求多个文件,并且仍然受益于每个单独的文件/ID 组合的客户端缓存?

当读取/写入 Apollo 客户端缓存时,您可以使用 GraphQL 片段对缓存数据使用比readQuery / writeQuery更“随机访问”,Apollo 文档读取和写入数据到缓存有更多关于readFragment / writeFragment的信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM