Registry / testing / apollo-link-offline

apollo-link-offline

JSON →
library1.1.1jsnpmunverified

An Apollo Link (v3+ compatible) that queues all mutations optimistically when offline or on network errors, assuming requests will fail and retrying until success. Designed for speed and resilience on slow/unreliable connections. v1.1.1 is current, tested with @apollo/client ^3.7.14. Unlike other offline solutions, it always queues mutations and relies on optimistic responses for immediate UI feedback. Ships TypeScript types. Requires Apollo Client 3.7.14+, lodash, and uuid as peer dependencies. Active development with regular releases.

npm install apollo-link-offline
INSTALL
IMPORT
SIG · APOLLO-LINK-OFFLIN
A
apollo-link-offline
testingjavascriptv1.1.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

OfflineLink
import OfflineLink from 'apollo-link-offline'
const OfflineLink = require('apollo-link-offline')
Default export; ESM-only, no named export. Works in Node.js with ESM or bundlers.
OfflineLink
const OfflineLink = require('apollo-link-offline').default
const OfflineLink = require('apollo-link-offline')
When using CommonJS, require the default property explicitly.
type definitions
import { OfflineLink, OfflineOptions } from 'apollo-link-offline'
Types are exported alongside the default export; use named export for TypeScript types.

Shows full setup of Apollo Client with offline link, cache persistence, and initialization.

import OfflineLink from 'apollo-link-offline'; import { ApolloClient, InMemoryCache, ApolloLink, HttpLink } from '@apollo/client'; import { persistCache } from 'apollo-cache-persist'; import AsyncStorage from '@react-native-async-storage/async-storage'; const cache = new InMemoryCache(); const httpLink = new HttpLink({ uri: 'http://localhost:4000/graphql' }); const offlineLink = new OfflineLink({ storage: AsyncStorage }); const client = new ApolloClient({ link: ApolloLink.from([offlineLink, httpLink]), cache, defaultOptions: { watchQuery: { fetchPolicy: 'cache-and-network', errorPolicy: 'all' }, query: { fetchPolicy: 'cache-and-network', errorPolicy: 'all' }, mutate: { errorPolicy: 'all' }, }, }); await persistCache({ cache, storage: AsyncStorage }); offlineLink.setup(client); export default client;
Debug
Known issues
gotchaRequires explicit call to offlineLink.setup(client) after client creation and cache persistence.
fix
Call setup method after client initialization and cache persistence promise resolves.
affects: >=1.0.0
gotchaAll mutations are queued optimistically; if optimistic response is not provided, UI may show stale data until success.
fix
Always include an optimisticResponse in mutations.
affects: >=1.0.0
breakingBreaking: peer dependency on @apollo/client ^3.7.14. Not compatible with Apollo Client 2.x.
fix
Upgrade to Apollo Client 3.7.14 or later.
affects: >=1.0.0
gotchaStorage parameter requires an AsyncStorage-like API; not compatible with localStorage or custom storage out of the box.
fix
Provide a storage adapter that implements getItem, setItem, removeItem (async).
affects: >=1.0.0
deprecatedApollo Client's errorPolicy: 'all' may mask real errors; use with caution.
fix
Handle errors explicitly in mutation callbacks or use errorPolicy: 'none' in production.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Cannot read property 'setup' of undefined
offlineLink.setup(client) called before offlineLink is fully constructed.
fix
Ensure new OfflineLink({...}) completes before calling .setup().
Error: Could not find client object in context
offlineLink.setup(client) not called or called with wrong client.
fix
Call offlineLink.setup(client) after ApolloClient is fully created.
Invariant Violation: You must wrap your component tree with an <ApolloProvider>
Missing ApolloProvider in React tree.
fix
Wrap root component with <ApolloProvider client={client}>.
Upgrade
Version history
1.1.1latest on npm
Audit
Dependencies
@apollo/clientrequiredpeer dependency for Apollo Link interface and client operation
lodashrequiredused for deep cloning and utility functions
uuidrequiredgenerates unique IDs for queued mutations
Agent activity
40 hits · last 30 days
node
36
OpenAI (training)
1
Resources
apollo-link-offline — npm install apollo-link-offline · libregistry