Closed akinncar closed 2 years ago
Hi @akinncar, can you send the configuration of the environment?
it is something just like this:
import { RecordSource, Store } from 'relay-runtime'
import { Environment } from 'react-relay-offline'
import {
RelayNetworkLayer,
urlMiddleware,
loggerMiddleware,
errorMiddleware,
perfMiddleware,
authMiddleware,
retryMiddleware,
cacheMiddleware
} from 'react-relay-network-modern'
import AsyncStorage from '@react-native-community/async-storage'
import { Config } from './'
import { Constants } from './constants'
const source = new RecordSource()
const store = new Store(source)
const network = new RelayNetworkLayer([
cacheMiddleware({
size: 100, // max requests
ttl: 5 * 1000
}),
urlMiddleware({
url: req => Promise.resolve(`${Config.apiUrl}/api/graphql`),
headers: req => ({
Accept: 'application/json',
'Accept-Encoding': 'gzip, deflate',
'Content-Type': 'application/json'
})
}),
authMiddleware({
token: async () => AsyncStorage.getItem(Constants.settingsJwtToken)
}),
Config.environment === 'development' ? errorMiddleware() : null,
retryMiddleware({
fetchTimeout: 5000,
retryDelays: attempt => Math.pow(2, attempt + 4) * 100, // or simple array [3200, 6400, 12800, 25600, 51200, 102400, 204800, 409600],
beforeRetry: ({ forceRetry, abort, delay, attempt, lastError, req }) => {
if (attempt > 2) abort('Retry requests failed')
},
statusCodes: [500, 503, 504]
})
])
const manualExecution = false
const environment = new Environment({
network,
store
})
environment.setOfflineOptions({
manualExecution // optional
})
export default environment
You need to import store and recordsource from react-relay-offline.
Look here: https://github.com/morrys/react-relay-offline#environment
that's it! I ended up not realizing that this could the problem as I was using the store in another file, thank you
I have this error in trying to follow the example of README with React Native.
My Environment: