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

Apollo seems to hit the network consistently, even if "cache-only" is the fetch policy #11341

Closed
glebdv opened this issue Nov 3, 2023 · 6 comments

Comments

@glebdv
Copy link

glebdv commented Nov 3, 2023

Trying to figure out if im doing something wrong here.

Query: (we're using codegen to generate types from the schema)

image

ROOT_QUERY cache:

image

The component is basically a two part radio group toggle that either fetches all availableHospitalsForAppointment with deptId: null or per department scpecific hospitals.

However, it seems that every time the call is made, a network request is always made, and always hits the backend.

All of the below calls are GetAvailableHospitalsForAppointment queries

image

we have custom typePolicies for certain things, but none for that graphtype

any thoughts on why this could happen? I set it cache-only just to check, but it always seems to hit the backend, otherwise we have it at cache-first

@glebdv
Copy link
Author

glebdv commented Nov 3, 2023

does it maybe have anything to do with the fact that we are refetching the query?
image

@glebdv
Copy link
Author

glebdv commented Nov 3, 2023

ok like 99% convinced its because of that; is there any way of setting the fetch policy or will I have to transform this to a lazyQuery?

@glebdv
Copy link
Author

glebdv commented Nov 3, 2023

100% convinced its that. I just changed it to a lazyQuery that fires on load although I try to avoid the useEffects as much as I can

@phryneas
Copy link
Member

phryneas commented Nov 6, 2023

Yes, it's due to the refetch - there's no more explicit way of saying "I really want this to hit the network layer" than calling refetch.

Question: why do you not skip any useEffects and just set a state with the variables you want to use for your query? The component will rerender and the useQuery hook will execute for those new variables.

@glebdv
Copy link
Author

glebdv commented Nov 8, 2023

good point, I did exactly that,thank you!

@glebdv glebdv closed this as completed Nov 8, 2023
Copy link
Contributor

github-actions bot commented Dec 9, 2023

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
For general questions, we recommend using StackOverflow or our discord server.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants