Inconsistent results with cache-only
between useLazyQuery
and client.query
#10236
Labels
cache-only
between useLazyQuery
and client.query
#10236
Intended outcome:
Usage of
useLazyQuery
(and likely useQuery) andclient.query
differ in the results given to fetching a query withfetchPolicy
set tocache-only
and the cached record missing fields. According to the docs it should throw an error - this doesn't happen, and different data is returned depending on which implementation is used.I would expect to be given an error if a complete query could not be returned from cache - and consistent behaviour on whether to return a partial query or
undefined
for data.Actual outcome:
useLazyQuery
- returnsundefined
for data andundefined
for error.client.query
- returns partial data query andundefined
for error.The lack of errors here can mean silent bugs creeping into applications.
How to reproduce the issue:
https://github.com/leepowelldev/apollo-client-bug
Versions
System:
OS: macOS 12.6
Binaries:
Node: 18.10.0 - /usr/local/bin/node
Yarn: 1.22.17 - /usr/local/bin/yarn
npm: 8.19.2 - /usr/local/bin/npm
Browsers:
Chrome: 106.0.5249.119
Edge: 106.0.1370.52
Firefox: 106.0.2
Safari: 16.0
npmPackages:
@apollo/client: ^3.7.1 => 3.7.1
Update: Adding
returnPartialData: true
to the hook allows it to remain consistent with the result returned fromclient.query
however, when addingreturnPartialData: false
toclient.query
seems to make no difference and it still returns partial data. And oddly if I setreturunPartialData: true
toclient.query
I get aInvariant Violation: returnPartialData option only supported on watchQuery
error - when according to the docs it should be possible to setThe text was updated successfully, but these errors were encountered: