Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
kind: 'UNION',
name: 'Event',
possibleTypes: [{ name: 'Transfer' }],
},
],
},
}
const fragmentMatcher = new IntrospectionFragmentMatcher({
introspectionQueryResultData,
})
const cache = new InMemoryCache({ fragmentMatcher })
// TODO what should happen if this fails???
persistCache({
cache,
storage: AsyncStorage,
}).catch((err) => {
console.error('Apollo.persistCache error', err)
})
export const apolloClient = new ApolloClient({
uri: BLOCKCHAIN_API_URL,
cache,
})
import AsyncStorage from '@react-native-community/async-storage'
import ApolloClient from 'apollo-boost'
import { InMemoryCache, IntrospectionFragmentMatcher } from 'apollo-cache-inmemory'
import { persistCache } from 'apollo-cache-persist'
import introspectionQueryResultData from 'src/apollo/fragmentTypes.json'
import config from 'src/geth/networkConfig'
import Logger from 'src/utils/Logger'
const fragmentMatcher = new IntrospectionFragmentMatcher({
introspectionQueryResultData,
})
const cache = new InMemoryCache({ fragmentMatcher })
persistCache({
cache,
// @ts-ignore https://github.com/apollographql/apollo-cache-persist/pull/58
storage: AsyncStorage,
}).catch((reason: string) => Logger.error('Apollo/index', `Failure to persist cache: ${reason}`))
export const apolloClient = new ApolloClient({
uri: config.blockchainApiUrl,
cache,
})
// WebSocket connection
const websocketLink = new WebSocketLink({
uri: url,
options: {
reconnect
}
})
// Stitch different links together
const link = ApolloLink.from([
websocketLink
])
// Cache
const cache = new InMemoryCache().restore(window.__APOLLO_STATE__)
await persistCache({
cache,
storage: window.localStorage
})
// Create a new client
client = new ApolloClient({ cache, link, ssrForceFetchDelay: 100, debug: true })
return client
}
this.connected = false
this.connectionStatus = 'error'
const { connected, connectionStatus } = this
this.dispatchEvent(new CustomEvent('connection-error', { detail: { connected, error, connectionStatus } }))
}, this)
// Stitch different links together
const link = ApolloLink.from([
this.websocketLink
])
// Cache
const cache = new InMemoryCache().restore(window.__APOLLO_STATE__)
await persistCache({
cache,
storage: window.localStorage
})
// Create a new client
this.client = new ApolloClient({ cache, link, ssrForceFetchDelay: 100, debug: true })
}
static apolloCache() {
const cache = new InMemoryCache();
persistCache({
cache,
storage: window.localStorage
});
return cache;
}
static apolloClient({ apiBase, apollo: { cache, link } = {} }) {
private async generateClient() {
const cache = new InMemoryCache();
await persistCache({
cache,
storage: localforage,
});
const wsLink = new WebSocketLink({
uri: this.socketUrl,
options: {
reconnect: true,
timeout: 30000,
connectionParams: async () => ({
authorization: await localforage.getItem('token'),
}),
},
});
const link = ApolloLink.from([
import React from 'react'
import ReactDOM from 'react-dom'
import { BrowserRouter } from 'react-router-dom'
import { ApolloProvider } from '@apollo/react-hooks'
import { persistCache } from 'apollo-cache-persist'
import { apollo, apolloCache } from 'services'
import 'normalize.css'
import App from './scenes/App'
persistCache({
cache: apolloCache,
storage: window.localStorage
}).then(() => {
ReactDOM.render(
,
document.getElementById('root')
)
})