morrys / react-relay-offline

TypeScript library files for Relay Modern Offline
https://morrys.github.io/react-relay-offline/docs/react-relay-offline.html
MIT License
230 stars 15 forks source link

Retrying mutations on network failure #52

Open Felix-N opened 4 years ago

Felix-N commented 4 years ago

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 commented 4 years ago

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)?

morrys commented 4 years ago

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 commented 4 years ago

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

Felix-N commented 4 years ago

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.

morrys commented 4 years ago

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.

Felix-N commented 4 years ago

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.

morrys commented 4 years ago

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

is it right?

Felix-N commented 4 years ago

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

morrys commented 4 years ago

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.