2

How would you combine / solve the two diverging approaches of:

  • rtk query / graphql advising to only fetch what is needed on that screen
  • offline first capability

in a react native app?

Basically apollo and also rtk-query advise for small queries that are only fetching data that is relevant to what the component needs. This would mean that all data is only present when rendered, but what happens when the user does not have internet?

We don't want the user to see outdated data if they haven't visited that screen for a long time so we want to fetch this in the background and never show loading spinners. When they are offline everything should be as up to date as possible and usable.

Also mutations should be queued and performed when internet access is restored. The app should basically behave as if there is no connection issue at all.

So probably a graphql subscription would be ok but everyone strongly discourages to the subscribe-to-anything-pattern. Subscriptions in graphql still sound like they should be small and also only care about what is rendered on the screen and unsubscribe when the screen is unmounted.

At this point this whole seems like a graphql anti-pattern to me, but from a user perspective it makes sense for a (react) native app. You want stuff to be up to date because it is an app not a website where a lot of data is cached anyway and timeliness doesn't matter that much.

uloco
  • 2,283
  • 4
  • 22
  • 37

0 Answers0