Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { ApolloClient } from "@wora/apollo-offline";
import ApolloCache from "@wora/apollo-cache";
import { HttpLink } from "apollo-link-http";
// import ApolloClientIDB from '@wora/apollo-offline/lib/ApolloClientIDB';
const httpLink = new HttpLink({
uri: "http://localhost:4000/graphql"
});
const cacheOptions = {
dataIdFromObject: o => o.id
};
const client = new ApolloClient({
link: httpLink,
cache: new ApolloCache(cacheOptions)
});
client.setOfflineOptions({
manualExecution: false, //optional
link: httpLink, //optional
start: async mutations => {
//optional
console.log("start offline", mutations);
return mutations;
},
finish: async (mutations, error) => {
//optional
console.log("finish offline", error, mutations);
},
return true;
},
onPublish: (offlinePayload) => { //optional
//const rand = Math.floor(Math.random() * 4) + 1
//offlinePayload.serial = rand===1;
//console.log("offlinePayload", offlinePayload.serial)
console.log("onPublish offline", offlinePayload)
return offlinePayload
}
};
const cacheOptions = {
dataIdFromObject: o => o.id
};
const client = new ApolloClient({
link: httpLink,
cache: new ApolloCache(cacheOptions)
}, offlineOptions);
export default client;