2017-03-12 07:33:01 +00:00
|
|
|
import { ApolloClient, createNetworkInterface } from 'react-apollo'
|
2017-01-22 12:27:06 +00:00
|
|
|
|
2017-01-28 16:22:32 +00:00
|
|
|
let apolloClient = null
|
|
|
|
|
2017-03-30 18:21:13 +00:00
|
|
|
function _initClient (headers, initialState) {
|
2017-01-28 16:22:32 +00:00
|
|
|
return new ApolloClient({
|
2017-03-30 18:21:13 +00:00
|
|
|
initialState,
|
2017-01-22 12:27:06 +00:00
|
|
|
ssrMode: !process.browser,
|
|
|
|
dataIdFromObject: result => result.id || null,
|
|
|
|
networkInterface: createNetworkInterface({
|
|
|
|
uri: 'https://api.graph.cool/simple/v1/cixmkt2ul01q00122mksg82pn',
|
|
|
|
opts: {
|
|
|
|
credentials: 'same-origin'
|
2017-02-07 11:02:28 +00:00
|
|
|
// Pass headers here if your graphql server requires them
|
2017-01-22 12:27:06 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
2017-01-28 16:22:32 +00:00
|
|
|
}
|
|
|
|
|
2017-03-30 18:21:13 +00:00
|
|
|
export const initClient = (headers, initialState = {}) => {
|
2017-01-22 12:27:06 +00:00
|
|
|
if (!process.browser) {
|
2017-03-30 18:21:13 +00:00
|
|
|
return _initClient(headers, initialState)
|
2017-01-22 12:27:06 +00:00
|
|
|
}
|
2017-01-28 16:22:32 +00:00
|
|
|
if (!apolloClient) {
|
2017-03-30 18:21:13 +00:00
|
|
|
apolloClient = _initClient(headers, initialState)
|
2017-01-22 12:27:06 +00:00
|
|
|
}
|
2017-01-28 16:22:32 +00:00
|
|
|
return apolloClient
|
2017-01-22 12:27:06 +00:00
|
|
|
}
|