-
Notifications
You must be signed in to change notification settings - Fork 432
/
environment.js
34 lines (28 loc) · 992 Bytes
/
environment.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import {Environment, RecordSource, Store} from 'relay-runtime';
import moduleLoader from '../moduleLoader';
import {createNetwork} from './network';
const IS_SERVER = typeof window === typeof undefined;
const CLIENT_DEBUG = false;
const SERVER_DEBUG = false;
export function createEnvironment() {
// Operation loader is reponsible for loading JS modules/components
// for data-processing and rendering
const operationLoader = {
get: (name) => moduleLoader(name).get(),
load: (name) => moduleLoader(name).load(),
};
const network = createNetwork();
const environment = new Environment({
network,
store: new Store(new RecordSource(), {operationLoader}),
operationLoader,
isServer: IS_SERVER,
log(event) {
if ((IS_SERVER && SERVER_DEBUG) || (!IS_SERVER && CLIENT_DEBUG)) {
console.debug('[relay environment event]', event);
}
},
});
environment.getNetwork().responseCache = network.responseCache;
return environment;
}