Any advice on how we can get some of these things working would be appreciated. If you have a more complete React Native example with this type of basic implementation you can point us at too, that would be helpful I think.
Our app.js...
const client = new ApolloClient({
link: httpLink,
cache: new ApolloCache({
dataIdFromObject: (o) => o.id,
}),
});
client.setOfflineOptions({
manualExecution: false, //optional
link: httpLink, //optional
start: async (mutations) => {
//optional function that is called once the request queue has been started
console.log('start offline', mutations);
return mutations;
},
finish: async (mutations, error) => {
//optional function that is called once the request queue has been processed
console.log('finish offline', error, mutations);
},
onExecute: async (mutation) => {
//optional function that is called before the request is sent to the network
console.log('onExecute offline', mutation);
return mutation;
},
onComplete: async (options) => {
//optional function that is called once the request has been successfully completed. Only if the function returns the value true, the request is deleted from the queue
console.log('onComplete offline', options);
return true;
},
onDiscard: async (options) => {
//optional function that is called when the request returns an error. Only if the function returns the value true, the mutation is deleted from the queue
console.log('onDiscard offline', options);
return true;
},
onPublish: async (offlinePayload) => {
//optional function that is called before saving the mutation in the store
console.log('offlinePayload', offlinePayload);
return offlinePayload;
},
});
export default function App() {
client.hydrate();
const [showAdd, setShowAdd] = useState(true);
const [hydrated, setHydrated] = useState(false);
const [online, setOnline] = useState(false);
const [cache, setCache] = useState('');
const checkMorrys = async () => {
const storeOffline = client.getStoreOffline();
const cacheState = storeOffline.getState();
const cacheList = storeOffline.getListMutation();
setHydrated(client.isRehydrated());
setOnline(client.isOnline());
setCache(JSON.stringify(cacheState, null, 2));
console.log('Offline queue: ', storeOffline);
console.log('Cache state: ', cacheState);
console.log('Cache list: ', cacheList);
};