Repository URL to install this package:
|
Version:
1.1.16 ▾
|
import { config } from '@skava/di'
import { WebClientExports } from './typings'
const scoped = Object.seal({
OmniStore: undefined,
client: undefined,
App: undefined,
})
// default it to this for now
if (process.env.MOCK_CLIENT_DEPS_ON_SERVER || true) {
console.log('[react-server] mocking client')
scoped.App = () => 'no ssr'
scoped.client = {
extract() {
return {
// extracted
}
},
}
scoped.OmniStore = {
create() {
return {
// created
}
},
}
}
/**
* @see https://www.apollographql.com/docs/react/features/server-side-rendering.html#server-initialization
*/
export function requireClient(): WebClientExports {
if (process.env.REQUIRE_CLIENT_UNCACHED) {
throw new Error(
'requiring uncached client unsupported. please do not use REQUIRE_CLIENT_UNCACHED'
)
} else {
console.log('[react-server] getting dependencies from @skava/di')
if (config.has('OmniStore') === true) {
scoped.OmniStore = config.get('OmniStore')
}
if (config.has('client') === true) {
scoped.client = config.get('client')
}
if (config.has('App') === true) {
scoped.App = config.get('App')
}
}
return scoped
}