-
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
Fix cache-and-network cachePolicy queries never dispatching APOLLO_QUERY_RESULT_CLIENT #1463
Fix cache-and-network cachePolicy queries never dispatching APOLLO_QUERY_RESULT_CLIENT #1463
Conversation
…ERY_RESULT_CLIENT
This change actually landed in rc.4
Thanks @BlooJeans ! Could you add a test for this? |
@helfer I found a test Line 1194 in ec9437f
It seems that the above test is checking the number of times the observableQuery fires, but I don't know the relation between observables and redux actions. Mind pointing me in the right direction? |
@BlooJeans I'm pretty sure that test is working, so maybe the real question is: how did you determine that it's not working? Was the only problem that it didn't dispatch the redux action? Either a reproduction or a test that fails without this PR would be great. The test should look pretty much like the one you linked to. |
Sorry for the wall of text: I determined it's currently fault because 'cache-and-network' claims to return the cached result, if available, and then a network request, and I wasn't noticing that in our app. I searched through the apollo repo to where apollo potentially dispatches the APOLLO_QUERY_RESULT_CLIENT and stepped through the code and realized that the current logic will never emit the APOLLO_QUERY_RESULT_CLIENT; it will always only call APOLLO_QUERY_RESULT when the network call returns. If you glance over the logic (not too complicated):
My debugging was not a refetch, nor was it network-only, so we get inside this if block. We check the cache, and my data was successfully retrieved (in full). So far so good.
This will set Two lines later:
Also sets A few lines later: this is the faulty logic imo. Dispatching the data found in the cache shouldn't only happen only when shouldFetch is false.
Again, I'm not too familiar with the internals, so maybe cache-and-network is working as intended. Assuming my analysis shows that this is a bug and my fix solves it, I'm happy to write a test to cover it, but I'm not sure what the current test is covering (i.e. the relationship between redux and the query observables) |
Thanks @BlooJeans! I agree with you that it should dispatch the QUERY_RESULT_CLIENT action, so I'm going to merge the PR 🙂 |
What is the difference between |
@grifotv there's only a fetchPolicy, I mistakingly called it cachePolicy here |
Previously: If you ran a cache-and-network query, it would read the query from the store and then never use it. This effectively made cache-and-network queries function as network-only
TODO: