reactive variables not working after calling resetStore()
See original GitHub issueIntended outcome:
I have a reactive variable:
export const isLoggedIn = makeVar(false);
Here is client initialization:
export const graphqlClient = new ApolloClient({
link: ApolloLink.from([authLink, logoutLink, httpLink]),
cache: new InMemoryCache({
typePolicies: {
Query: {
fields: {
user: {
read() {
return {
isLoggedIn: isLoggedIn(),
};
},
}
},
},
},
}),
});
And I have a query:
export const GET_IS_USER_LOGGED_IN = gql`
query GetIsUserLoggedIn {
user @client {
isLoggedIn
}
}
`;
I use this query in some place like this:
const { data: { user: { isLoggedIn } } } = useQuery(GET_IS_USER_LOGGED_IN);
Then I call graphqlClient.resetStore();
and after that I try to update reactive variable value like this isLoggedIn(true);
isLoggedIn
should become true
in this code:
const { data: { user: { isLoggedIn } } } = useQuery(GET_IS_USER_LOGGED_IN);
Actual outcome:
When you call graphqlClient.resetStore();
and after that you update reactive variable value like this:
isLoggedIn(true);
queries which use this reactive variable are not updated, for example this query still returns false
in isLoggedIn
property:
const { data: { user: { isLoggedIn } } } = useQuery(GET_IS_USER_LOGGED_IN);
But if I never use graphqlClient.resetStore();
and try to update reactive variable value like this isLoggedIn(true);
all works great.
How to reproduce the issue: Here is sandbox
First click click to reset store button and after that click click to change reactive variable value button. You will see that value is still false.
But if you just click click to change reactive variable value button, value will be changed to true
.
Versions System: OS: macOS Mojave 10.14.6 Binaries: Node: 15.4.0 - ~/.nvm/versions/node/v15.4.0/bin/node Yarn: 1.22.10 - /usr/local/bin/yarn npm: 7.0.15 - ~/.nvm/versions/node/v15.4.0/bin/npm Browsers: Chrome: 88.0.4324.150 Edge: 88.0.705.63 Firefox: 84.0.1 Safari: 13.0.5 npmPackages: @apollo/client: ^3.3.8 => 3.3.8
Issue Analytics
- State:
- Created 3 years ago
- Reactions:7
- Comments:11 (3 by maintainers)
Top GitHub Comments
@jcreighton yeah you are right. In the sandbox after updating to 3.3.8 it works. But in my project I use 3.3.8 and still have this issue. I will try to figure out why behavior in my project differs from behavior in the sandbox and will write again. Thanks.
@vladimir-drachuk We have a company-wide deadline today (peer reviews are due), but @jcreighton is actively working on fixing this.