gpt4 book ai didi

javascript - Apollo 客户端 : Keep/Reset defaults on clearing or resetting store

转载 作者:行者123 更新时间:2023-12-03 00:44:32 27 4
gpt4 key购买 nike

我使用 apollo-link-state 来本地存储错误,但清除缓存后出现以下错误。

我已在 apollo 客户端配置选项中将 errors 的默认值设置为空数组 []

但是,在 apolloClient.cache.reset()apolloClient.store.reset() 之后,似乎我丢失了所有默认值,导致此错误:

Error

有什么想法可以解决这个问题吗?

最佳答案

来自docs :

Sometimes you may need to reset the store in your application, for example when a user logs out. If you call client.resetStore anywhere in your application, you will need to write your defaults to the store again. apollo-link-state exposes a writeDefaults function for you. To register your callback to Apollo Client, call client.onResetStore and pass in writeDefaults.

所以你可以这样做:

const cache = new InMemoryCache()
const link = withClientState({ cache, resolvers, defaults })

const client = new ApolloClient({
cache,
link,
})

client.onResetStore(stateLink.writeDefaults)

关于javascript - Apollo 客户端 : Keep/Reset defaults on clearing or resetting store,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53304560/

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