Apollo-client: Refetch after being offline

Created on 14 Mar 2017  ·  13Comments  ·  Source: apollographql/apollo-client

Intended outcome:
When initiating query offline and failing to fetch it, I expect refetch to work after going online.

Actual outcome:
When offline and failing to fetch a query, if you go online and try to refetch it apollo fails producing network error "Network request failed". (it happens in 1.0.0.rc2, does not happen in 0.10.1)

How to reproduce the issue:
Turn off network, open a screen of your app querying sth and wait until it fails, turn on network, try to refetch.

good-first-issue ✔ confirmed 🐞 bug 🙏 help-wanted

Most helpful comment

@NeoPhi I think I know what the problem is, so I can fix it without a reproduction. But thanks anyway! 🙂

All 13 comments

I've been seeing very similar results, meaning the app effectively fails to come back from network issues

Although I actually still see the problem in 0.10.1, and also with fetchMore. This is in a react native app along with react-apollo.

I think I've found the problem - does this seem like a reasonable amendment? It fixes the problems I'm seeing

https://github.com/siliconrhino/apollo-client/commit/a0d84672a4c0e2408334e6e6309bc7dd4fb2335c

The plot thickens - the above only fixes fetchMore with queryDeduplication turned off. It seems refetch works anyway with queryDeduplication turned off, and so it seems there are 2 problems here:

  • queryDeduplication breaking any follow up requests after encountering network errors
  • fetchMore failing for follow up requests after encountering network errors

That could explain why @binchik is only seeing it for refetch in the RC, as queryDeduplication was defaulted to false before as per https://github.com/apollographql/apollo-client/pull/1362

Could either of you create a reproduction with react-apollo-error-template? It would go a long way in helping us find out exactly what is wrong and then fixing it. Having a reproduction with both refetch and fetchMore would be helpful.

Since the error template does not actually make an HTTP request you’ll probably want to add a switch to simulate going offline. If the switch is true then the network interface will always throw an error. If the switch is false then the network interface will always execute the request.

You can find the network interface for react-apollo-error-template here: https://github.com/apollographql/react-apollo-error-template/blob/master/src/graphql/networkInterface.js#L6-L15

@philhardy thanks for digging into this! The queryDeduplication issue sounds like a simple bug that should be relatively easy to fix, and it seems like it could be the original issue here.
@binchik can you confirm that refetch works when queryDeduplication is set to false when initializing the client?

There's probably a network request info somewhere that should be cleared out when a query errors. Would you mind making a PR to fix that @philhardy !? If necessary, you can first try isolating the error with the template like @calebmer suggested.

The fetchMore issue looks like a separate one, and it's a bit more complicated, because the reason we put the networkError on the query in the first place is so the original query gets notified if there's an error on the fetchMore query. I'm not sure simply clearing out the error when fetchMore is called is the right thing. Could you open a new issue about this specific problem @philhardy?

@helfer Hi! I tried to reproduce the issue again with 1.0.0-rc.2 and it suddenly disappeared without setting queryDeduplication to false. I changed some of my code between opening the issue until now, not sure what caused the disappearance.

I have 1.0.0-rc.3 and I can confirm that fetchMore works when queryDeduplication is set to false.

I am on 1.0.0-rc.6 and am seeing this issue when I call refetch(). Setting queryDeduplication to false does fix the issue.

I'm trying to find the time to do some of the suggested - will get back if no one beats me to it

Believe that we are hitting a similar issue when using pollInterval. If one of the query attempts fails then all later ones fail as well. I'll try to put together a sample later today or tomorrow if @philhardy doesn't get to something first.

@NeoPhi I think I know what the problem is, so I can fix it without a reproduction. But thanks anyway! 🙂

this pr might help - using it the current queries automatically refetch when the websocket reconnects...

https://github.com/apollographql/apollo-link/pull/235

Was this page helpful?
0 / 5 - 0 ratings