Open molyholy opened 3 months ago
Hi @molyholy 👋
Thanks for this detailed description and reproduction. I've taken a quick look and also noticed this open issue: https://github.com/apollographql/apollo-client/issues/6857
I don't have an answer right now, but I've put this on our team's agenda for discussion and hope to get back to you soon with more info :) Thanks!
Thank you :)!
Hey sorry to bother you all, but is there any update on this?
Issue Description
Hello! I'm encountering a peculiar behavior when using
fetchMore
for pagination. I'm noticing that if the initial call touseQuery
succeeds, but then a subsequent call tofetchMore
fails, thenonError
is never called. Instead,onComplete
is called and theresponse
object will contain the result from the initial, successfuluseQuery
call (presumably because it's cached by Apollo via the cache field policy, but i'm not sure of the specifics).However, this leads to
fetchMore
being called infinitely.onComplete
is where we callfetchMore
, and sinceonComplete
is being called instead ofonError
, andresponse
will always exist, thenfetchMore
is just going to be called again and again. Is this a bug with Apollo? Or is there any way to forcefetchMore
to stop when it encounters an error?Below is a simplified version of my code. I've also provided a working example via codesandbox. Essentially, the initial
useQuery
call is successful, but then I pass in garbage params into thefetchMore
to force an error which should simulate what it's like for thefetchMore
to encounter an API error in real code.Link to Reproduction
https://codesandbox.io/p/devbox/wonderful-tdd-4hhnpl?file=%2Fsrc%2Findex.jsx%3A47%2C17
Reproduction Steps
Open up the codesandbox, open up dev tools and look at the console logs. There should be an infinite loop of queries
@apollo/client
version^3.7.15