react-relay-offline icon indicating copy to clipboard operation
react-relay-offline copied to clipboard

Retrying mutations on network failure

Open Felix-N opened this issue 4 years ago • 9 comments

Hi Morries,

im currently testing the replay of mutations in case of network failure.

Pure offline/online mode works fine, however as soon as a network query fails that one is not replayed again. The local store reflects the change, but it won't be communicated to the server.

Am I doing something wrong here, or is this intentional? I'm kinda looking for a retry strategy, the assumption is that users may have a flaky internet connection and requests my fail due to that but should be replayed later on.

Felix-N avatar Aug 08 '20 14:08 Felix-N

I found the parts about onDiscard, which resolves part the part of the issue where offline request would be discarded if they failed once online.

However I've still the issue that a request which is being made (while online) fails due to connectivity issues, is not retried.

Should this be handled by the library (in particular TypeError: Failed to fetch)?

Felix-N avatar Aug 09 '20 22:08 Felix-N

At the moment I have no retry logic in the library to leave the management at the network level (eg. react-relay-network-modern)

morrys avatar Aug 10 '20 11:08 morrys

Or in the finish method you can schedule another processing with the process method of the offline store.

morrys avatar Aug 10 '20 11:08 morrys

whats from a user perspective (mine ;)) a bit odd is that a failed network request with a failed to fetch is behaving different than being offline.

as well that if the request was scheduled offline and onDiscard returns false, it is going to be retried even if the network requests fails.

i haven't figured yet out how to handle it well, in particular as the order is important of mutations on the same node.

Felix-N avatar Aug 10 '20 12:08 Felix-N

i haven't figured yet out how to handle it well, in particular as the order is important of mutations on the same node.

this is one of the reasons why I have not put retry logic inside the library but I have given the possibility to configure / customize each step of the offline workflow.

morrys avatar Aug 10 '20 17:08 morrys

but isn't the logic kind of implemented if the mutation is done while being 'offline'?

from my perspective i'd love to have one path all mutations or queries take, independent of my current network or connectivity state.

Felix-N avatar Aug 10 '20 20:08 Felix-N

What you are asking for is NetInfo's isInternetReachable offline workflow management, which is currently not implemented.

is it right?

morrys avatar Aug 11 '20 10:08 morrys

honestly i do not know netinfo, so hard to say ...

Felix-N avatar Aug 11 '20 20:08 Felix-N

At the moment the application is considered offline when the APIs made available in the WEB / react-native consider it as such (If there is an active network connection)

While isInternetReachable defines whether the Internet is reachable with the currently active network connection.

morrys avatar Aug 12 '20 11:08 morrys