How to use @wora/apollo-cache - 3 common examples

To help you get started, we’ve selected a few @wora/apollo-cache examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github morrys / offline-examples / apollo / todo / client / src / apollo / index.js View on Github external
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);
  },
  onExecute: async mutation => {
    //optional
github morrys / offline-examples / apollo / react-native / todo / src / apollo / index.js View on Github external
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;
github morrys / wora / packages / apollo-offline / src / ApolloClientIDB.ts View on Github external
...offlineStoreOptions,
        };
        if (typeof window !== 'undefined') {
            const { name = 'apollo', onUpgrade, version } = idbOptions;
            const idbStorages: Array = IDBStorage.create({
                name,
                storeNames: ['store', 'offline'],
                onUpgrade,
                version,
            });

            idbStore.storage = idbStorages[0];
            idbOffline.storage = idbStorages[1];
        }

        const cache = new ApolloCache(cacheOptions, idbStore);
        return new ApolloClientOffline({ ...config, cache }, idbOffline);
    }
}

@wora/apollo-cache

@wora Apollo Cache

MIT
Latest version published 3 years ago

Package Health Score

45 / 100
Full package analysis

Popular @wora/apollo-cache functions