apollo-client: client.resetStore() doesn't reset the store
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
.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 6
- Comments: 18 (5 by maintainers)
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?
How are we supposed to reset the store if
client.resetStore()
is not resetting the store?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
resetStore
torefetchAllQueries
.client.cache.reset() will actually clear the cache https://github.com/Akryum/vue-apollo/issues/53#issuecomment-374868508
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.
what about exporting defaultState from index.js containing all initial states and use cache.writeData({data: defaultState}) in logout method?
index.js:
export const defaultState = { ...currentUser, ...someData, };
const stateLink = withClientState({ cache, defaults: defaultState, resolvers: {...}, }
in Logout.js:
this.props.logout(); this.props.client.cache.writeData({ data: defaultState });