5

I am using a react-native app with relay modern.

Currently our app's fetchQuery implementation, just does a fetch on the network (like in https://facebook.github.io/relay/docs/en/network-layer.html),

Although there is a possibility of another local-network layer like https://github.com/relay-tools/relay-local-schema which returns data from a local-db like sqlite/realm.

Is there a way to setup offline-first response from local-network layer, followed by automatic request to real network which also populates the store with fresher data (along with writing to local-db)? Also should/can they share the same store?

From the requirements of Network.create(), it should return a promise containing the payload, there does not seem a possibility to return multiple values.

Any ideas/help/suggestions are appreciated.

jay shah
  • 903
  • 6
  • 21
  • undocumented api https://facebook.github.io/relay/docs/en/next/fetch-query.html helps a little, but returns some masked kind of data. – jay shah Mar 23 '18 at 12:29

1 Answers1

0

What you trying to achieve its complex, and ill go for the easy approach which is long time cache.

As you might know relay modern uses a local storage and its exact copy of the data you are fetching, you can configure this store cache as per your needs, no cache on mutations.

To understand how this is achieve the best library around to customise Relay Modern or Classic network layer you can find in https://github.com/nodkz/react-relay-network-modern

My recommendation: setup your cache and watch your request.... (you going to love it)

Thinking in Relay, https://facebook.github.io/relay/docs/en/thinking-in-relay.html

Kiko Seijo
  • 701
  • 8
  • 11