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.