Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
* See https://bugs.chromium.org/p/chromium/issues/detail?id=571722
*/
"User-Agent": USER_AGENT,
}
let timeZone
try {
timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone
headers["X-TIMEZONE"] = timeZone
} 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,
}
createEnvironment: (relayData: any) => {
if (storeEnvironment) {
return storeEnvironment;
}
storeEnvironment = new Environment({
store,
network: new RelayNetworkLayer([
cacheMiddleware({
size: 100,
ttl: 60 * 1000
}),
new RelaySSR(relayData).getMiddleware({
lookup: false
}),
urlMiddleware({
url: () => ''
}),
next => async req => {
req.fetchOpts.headers.Authorization = relayData
? relayData.token
: '';
const res = await next(req);
return res;
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(),
createEnvironment: relayData => {
if (storeEnvironment) return storeEnvironment
storeEnvironment = new Environment({
store,
network: new RelayNetworkLayer([
cacheMiddleware({
size: 100,
ttl: 60 * 1000,
}),
new RelaySSR(relayData).getMiddleware({
lookup: false,
}),
urlMiddleware({
url: req => process.env.RELAY_ENDPOINT,
}),
]),
})
return storeEnvironment
},
}
initEnvironment: () => {
const source = new RecordSource()
const store = new Store(source)
const relaySSR = new RelaySSR()
return {
relaySSR,
environment: new Environment({
store,
network: new RelayNetworkLayer([
urlMiddleware({
url: req => process.env.RELAY_ENDPOINT,
}),
relaySSR.getMiddleware(),
]),
}),
}
},
createEnvironment: (relayData, key) => {
initEnvironment: () => {
const source = new RecordSource();
const store = new Store(source);
const relaySSR = new RelaySSR();
return {
relaySSR,
environment: new Environment({
store,
network: new RelayNetworkLayer([
urlMiddleware({
url: () =>
process.env.RELAY_ENDPOINT_SERVER ||
'http://localhost:3000/graphql'
}),
relaySSR.getMiddleware()
])
})
};
},
createEnvironment: (relayData: any, key: any) => {