gpt4 book ai didi

graphql - 在 apollo-client 的 useQuery 中使用 fetchPolicy ='cache-and-network' 不在 fetch 上更新缓存更多

转载 作者:行者123 更新时间:2023-12-04 04:11:04 35 4
gpt4 key购买 nike

我正在为我的 graphql 设置使用 apollo-client。我有一个分页调用,为此我使用了 useQuery Hook 返回的 fetchMore 函数。在 fetchMore 函数中,我使用它的 updateQuery 参数将新获取的数据附加到缓存中的结果。

fetchMore({
variables: {
request: fetchMorerequest,
},
updateQuery: (previousResult, { fetchMoreResult }) => {
const updatedResults = update(previousResult, {
list: {
data: { $push: fetchMoreResult.list.data },
hasMore: { $set: fetchMoreResult.list.hasMore },
},
});

return updatedResults;
},
});

这对我来说很好。

现在,我已将我的 fetchPolicy 从默认的 cache-first 更改为 cache-and-network。更改之后,我从 updateQuery 函数返回的 updatedResults 反射(reflect)在我的缓存中,但没有返回到我的组件中。我可以在 chrome 的 apollo 扩展中看到缓存中的更新项目。但没有将它们放入我的组件中。

知道这里有什么问题吗?我错过了什么吗?请帮忙。

最佳答案

在您的 defaultOptions 或当前查询选项中设置 nextFetchPolicy: 'cache-first'

read more here

关于graphql - 在 apollo-client 的 useQuery 中使用 fetchPolicy ='cache-and-network' 不在 fetch 上更新缓存更多,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61727680/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com