-
Notifications
You must be signed in to change notification settings - Fork 101
Link State breaks after client.resetStore() #156
Comments
Full error message here:
|
Good point. And as Our current solution is using cache as argument and not wrap it nor return the instance, so each link would have to mutate the cache object which is just bad architecture. I would suggest some function like Or it will accept array of Or if we define it's arguments as object in shape like
We would enhance it in a way which would allow us to override also these things. For example current official persist link is mutating cache itself and not just wrapping it. This way it could just enhance it in our helper function. Not sure if we want to prepare some apollo-client or utils function which can be reused, or we prepare just 1 simple enhancer for our usecase. In both cases I would return new instance so it can be chained if needed. That would let us use default Link cache pointer and not need to provide it as argument.
I did not check how adding |
Hey @stolinski, thanks for reporting this! This is happening because we need to populate the cache with the defaults again after calling Thanks @ShockiTV for looking into a possible solution. This use case is tricky since the state link has no way to hook into events orchestrated by the client. @jbaxleyiii and I have been discussing an events API for Apollo Client that will make these types of problems non-existent in the future. For now, we've added a hook to the client that will allow you to register callbacks that will be executed after |
Forgot to mention the solution is documented here: and here: |
I've updated all version and am using You can see this in action with. Errors shown are:
|
Apparently adding a query of any kind to your state resolvers fixes this. As mergebandit mentioned on Slack. None of the examples or docs show anything about a query being needed. I can't imagine needed a |
How about with apollo-boost ?
|
Same issue as @moseslucas, it's unclear how to enable restoration of default values after resetting the store with Right now, I'm getting around this with a custom mutation which re-writes all the default store values, but it would be nice if |
I am also having this issue. Looking for a workaround as |
Same issue here. It seems that link-state fails to reset defaults when executing |
I just ran into the same error after following the documentation. Is this indeed closed and fixed or is still an open issue? |
Intended outcome
Calling client.resetStore() after a user logs in or out to reset the entire store. Expected things to work as they do without link state.
Actual outcome
All active link state queries throw errors
Uncaught (in promise) TypeError: Cannot read property 'todos' of undefined at resolver
(where "todos" is the name of the property) and all future mutations on those stop working without a refresh.How to reproduce the issue
https://github.com/stolinski/apollo-link-state-todos-resetStorebug
Add some todos and click the reset store button. Both todos and visibilityFilter will error out.
The text was updated successfully, but these errors were encountered: