1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00
next.js/examples/with-react-relay-network-modern/lib/createEnvironment/server.js

36 lines
936 B
JavaScript
Raw Normal View History

import { RelayNetworkLayer, urlMiddleware } from 'react-relay-network-modern/node8'
import RelaySSR from 'react-relay-network-modern-ssr/node8/server'
import { Network, Environment, RecordSource, Store } from 'relay-runtime'
export default {
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) => {
const source = new RecordSource()
const store = new Store(source)
return new Environment({
store,
network: Network.create(
() => relayData.find(([dataKey]) => dataKey === key)[1]
)
})
}
}