question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

client.resetStore() doesn't reset the store

See original GitHub issue

Intended 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:closed
  • Created 6 years ago
  • Reactions:6
  • Comments:18 (5 by maintainers)

github_iconTop GitHub Comments

75reactions
richardgirgescommented, Apr 6, 2017

I think client.resetStore is most confusing when it comes to active queries that are contingent on authentication. When I call client.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?

  1. User goes to app/website
  2. User logs in
  3. User views “My Purchases” page (triggers MyPurchasesQuery)
  4. User logs out
  5. How do we clear out the MyPurchasesQuery data in this case? client.resetStore will attempt to refetch the MyPurchasesQuery 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.

27reactions
danderson00commented, Dec 5, 2017

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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found