【问题标题】:How to update the store after a mutation with relay?中继突变后如何更新商店?
【发布时间】:2020-07-06 21:20:36
【问题描述】:

我正在努力弄清楚这应该如何工作。我有一个具有当前用户的应用程序,因此,最上面的查询如下所示:

  query AppQuery {
    currentUser {
      id
      email
      ...Account_currentUser
      ...AccountEdit_currentUser
    }
  }

AccountEdit_currentUser 是这样定义的:

export default createFragmentContainer(AccountEdit, {
  currentUser: graphql`
    fragment AccountEdit_currentUser on User {
      email
      name
      nickName
    }`
})

AccountEdit 组件上。该组件提交了这个突变:

  mutation AccountEditMutation($email: String!, $name: String!, $nickName: String!) {
    updateAccount(input: {email: $email, name: $name, nickName: $nickName}) {
      accountUpdated
      currentUser {
        id
        email
        name
        nickName
      }
    }
  }

之后,服务器会返回正确的电子邮件、姓名、昵称等值。这些新值应该如何在存储中结束?因为它似乎不是自动的。我需要编写自定义更新程序吗?并更新配置?我尝试了几次,但我无法接近甚至引发合理错误的东西。

【问题讨论】:

    标签: graphql relay


    【解决方案1】:

    商店的这种更新是自动发生的,之所以没有更新,是因为当前用户在原始查询和后续查询中的 node_ids 不同。一旦我使它们相同,它就开始工作了。

    【讨论】:

      猜你喜欢
      • 2019-05-02
      • 2018-04-14
      • 2016-02-06
      • 1970-01-01
      • 1970-01-01
      • 2018-06-29
      • 1970-01-01
      • 1970-01-01
      • 2018-12-24
      相关资源
      最近更新 更多