-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
client.resetStore() doesn't reset the store #1552
Comments
I don't think it makes sense to call this |
I think This seems heavy-handed because I know the queries are no longer valid - I just want to empty them out. So if
I guess I'm looking for something more along the lines of a " |
The reason I filed this ticket, the spirit of the ticket per se, is what @richardgirges has described. |
@Poincare this is what the docs say:
I am relatively new to the world of front-end, so I see everything on the front-end as a cache. When I see, "there is no data left in your store from a time before you called this method", I interpret that to mean "all Apollo data will be wiped". Am I correct in assuming this really means:
Thanks! |
I think the problem here is confusion due to bad naming, and possibly bad docs. It might be worth while to change the name of |
These concerns are pretty reasonable. I'm not sure if we have a good solution at the moment to clear out auth'ed data from your cache. As I mentioned, just throwing away everything in the cache isn't a reasonable solution since all active queries (i.e. those with Observables associated with them) would break. I do think the docs don't do a great job of explaining this, especially with the second sentence. If any of you could submit a PR to fix that, that would be awesome. I don't agree with renaming |
@Poincare well, technically you shouldn't need to clear the store if you re-fetch all queries... unless you aren't cleaning up references. Data shouldn't remain in the store if it is no longer referenced by a query / mutation entry... it should be removed so that the GC can clear up memory... and there is just no reason to leave it there since it is no longer accessible anyway. If the query references are re-built, it seems like it solves the problem of purging the cache of old now-inaccessible data, does it not? |
I agree that apollographql/react-apollo#531 was recently merged for the purpose of trying to deal with Me like others only considered I'll look into manually removing the redux-state populated by apollo-client and remove the entire client on logout and create a new client on login, optionally just skip it all and revert to refreshing the page as a last resort. Maybe the equivalent of that should be added as |
Ok, it seems like the issue has been solved, so I'll close this. I agree with @jacobk that we could probably use a |
Is there any best practice on resetStore() on logout since then? I also had the idea that resetStore() would reset my store and not refetch queries again like I'm seeing today. |
Are there any updates on this? |
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? |
The way I handled this was that I am using my own redux store and have the actual ApolloStore as a single child reducer under this store. I use the redux way to actually delete the entire store via an Action that can be called in a "logout" function for example. Since the ApolloStore is a reducer in that store, it resets/wipes it.
|
Running into continued issues with this as well. |
How are we supposed to reset the store if |
client.cache.reset() will actually clear the cache |
@stantoncbradley I tried this but it is still refetching queries. Is this supposed to actually clear the cache and NOT refetch anything? |
what about exporting defaultState from index.js containing all initial states and use cache.writeData({data: defaultState}) in logout method? index.js:
in Logout.js: |
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
.The text was updated successfully, but these errors were encountered: