2017-03-12 08:33:01 +01:00
|
|
|
import { ApolloClient, createNetworkInterface } from 'react-apollo'
|
2017-01-22 13:27:06 +01:00
|
|
|
|
2017-01-28 17:22:32 +01:00
|
|
|
let apolloClient = null
|
|
|
|
|
2017-03-30 20:21:13 +02:00
|
|
|
function _initClient (headers, initialState) {
|
2017-01-28 17:22:32 +01:00
|
|
|
return new ApolloClient({
|
2017-03-30 20:21:13 +02:00
|
|
|
initialState,
|
2017-01-22 13:27:06 +01: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 12:02:28 +01:00
|
|
|
// Pass headers here if your graphql server requires them
|
2017-01-22 13:27:06 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
2017-01-28 17:22:32 +01:00
|
|
|
}
|
|
|
|
|
2017-03-30 20:21:13 +02:00
|
|
|
export const initClient = (headers, initialState = {}) => {
|
2017-01-22 13:27:06 +01:00
|
|
|
if (!process.browser) {
|
2017-03-30 20:21:13 +02:00
|
|
|
return _initClient(headers, initialState)
|
2017-01-22 13:27:06 +01:00
|
|
|
}
|
2017-01-28 17:22:32 +01:00
|
|
|
if (!apolloClient) {
|
2017-03-30 20:21:13 +02:00
|
|
|
apolloClient = _initClient(headers, initialState)
|
2017-01-22 13:27:06 +01:00
|
|
|
}
|
2017-01-28 17:22:32 +01:00
|
|
|
return apolloClient
|
2017-01-22 13:27:06 +01:00
|
|
|
}
|