Apollo GraphQl反应.如何清除所有变量组合的查询缓存? [英] Apollo GraphQl react. How to clear query cache for all variable combinations?

查看:52
本文介绍了Apollo GraphQl反应.如何清除所有变量组合的查询缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的React应用程序中使用apollo graphql.说我有以下查询:

I am using apollo graphql in my react application. Say I have the following query:

query ListQuery($filter: String!) {
   items(filter: $filter) {
     id
     name
   }
}

此查询使我可以使用过滤器查询项目列表.假设我使用了过滤器字符串A,然后使用了过滤器字符串B.缓存现在将包含两个条目:ListQuery(A)和ListQuery(B).

This query lets me query a list of items using a filter. Say I used filter string A, and then used filter string B. The cache would now contain two entries: ListQuery(A) and ListQuery(B).

现在让我们说我使用一种变异来添加一个新物品.如何从缓存中删除所有缓存的查询?因此,在这种情况下,我想从缓存中同时删除ListQuery(A)和ListQuery(B).

Now let's say I use a mutation to add a new item. How can I remove all the cached queries from the cache? So in this case, I want to remove both ListQuery(A) and ListQuery(B) from the cache.

我该怎么做?

推荐答案

在您的情况下,您可以使用阿波罗的方法client.resetStore();

In your case, you can use the apollo's method client.resetStore();

它将清除先前的缓存,然后加载活动查询.

It will clear the previous cache and then load the active queries.

这篇关于Apollo GraphQl反应.如何清除所有变量组合的查询缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆