facebook / relay

Relay is a JavaScript framework for building data-driven React applications.
https://relay.dev
MIT License
18.33k stars 1.82k forks source link

Question: How to build a progressive web app (PWA) using Relay #2214

Open hari-mohan-choudhary opened 6 years ago

hari-mohan-choudhary commented 6 years ago

hello We are planning our application to develop pwa. Is it possible. we can develop using modern relay. if possible then how we can use cache strategy, offline behaviour, service worker. Please suggest any starter.

sibelius commented 6 years ago

you can use this approach https://github.com/facebook/relay/pull/2121 by @felippepuhle

sibelius commented 5 years ago

You can improve the network layer to provide offline first support check this https://medium.com/@sibelius/relay-modern-network-deep-dive-ec187629dfd3

You can save relay store to localstorage or AsyncStorage like this https://github.com/mrtnzlml/quick-payments/blob/07cd415dbd69709e01919fdf6024ce9e4f701c94/packages/relay/src/Environment.js#L55

and always fallback to it when not connected to internet

johntran commented 5 years ago

One problem I haven't been able to get around is the service worker caching the GQL query. If the site has an update, Relay could be fetching for old data requirements on old React components, because the default service worker behavior is to check the cache before hitting the network.

This is problematic for persisted queries, because the query hashes will rarely match up between service worker and the server on site updates.

I've ended up removing persisted queries from my site, since the performance boost and slight inconvenience of service workers was worth the trade off.

josephsavona commented 5 years ago

@johntran How does not using persisted queries help? The text version of the query would change along with the hash. Can you describe your setup a bit more?

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.