Skip to content
This repository has been archived by the owner on Jul 10, 2019. It is now read-only.

apollo client resetStore with apollo-link-state triggers Error: Network error: Cannot read property of undefined #198

Closed
rares-lupascu opened this issue Feb 2, 2018 · 16 comments · Fixed by #202

Comments

@rares-lupascu
Copy link

I am trying this a second time because the previous issue was closed without a single test #194
so the error is replicated here https://codesandbox.io/s/v69v13w0o0
you will see the error in the console after clicking the reset button which does client.resetStore

i really hope we can sort this out
thanks

@EQuimper
Copy link

EQuimper commented Feb 5, 2018

  • 1 for me, I also did like told in the docs about putting statelink.writeDefaults and nothing change same error.

@rares-lupascu
Copy link
Author

i added client.onResetStore(stateLink.writeDefaults);

the error exists with or without this callback

@wKovacs64
Copy link

Agreed, writeDefaults is not currently working.

@rares-lupascu
Copy link
Author

looking into the code i realized that this is actually an apollo client bug ... not related to apollo-link-state

@res84
Copy link

res84 commented Feb 6, 2018

+1 for me...
i think same issue on #187, #194... and #195 should fix.. but i am still getting the same error even upgrading both apollo-cache-inmemory and apollo-link-state...

"apollo-cache-inmemory": "^1.1.7",
"apollo-client": "^2.2.2",
"apollo-link-state": "^0.4.0",
"apollo-utilities": "1.0.6"

@res84
Copy link

res84 commented Feb 7, 2018

ok, i guess the trick is adding query to state resolvers like mentioned in #156 by Scott (@stolinski)

@rares-lupascu
Copy link
Author

yeap :) that fixed it :)

@wKovacs64
Copy link

Maybe you are seeing different results than I, but simply adding an empty/dummy query to my resolvers map is not fixing anything. It masks the problem by causing the new (after a resetStore() call) resolverMap to exist, but the default resolvers are not present so future queries do not resolve properly, warning about Missing field someArbitraryStateField in {}.

@rares-lupascu
Copy link
Author

@wKovacs64 u jinxed my code ... i can swear it was working yesterday ... now indeed i get Missing field :(

here is the updated link:
https://codesandbox.io/s/v69v13w0o0

i really hope we aren't the only ones tracking this issue :)

@wKovacs64
Copy link

Maybe Apollo will clone @peggyrayzis for additional bandwidth. 😉 🤞

@evans
Copy link
Contributor

evans commented Feb 9, 2018

@wowzaaa Thank you for opening the issues! Really appreciate the codesandbox! It made spinning up on the project really nice. Please check out #202. It is sort of a temporary fix, since the query resolvers don't see the defaults yet. Let me know if #202 is what you are looking for or you need the cache.readQuery functionality as well.

@wKovacs64 Thank you for the followup! Hopefully I can live up to a clone of peggy 🙏 Please take a peek at #202 when you get a chance!

@rares-lupascu
Copy link
Author

@evan hi and thank you for your help ... i added Query: () => {}, to the resolvers but not it triggers a warning that Missing field counter in {}
i updated the codesandbox demo
https://codesandbox.io/s/3q2724orp5

thanks

@wKovacs64
Copy link

#202 ...*resolves... the issue for my use case (I don't need cache.readQuery yet). Thank you, @evans!

*Sorry, couldn't resist. Not sorry. 😆

@rares-lupascu
Copy link
Author

@wKovacs64 did u do anything else than adding Query: () => ({}), to the resolvers? beucase i suggested that a few days ago and u mentioned the a missing field warning appears ... which i understand you do not get anymore ... so did u change anything else?

thanks

@wKovacs64
Copy link

@wowzaaa I didn't add Query: () => ({}), it works without that (as it should). PR #202 is what fixes it, but it isn't merged/published yet. To test and confirm that it works for you, you can perform the following steps:

  1. git clone https://github.com/apollographql/apollo-link-state.git
  2. cd apollo-link-state/packages/apollo-link-state && git checkout reset-store-fix
  3. yarn && yarn build
  4. yarn link
  5. Change directories back into your project
  6. yarn link apollo-link-state

At that point, your project will be using your local copy of apollo-link-state with the fix in place.

Note:
If you do this, be sure to yarn unlink when you're done testing.

@rares-lupascu
Copy link
Author

awesoeme response thanks :)

yes it works :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
5 participants