client.resetStore() doesn't reset the store
See original GitHub issueIntended outcome:
Props change when client.resetStore()
is called.
Actual outcome:
Props do not change on client.resetStore()
.
How to reproduce the issue: Checkout this minimally modified repo: https://github.com/dfee/react-apollo-error-template/tree/resetstore
Etc. Is this intended? I assumed that resetting the store (upon logout for instance) would immediately reset apollo data. Instead it seems that if the query returns a new result, then the update occurs.
It appears this function might be more aptly named: client.refetchQueries
.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:6
- Comments:18 (5 by maintainers)
Top Results From Across the Web
Reset store after logout with Apollo client - Stack Overflow
client.resetStore() doesn't actually reset the store. It refetches all active queries. Above statement is very correct.
Read more >clearStore() vs resetStore() - Help - Apollo GraphQL
If you just want the store to be cleared and don't want to refetch active queries, use client.clearStore() instead. It mentions resetStore() ......
Read more >Advanced Topics on Caching – Angular
If you want to clear the store but don't want to refetch active queries, use client.clearStore() instead of client.resetStore() .
Read more >Change or reset Internet Explorer settings - Microsoft Support
When Internet Explorer finishes applying default settings, select Close, and then select OK. Restart your PC to apply changes. If Internet Explorer won't...
Read more >[Solved]-Reset store after logout with Apollo client-Reactjs
client.resetStore() doesn't actually reset the store. It refetches all active queries. Above statement is very correct. I was also having the logout related ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think
client.resetStore
is most confusing when it comes to active queries that are contingent on authentication. When I callclient.resetStore
in my app after logout, what I want it to do is clear out all of my active queries’ data. Instead, I get a slew of 401 auth errors from my backend due to the majority of the active queries being session-based queries.This seems heavy-handed because I know the queries are no longer valid - I just want to empty them out.
So if
client.resetStore
isn’t the answer to this scenario, then what is the right approach to the following workflow?MyPurchasesQuery
)MyPurchasesQuery
data in this case?client.resetStore
will attempt to refetch theMyPurchasesQuery
but the desired behavior in this scenario isn’t to refetch the query, it’s to dump the query’s data.I guess I’m looking for something more along the lines of a “
client.emptyStore
”. Or maybe my general approach is wrong - any light you can shed on my plight would be greatly appreciated.Why is this closed? I don’t see how the issue is resolved. We require a way to reset the client state on log out, like many others contributing to this thread. If the issue is resolved, what is the current guidance for achieving this?