apollo-client: apollo-client not working as expected for `network-only` cache policy, duplicate requests noticed
Intended outcome: Network tab doesn’t show duplicate query requests
Actual outcome:
Noticed the query being requested for twice How to reproduce the issue:
Versions System: OS: macOS High Sierra 10.13.6 Binaries: Node: 12.9.1 - /usr/local/bin/node npm: 6.10.3 - /usr/local/bin/npm Browsers: Chrome: 84.0.4143.2 Firefox: 75.0 Safari: 13.1 npmGlobalPackages: apollo: 3.0.0-beta.45
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 9
- Comments: 23 (7 by maintainers)
minimal reproduction here: codesandbox
Intended outcome: 1 request to
/api/graphql
when clicking theFetch More
buttonActual outcome: 2 requests to
/api/graphql
How to reproduce the issue: click
Fetch More
& observe in devtools network tabrunning into the same issue as @kfazinic — cache-first is the only option that will render the correct data.
network-only
andcache-and-network
both first two requests… the first one has the correctoffset
, and the second is a stale offset. on apollo-clientv3.3.9
I am seeing this as well. The change happened in
@apollo/client@3.0.0-beta.45
and has the same behavior up to@apollo/client@3.0.0-beta.50
.@apollo/client@3.0.0-beta.44
does not have the issue.I will work on unraveling my project a bit and try to create a reproduction.
Sorry guys, I’m upgrading my project from v2 to v3. I’m trying to figure out why is it making duplicate requests. Correct me if I’m wrong team, I solved my the problem, in my case, by providing both fetchPolicy and nextFetchPolicy in useQuery hook? For example, fetchPolicy: “cache-and-network” and nextFetchPolicy: “cache-first”.
I can confirm that this is happening in our application on
beta.49
for us as well. We have a code change where all we did was flip our main query fromcache-and-network
tonetwork-only
and this exact problem manifests. No other code changes introduced.I am sorry I cannot provide a minimum reproduction, but for what it’s worth we are using
@client
directive on the query and are resolving its data via a client-side resolver.In my case I noticed second http request was being made with empty variables when I use
fetchMore
. I was usingnetwork-only
as myfetchPolicy
since my use-case was fetching paginated list of latest events, As a workaround, I changedfetchPolicy
tocache-first
which would make single http request always, and useduseEffect
to clear related cache on component unmount and refetching data conditionally, as so:I’ve been digging through open issues a bit trying to find something similar to what I’ve been experiencing, and I’d like to suggest that this may be a duplicate of #6301. The reproduction linked and the fix suggested there may be helpful.
There is something I don’t understand from the docs:
What is meant by “initial data”? I tried to browse through the doc for its meaning, but it is not clarified.
@jpvajda We have upgraded to the latest version, We don’t notice this anymore. Thank you so much ill close the ticket
Any update from this issue? I am also experiencing duplicate network requests using useQuery hook of @Apollo/client. Thanks
I have this issue when using
useLazyQuery
.loadResults()
requests just once, butfetchMore
(where I give a differentoffset
value) requests twice: first with the newoffset
given in its options, then with the originaloffset
(0).Any solution to this?
For what it’s worth, I am also getting “No more mocked responses” error for queries and mutations that do not have a
fetchPolicy
explicitly set. The weird thing is that sometimes just duplicating the mock will “fix” it. Other times, I can create many, many copies of the mock and it will still give the “No more mocked responses” error.