With redux, when the state changes it updates any components props that is connect
ed to the store with mapStateToProps
. However with Apollo when performing a mutation, any component that is using the same data receive the new props.
I understand this is expected behaviour because Apollo doesn't know that the data sets are the same. Here's an example of what I'm getting at:
const query = gql`query { me { username } }`
@graphql(query)
class Header extends React.Component {
render () {
return <h1>{this.props.data.me.username}</h1>
}
}
const mutation = gql`mutation updateAccount($username: String!) {
updateAccount(username: $username) {
me {
username
}
}
}`
@graphql(mutation)
class Edit extends React.Component {
render () {
# ...
}
onSubmit(e) {
e.preventDefault()
this.props.mutate({variables: {username: this.state.username})
}
}
The Header
component renders out the username
, where as the Edit component updates the username
. I want to re-render Header
when username
changes. I'm not sure how to do this without polling the query.