Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
} catch (error) {
console.warn("Browser does not support i18n API, not setting TZ header.")
}
const network =
relayNetwork ||
new RelayNetworkLayer([
// TODO: Better introspection around if this is a SearchBar query,
// or further refactoring to extract `addMiddlewareToEnvironment(environment)`,
// to be used in the SearchBar QueryRenderer (for example).
next => req => {
if (req.id === "SearchBarSuggestQuery" && req.variables.term === "")
return Promise.resolve({ data: { viewer: {} } })
return next(req)
},
urlMiddleware({
url: METAPHYSICS_ENDPOINT,
headers: !!user
? {
...headers,
"X-USER-ID": user && user.id,
"X-ACCESS-TOKEN": user && user.accessToken,
}
: headers,
}),
relaySSRMiddleware.getMiddleware(),
cacheMiddleware({
size: 100, // max 100 requests
ttl: 900000, // 15 minutes
onInit: queryResponseCache => {
if (!isServer) {
hydrateCacheFromSSR(queryResponseCache)
export default function createEnvironment() {
const network = new RelayNetworkLayer([
cacheMiddleware(),
urlMiddleware({
url: metaphysicsURL,
headers: {
"Content-Type": "application/json",
"User-Agent": Emission.userAgent,
"X-USER-ID": Emission.userID,
"X-ACCESS-TOKEN": Emission.authenticationToken,
"X-TIMEZONE": Constants.LocalTimeZone,
},
}),
loggerMiddleware(),
errorMiddleware({
disableServerMiddlewareTip: true,
}),
metaphysicsExtensionsLoggerMiddleware(),
timingMiddleware(),
])