cache.writequery只是,不添加到缓存

发布于 2025-02-05 00:25:53 字数 748 浏览 3 评论 0原文

我正在使用cache.writequery在突变后更新我的缓存,而它只是没有更新缓存。更新不在那里。

这是在我的update() usemuont 的回调中:

 const userData = copy(cache.readQuery({
     query: GET_USER
 }))

 userData.me.categories.push(newCategory)

 cache.writeQuery({
    query: GET_USER,
    data: userData
 })

 console.log('New category shows up here:')
 console.log(userData.me.categories.map(category => category.id))

 const _userData = copy(cache.readQuery({
    query: GET_USER,
 }))

 console.log('New category is not in here:')
 console.log(_userData.me.categories.map(category => category.id))

我正在深入关注我的用户数据,并只是将其推向其类别。它只是不想存储更新的数据。显然,在我可以突变我所有现有类别并更改其名称等的情况下,它在做 ,它不会添加新的类别。

接下来我可以尝试什么?

I'm using cache.writeQuery to update my cache after a mutation, and it just is not updating the cache. The updates just aren't in there.

This is in my update() callback from the useMutation:

 const userData = copy(cache.readQuery({
     query: GET_USER
 }))

 userData.me.categories.push(newCategory)

 cache.writeQuery({
    query: GET_USER,
    data: userData
 })

 console.log('New category shows up here:')
 console.log(userData.me.categories.map(category => category.id))

 const _userData = copy(cache.readQuery({
    query: GET_USER,
 }))

 console.log('New category is not in here:')
 console.log(_userData.me.categories.map(category => category.id))

I'm deep-cloning my user data, and simply pushing onto its categories. It just doesn't want to store the updated data. It's clearly doing something, insofar as I can mutate all my existing categories and change their names etc, it just will not add a new one.

What can I try next?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文