Skip to content

e9labs/apollo-link-offline

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

apollo-link-offline GitHub license PRs Welcome

An Apollo Link to queue mutations when offline or network errors exist.

NOTICE: This is still experimental, any comments and/or pull requests are welcome!

Setup

yarn add apollo-link-offline

Example

React Native

import { AsyncStorage } from "react-native";
import ApolloClient from "apollo-client";
import { ApolloLink } from "apollo-link";
import { InMemoryCache } from "apollo-cache-inmemory";
import OfflineLink from "apollo-link-offline";
import { persistCache } from "apollo-cache-persist";

const offlineLink = new OfflineLink({
  storage: AsyncStorage
});

const cache = new InMemoryCache();

const client = new ApolloClient({
  link: ApolloLink.from([offlineLink, serverLink]),
  cache,
  defaultOptions: {
    watchQuery: {
      fetchPolicy: "cache-and-network",
      errorPolicy: "all",
    },
    query: {
      fetchPolicy: "cache-and-network",
      errorPolicy: "all",
    },
    mutate: {
      errorPolicy: "all"
    }
  }
});

await persistCache({
  cache,
  storage: AsyncStorage,
  maxSize: false,
  debug: false
});

offlineLink.setup(client);

export default client;

About

An Apollo Link to queue mutations when offline or network errors exist.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%