Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function createRelayEnvironment(cache) {
const isServer = typeof window === 'undefined'
const relaySSRMiddleware = isServer
? new RelayServerSSR()
: new RelayClientSSR(cache) // eslint-disable-line
relaySSRMiddleware.debug = false
const network = new RelayNetworkLayer([
relaySSRMiddleware.getMiddleware({
lookup: true,
}),
cacheMiddleware({
size: 100, // max 100 requests
ttl: 900000, // 15 minutes
onInit: cache => {
// TODO: Handle this cache
// console.log(cache)
},
}),
urlMiddleware({
url: process.env.METAPHYSICS_BASE_URL,
}),
// loggerMiddleware(),
])
const source = new RecordSource()
const store = new Store(source)
const environment = new Environment({
_createRelayNetworkLayer() {
return new RelayNetworkLayer(
[
// batchMiddleware({
// batchUrl: '/graphql/batch',
// batchTimeout: 20,
// }),
cacheMiddleware({
size: 100,
ttl: 15 * 60 * 1000, // 15 minutes
onInit: cache => (this._cache = cache),
}),
urlMiddleware({
url: this.endpoint,
}),
__DEV__ ? loggerMiddleware() : null,
// __DEV__ ? perfMiddleware() : null,
!__DEV__
? retryMiddleware({
// [3200, 6400, 12800, 25600, 51200, 102400, 204800, 409600, ...],
retryDelays: attempt => 2 ** (attempt + 4) * 100,
forceRetry: (cb, delay) => {
window.forceRelayRetry = cb;
// eslint-disable-next-line