How to use @wora/apollo-offline - 5 common examples

To help you get started, we’ve selected a few @wora/apollo-offline 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 { 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);
  },
github morrys / offline-examples / apollo / nextjs / pages / index.tsx View on Github external
const Home = props => {
  const {loading, error, data, ...others} = useQuery(USER_TODOS, {
    variables: {
      // Mock authenticated ID that matches database
      userId: 'me',
    },
  });

  if (loading) return <div>;
  if (error) return `Error! ${error.message}`;
  return ;
};
</div>
github morrys / offline-examples / apollo / nextjs / pages / you.tsx View on Github external
const Home = props =&gt; {
  const {loading, error, data, ...others} = useQuery(USER_TODOS, {
    variables: {
      // Mock authenticated ID that matches database
      userId: 'you',
    },
  });
  if (loading) return <div>;
  if (error) return `Error! ${error.message}`;
  return ;
};
</div>
github morrys / offline-examples / apollo / react-native / todo / src / apollo / index.js View on Github external
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;
github morrys / offline-examples / apollo / nextjs / apollo / createApolloClient.ts View on Github external
export function createApolloClient(initialState = {}) {
  const httpLink = new HttpLink({
    uri: 'http://localhost:3000/graphql',
  });

  const cacheOptions = {
    dataIdFromObject: o => o.id,
  };

  const persistOptions = {
    initialState,
  };

  const client = ApolloClientIDB.create(
    {
      link: httpLink,
    },
    {
      cacheOptions,
      persistOptions,
    },
  );
  /*
  const client = new ApolloClient({
    link: httpLink,
    cache: new ApolloCache(cacheOptions, cachePersistOption),
  });*/

  client.setOfflineOptions({
    manualExecution: false, //optional

@wora/apollo-offline

@wora Apollo Offline Capabilities

MIT
Latest version published 3 years ago

Package Health Score

45 / 100
Full package analysis