Open FelixMalfait opened 7 months ago
Discussed with Lucas: we will most likely just use cache-and-network
even for nextFetchPolicy
because the subscription/sync engine will only listen to queries that are in context for the current user (ex: record he's viewing)
As of today we are using "cache-first" strategy and "in-memory" storage.
Instead we would like to introduce a persistent storage through https://github.com/apollographql/apollo-cache-persist/ (most likely LocalStorage).
Instead of using fetchPolicy we will use:
initialFetchPolicy: cache-and-network
nextFetchPolicy: cache-first
The idea is that the cache coming from localStorage is considered to be less trustworthy (we weren't connected to the app so objects might have changed) - with this setting we ensure that users see cached data immediately for a fast initial load while updating with fresh data from the network. On subsequent load, the data should be trustworthy because we'll have websocket so we can keep the current setting which is cache-first.
I tried to do a quick proof of concept:
useMemo
; I'm not sure we need to await for cache persistance since our initialFetchPolicy is "cache-and-network" which will throw a request anyway this seems superfluous to me so I left it this way