1.0.3 • Published 1 year ago

urql-storage-capacitor v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

URQL Storage Capacitor

URQL Storage Capacitor

Installation

pnpm install urql-storage-capacitor

urql-storage-capacitor is a Graphcache offline storage for Capacitor.

It is compatible for both plain Capacitor (including managed workflow), but it has a two peer dependencies - Capacitor Preferences and Capacitor Network - which must be installed separately. AsyncStorage will be used to persist the data, and NetInfo will be used to determine when the app is online and offline.

Quick Start Guide

Install Capacitor Preferenceshttps://capacitorjs.com/docs/apis/preferences and Capacitor Networkhttps://capacitorjs.com/docs/apis/network alongside urql-storage-capacitor:

Install urql-storage-capacitor alongside urql and @urql/exchange-graphcache:

pnpm add urql-storage-capacitor
# or 
yarn add urql-storage-capacitor
# or
npm install --save urql-storage-capacitor

Then add it to the offline exchange:

import { createClient, dedupExchange, fetchExchange } from 'urql'
import { offlineExchange } from '@urql/exchange-graphcache'
import { makeAsyncStorage } from 'urql-storage-capacitor'

const storage = makeAsyncStorage({
  dataKey: 'graphcache-data', // The AsyncStorage key used for the data (defaults to graphcache-data)
  metadataKey: 'graphcache-metadata', // The AsyncStorage key used for the metadata (defaults to graphcache-metadata)
  maxAge: 7, // How long to persist the data in storage (defaults to 7 days)
})

const cache = offlineExchange({
  schema,
  storage,
  updates: {
    /* ... */
  },
  optimistic: {
    /* ... */
  },
})

const client = createClient({
  url: 'http://localhost:3000/graphql',
  exchanges: [dedupExchange, cache, fetchExchange],
})

Inspiration

This project is inspired by @urql/storage-rn

License

This project is licensed under the MIT License.