Skip to content

Commit

Permalink
Update examples to use storage wrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
wodCZ authored and wtrocki committed Nov 21, 2020
1 parent 8453fbb commit 66217bb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 19 deletions.
4 changes: 2 additions & 2 deletions examples/react-native/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import React, { useEffect, useState } from 'react';
import { SafeAreaView, StyleSheet, ScrollView, Text } from 'react-native';
import { ApolloClient, InMemoryCache } from '@apollo/client';
import { persistCache } from 'apollo3-cache-persist';
import { persistCache, AsyncStorageWrapper } from 'apollo3-cache-persist';
import AsyncStorage from '@react-native-community/async-storage';
import { gql } from '@apollo/client';

Expand All @@ -26,7 +26,7 @@ const App = () => {
const cache = new InMemoryCache();
await persistCache({
cache,
storage: AsyncStorage,
storage: new AsyncStorageWrapper(AsyncStorage),
});
const client = new ApolloClient({
uri: 'https://48p1r2roz4.sse.codesandbox.io',
Expand Down
19 changes: 2 additions & 17 deletions examples/web/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,14 @@ import { render } from 'react-dom';
import { ApolloProvider, ApolloClient, useQuery, makeVar, useReactiveVar } from '@apollo/client';
import gql from 'graphql-tag';
import { InMemoryCache } from '@apollo/client/core';
import { CachePersistor } from 'apollo3-cache-persist';
import { PersistentStorage } from "apollo3-cache-persist/types";
import { CachePersistor, LocalStorageWrapper } from 'apollo3-cache-persist';

let persistor;

class LocalStoragePersistedStorage implements PersistentStorage {
getItem(key: string): string | null {
return localStorage.getItem(key);
}

removeItem(key: string) {
localStorage.removeItem(key);
}

setItem(key: string, data: any) {
localStorage.setItem(key, data);
}
}

async function createClient() {
const cache = new InMemoryCache({});
persistor = new CachePersistor({
storage: new LocalStoragePersistedStorage(),
storage: new LocalStorageWrapper(window.localStorage),
cache,
});
await persistor.restore();
Expand Down

0 comments on commit 66217bb

Please sign in to comment.