首页 > 解决方案 > 变异后 Apollo 客户端使用 cache.modify 差异更新缓存

问题描述

嗨,我只是想问一下下面这两个代码有什么区别我正在尝试在突变后更新评论缓存我尝试了下面的这两个代码片段,它都可以正常工作。我只需要知道区别。谢谢

  update(cache, { data }) {
    cache.modify({
      id: cache.identify(myPost),
      fields: {
        comments(existingCommentRefs, { readField }) {
          return existingCommentRefs.filter(
            commentRef => idToRemove !== readField('id', commentRef)
          );
        },
      },
    })
  }
 update(cache, { data }) {
          cache.modify({
            fields: {
              comments() {}
            }
          })
        }

标签: reactjsgraphqlapollo-clientreact-apolloapollo-server

解决方案


推荐阅读