Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update the store after a mutation with relay?

Tags:

graphql

relay

I'm struggling to figure out how this should work. I have an application that has a current user, so, the topmost query looks like this:

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

AccountEdit_currentUser is defined this way:

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

on the AccountEdit component. That component commits this mutation:

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

After that happens, the server returns the correct values for email, name, nickName, etc. How should those new values end up in the store? Because it doesn't seem to automatic. Do I need to write a custom updater? and update config? I tried it a few times but I couldn't get anywhere close to something that even throws a reasonable error.

like image 717
Marta Silva Avatar asked Sep 06 '25 19:09

Marta Silva


1 Answers

This updating of the store happens automatically and the reason why it wasn't is because the node_ids of the current user in the original query and on the subsequent query were different. Once I made them the same, it started working.

like image 199
Marta Silva Avatar answered Sep 09 '25 22:09

Marta Silva