Skip to content
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

useLazyQuery load function refetches from network regardless cache and variables #9209

Closed
anfinil opened this issue Dec 16, 2021 · 9 comments · Fixed by #9564
Closed

useLazyQuery load function refetches from network regardless cache and variables #9209

anfinil opened this issue Dec 16, 2021 · 9 comments · Fixed by #9564

Comments

@anfinil
Copy link

anfinil commented Dec 16, 2021

According last refactoring:

result && result.refetch(executeOptions?.variables);

reobserveOptions.fetchPolicy = 'network-only';

useLazyQuery load function will refetch data from network every time even with the same variables and regardless cache and fetchPolicy.

Desired behaviour: if load function results are cached (variables are the same), it shouldn't request network.

@Ccastillo06
Copy link

Having the same problem over here, was going crazy trying to find out why my cached responses did still requests to the server.

@orelHAnyvision
Copy link

same here

@mcsimps2
Copy link

I noticed the same issue when I was analyzing network requests with Chrome inspector

@LiamKlyneker
Copy link

Same problem here, I fixed it by returning to v3.4.17, I don't know why this feature changed in recent versions :/, maybe someone knows something about it

@hwillson hwillson added the 🔍 investigate Investigate further label Jan 4, 2022
@CowDotDev
Copy link

CowDotDev commented Jan 12, 2022

Seeing this behavior as well, additionally for my case of trying to fetchPolicy: 'cache-only' the fetch-policy is only respected on the first call. On subsequent calls a request is made to the network every time.

const [
    getLargeWarehouseSetCached,
    { loading: loadingLargeSetCached, error: errorLargeSetCached, data: dataLargeSetCached },
  ] = useLazyQuery(GET_WAREHOUSE_FULL, {
    fetchPolicy: 'cache-only',
  });

First Call: Only returns from cache - however, if there is no cached information there is no error as the documentation describes.

Second & additional calls: Always make a network request.

@sarink
Copy link

sarink commented Feb 16, 2022

Reverting to 3.4.17 also fixed it for me, thanks @LiamKlyneker

@benjamn benjamn self-assigned this Apr 6, 2022
@benjamn benjamn added this to the Release 3.6 milestone Apr 6, 2022
@benjamn
Copy link
Member

benjamn commented Apr 6, 2022

@anfinil @Ccastillo06 @orelHAnyvision @mcsimps2 @LiamKlyneker @CowDotDev @sarink Can you try the latest v3.6 beta by running npm i @apollo/client@beta when you have a chance (currently 3.6.0-beta.11)? I believe PR #9564 will help here (assuming this issue is similar to #9375). Thanks for your patience!

@colinrobertbrooks
Copy link

colinrobertbrooks commented Apr 6, 2022

@benjamn Can confirm I'm no longer seeing cache-first queries refetched with 3.6.0-beta.11. Thank you for the fix! 🎉

@anfinil
Copy link
Author

anfinil commented Apr 7, 2022

@benjamn I can confirm that fix is working.

@benjamn benjamn closed this as completed Apr 20, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.