【问题标题】:Why doesn't apollo store update?为什么阿波罗商店不更新?
【发布时间】:2018-05-06 16:11:31
【问题描述】:

我有以下问题

const ITEM_COMMENTS_QUERY = gql`
  query Search($id: UUID, $per_page: Int) {
    item(id: $id) {
      id
      comments(page: 1, per_page: $per_page) {
        edges {
          id
          author {
            id
            first_name
            last_name
          }
          content
        }
        total_count
      }
    }
  }
`;

以及以下突变

  const CREATE_COMMENT_MUTATION = gql`
  mutation create_comment($id: UUID!, $content: String!) {
    create_comment(id: $id, content: $content, type: COMMENT_TYPE_ITEM) {
      id
      ... on ItemComment {
        item {
          id
          comments(page: 1, per_page: 100) {
            edges {
              id
              author {
                id
                first_name
                last_name
              }
              content
            }
          }
        }
      }
    }
  }
`;

并且响应是正确的,但是 apollo 商店没有更新。 (我有dataIdFromObject:elm => elm.id

【问题讨论】:

    标签: reactjs redux graphql apollo react-apollo


    【解决方案1】:

    Apollo 客户端仅在更新突变时更新存储。因此,当您使用创建或删除突变时,您需要告诉 Apollo 客户端如何更新。我原以为商店会自动更新,但它没有......

    在更新/删除突变后,您需要使用 updaterefetch 命令 - see documentation 更新存储。这是update 示例example here

    【讨论】:

      猜你喜欢
      • 2019-05-02
      • 2019-08-31
      • 2017-03-03
      • 2018-01-13
      • 2019-12-06
      • 2013-02-02
      • 2021-12-28
      • 2017-10-15
      • 2021-08-20
      相关资源
      最近更新 更多