-
Notifications
You must be signed in to change notification settings - Fork 786
Calling writeQuery does not update the props #2209
Comments
I got around this for the time being by calling refetch on the query. It's not ideal, but it does the trick |
@scottmcpherson I've been struggling with the same issue. I have a query <Mutation
mutation={LOGIN}
variables={{ email, password }}
update={(cache, { data }) => {
cache.writeQuery({
query: GET_USER,
data: { user: data.login }
});
}}
>
// ... form here are the queries that correspond: import gql from 'graphql-tag';
export const GET_USER = gql`
{
user {
id
name
email
__typename
}
}
`;
export const LOGIN = gql`
mutation LoginMutation($email: String!, $password: String!) {
login(email: $email, password: $password) {
id
name
email
__typename
}
}
`; However, when I log in successfully, that update does not update the query (as far as I can tell, assuming that the header should switch over to the logged out state as it's referencing the same query). The data that I have coming back after login in I'm going to try to refetch from the server for now too but this feels redundant as you said... |
This thread is about refetching the user after log in, but fundamentally that feels like a redundant call. |
possibly duplicate of #2099 |
#2099 is a I'm leaving this open because it is another permutation of what I think is the same upstream bug. |
I proved the bug upstream is not a bug, so back to looking at other cases to find it. |
@scottmcpherson I don't think this has anything to do with
Since this is an error, the query isn't cached and is not observable. So then when you call |
The only thing you have to do to get it working is:
|
Thanks for digging in @danilobuerger. I'm closing given that solution/information. |
Intended outcome:
writeQuery
should refresh the props data. You can see here that when a user logs in, this function gets called with the user. I'm trying to callwriteQuery()
to update the currentUser.I've also tried calling
writeQuery
directly on theclient
andstore
, but no luck.Actual outcome:
writeQuery
does not refresh the props dataHow to reproduce the issue:
You can clone this repo to see the issue: https://github.com/scottmcpherson/react-graphql-apollo-semanticui-starter and checking out commit
3be17f74071dc347164d1ac825c8503bc075ee8b
Version
"apollo-boost": "0.1.10",
"react-apollo": "2.1.9",
The text was updated successfully, but these errors were encountered: