apollo-feature-requests icon indicating copy to clipboard operation
apollo-feature-requests copied to clipboard

Cancel fetchMore network requests

Open dylanwulf opened this issue 6 years ago • 6 comments

Hello,
I would like to be able to cancel fetchMore requests in these two scenarios:

  1. When the Query component unmounts
    Currently it seems like the initial query request will get cancelled when the component unmounts, but there is no way to cancel a request which was initiated with the fetchMore function. I think this would solve apollo-client issue #4114.
  2. When the variables change
    If the variables are changed while a fetchMore request is still in progress, the results from that fetchMore request are going to be completely useless; might as well just cancel the request. I think this would solve apollo-client issue #2813

Thank you!

Edit: This could possibly be considered a migration from apollo-client #3360

dylanwulf avatar Jun 04 '19 21:06 dylanwulf

+1

hogiyogi avatar Jul 02 '19 21:07 hogiyogi

Hi any updates or workaround for this?

i8ramin avatar Oct 25 '19 10:10 i8ramin

@i8ramin I don't have any way to cancel the network request, but I did find a way to work around issue https://github.com/apollographql/apollo-client/issues/2813 I just hold onto the query variables in a ref, then in the updateQuery function i do a deep comparison between the fetchMore variables and the current query variables

dylanwulf avatar Nov 01 '19 00:11 dylanwulf

For the "when the Query component unmounts" scenario, it would be great if we could at least not get an error thrown when this happens. I don't necessarily care if the request gets cancelled (which doesn't look to be possible with fetch), I just don't want an error in my logs for an issue that doesn't actually impact the user.

Edit: Wait, I found this https://github.com/apollographql/apollo-client/issues/4114#issuecomment-502111099. Still there should probably be a better way of handling it. Or at least this should be documented maybe, I dunno.

sgtpepper43 avatar Jun 17 '20 16:06 sgtpepper43

👋 @dylanwulf - just touching base on this; do you think this is still a significant issue with current day @apollo/client? We're happy to dig into this if so.

hwillson avatar Sep 28 '21 15:09 hwillson

@hwillson Thank you for checking in! I don't think this is as big of a problem with modern-day apollo client, but it's still something which I feel would make sense to implement eventually. Currently, if a query is mounted and then unmounted the network request will be canceled. But if a query is unmounted after changing the variables or calling fetchMore, the request will not be canceled. To me this feels inconsistent and confusing, but doesn't really cause any problems so it's not super important that it get solved. Neither of the issues I referenced in the original description (https://github.com/apollographql/apollo-client/issues/4114 and https://github.com/apollographql/apollo-client/issues/2813) are a problem for me anymore. (I'm currently on @apollo/[email protected] so please excuse me if anything I stated above is no longer true in the latest version)

dylanwulf avatar Oct 05 '21 23:10 dylanwulf