RFC: Offline Exchange for Graphcache
See original GitHub issueSummary
The offlineExchange
will build on Graphcache’s persistence support (see #674) to bring full offline capabilities to the library.
It will be a new exchange that wraps around the cacheExchange
and looks identical in its API with extended functionality.
This extended functionality supplements the persistence support by being able to queue operations when the user went offline, preventing errors from surfacing in the UI when going back online, and also reexecuting operations as necessary.
It shouldn’t duplicate existing functionality, like the retryExchange
, but may build on it.
Requirements
- Catch operation results with
networkError
s and return their results if the user is online and they’re not exclusively optimistic mutations- this behaviour is compatible with
retryExchange
being added in parallel
- this behaviour is compatible with
- Optimistic mutations must be written to the persistence layer immediately and removed if they succeeded
- When coming back online (or on start) we flush the queued operations that have failed previously and empty the queue
- Prevent offline operations from calling the
fetchExchange
in the first place when offline by adding a grace period- maybe let the user decide whether to let them remain pending or whether to let them fail?
The storage adapter in Graphcache will need to be extended; this is our first draft:
export interface StorageAdapter {
readMetadata(): Promise<string>;
writeMetadata(json: string): any;
readData(): Promise<SerializedEntries>;
writeData(data: SerializedEntries): any;
onNetworkChange(cb: () => void): void;
isOnline(): boolean;
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
RFC: Offline Exchange for Graphcache · Issue #683 - GitHub
It will be a new exchange that wraps around the cacheExchange and looks identical in its API with extended functionality. This extended ...
Read more >Graphcache | urql Documentation
In urql , caching is fully configurable via exchanges, and the default ... Offline support Graphcache can persist and rehydrate its entire state, ......
Read more >swyx on Twitter: "@_philpl Do you have a spec or rfc somewhere ...
Graphcache (our normalised cache) will have schema awareness in the next RC.1! ... can hence be left out for offline partial results) and...
Read more >RFC Errata Report » RFC Editor
Found 2 records. Status: Verified (2). RFC 7664, "Dragonfly Key Exchange", November 2015. Source of RFC: IRTF. Errata ID: 5754. Status: Verified
Read more >urql cache exchange - tr.fr.edu.vn 'da Ara
@urql/exchange-graphcache | urql Documentation formidable.com › urql › docs ... RFC: Add stricter types for `cache` in graphcache resolvers ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I forgot to leave a follow-up comment here, but
v3
is now shipping Offline Support (experimental for now) with all the strategies we’ve mentioned across comments and PRs. https://formidable.com/open-source/urql/docs/graphcache/offline/We are currently checking whether we can reuse some storage adaptor code you already have here.
That being said this is kind of besides the point of this RFC (luckily) 😅 We already have a solid caching and persistence system. The persistence is already able to persist server-accurate state accordingly. Optimistic updates to the cache are separate and always have been. They’re quickly and easily invalidated automatically at the first server result (as they should be). To this point of caching, we don’t need a layer for scheduling;
so to sum this up, here’s a list of what we already have (although some of this isn’t documented as we’re waiting for additional features from this RFC)
So don’t worry about the basic persistence 😅 that’s off-topic here and basically done. We’re more interested in the hard part here of what we do in the face of network-errors.
Mutations can be partially optimistic, so part of the problem is that we’re defining what the user is likely to want to happen in the case of mutations failing, due to the client being offline. Apart from that our problems are mostly solved.
We’re mainly currently discussing what happens to the operation’s result when an optimistic mutation fails. One option is to deliver the optimistic result to the framework bindings immediately and rely on the user to only use optimistic results where it’s sensible.
The other option is to defer the result indefinitely for mutations during offline, or to even deliver the errored result itself. Which are not the favoured options right now 🙃
tl;dr: this is not about persistence of cache data and/or conflict resolution, but simply around the implementation of a full offline exchange 😇