Query Functionality with onCompleted
is broken in v3.0.0 release (CodeSandbox repro) #6636
Description
Some core lazy querying functionality through useLazyQuery
seems a bit off.
Specifically, when a lazy query (through a useLazyQuery
hook) returns an error, then Apollo seems to start endlessly querying the server. The same thing happens if you give it a fetchPolicy
of network-only
(or anything that doesn't search the cache first).
Related: apollographql/react-apollo#4044
At the same time, if the lazy query function (returned by useLazyQuery
) gets called more than 1 times, then no callbacks are fired. The onCompleted
doesn't fire again. The onCompleted
fires on the 1st successful run of the "query" function and then consecutive invocations of the lazy query function, don't trigger onCompleted
callback (they should, since you can't have conditional business logic based on whether the data is cached or not!)
Related: apollographql/react-apollo#4000
Funnily enough, using client.query()
works fine. All this used to work perfectly during the beta (I think I've verified that something occurred after @apollo/client@v3.0.0-beta.43
), but now it doesn't.
UPDATE: I've added a codesandbox that reproduces it
Intended outcome:
- Lazy query errors shouldn't trigger endless API querying
- A
network-only
fetch policy shouldn't trigger endless API querying on a lazy query onCompleted
should fire every time a lazy query gets successfully executed
Actual outcome:
- Lazy query errors &
network-only
fetch policy start an endless loop of requests onCompeted
gets fired at most once regardless of the number of invocations
How to reproduce the issue:
- Take a lazy query and change the
fetchPolicy
tonetwork-only
or force an API error on a lazy query - Click a button that triggers a lazy query multiple time, while observing the number of invocations of the
onCompleted
callback.
Versions
System:
OS: macOS 10.15.2
Binaries:
Node: 12.18.0 - /usr/local/bin/node
Yarn: 1.19.0 - /usr/local/bin/yarn
npm: 6.14.4 - /usr/local/bin/npm
Browsers:
Chrome: 83.0.4103.116
Firefox: 72.0.2
Safari: 13.0.4
npmPackages:
@apollo/client: ^3.0.2 => 3.0.2
apollo-link-error: ^1.1.12 => 1.1.13