withspectrum/apollo-link-queue

Name: apollo-link-queue

Owner: Spectrum

Description: A link to queue GraphQL requests when offline

Created: 2018-03-01 13:59:29.0

Updated: 2018-04-04 00:56:08.0

Pushed: 2018-03-02 08:00:52.0

Homepage: null

Size: 81

Language: TypeScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

apollo-link-queue

npm version Build Status codecov

An Apollo Link that acts as a gate and queues requests when the gate is closed. This can be used when there is no internet connection or when the user has explicitly set an app to offline mode.

Installation
install apollo-link-queue

or

 add apollo-link-queue
Usage
rt QueueLink from 'apollo-link-queue';

t queueLink = new QueueLink();

o start queueing requests
eLink.close();

o let requests pass (and execute all queued requests)
eLink.open();
Offline mode example with queueing and retry
rt { ApolloLink } from 'apollo-link';
rt { HttpLink } from 'apollo-link-http';
rt { RetryLink } from 'apollo-link-retry';

rt QueueLink from 'apollo-link-queue';

t offlineLink = new QueueLink();

ote: remove these listeners when your app is shut down to avoid leaking listeners.
ow.addEventListener('offline', () => offlineLink.close());
ow.addEventListener('online', () => offlineLink.open());

.link = ApolloLink.from([
new RetryLink(),
offlineLink,
new HttpLink({ uri: URI_TO_YOUR_GRAPHQL_SERVER }),


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.