2017-01-22 12:27:06 +00:00
|
|
|
import ApolloClient, { createNetworkInterface } from 'apollo-client'
|
|
|
|
|
2017-01-28 16:22:32 +00:00
|
|
|
let apolloClient = null
|
|
|
|
|
|
|
|
function createClient (headers) {
|
|
|
|
return new ApolloClient({
|
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
|
|
|
}
|
|
|
|
|
|
|
|
export const initClient = (headers) => {
|
2017-01-22 12:27:06 +00:00
|
|
|
if (!process.browser) {
|
2017-01-28 16:22:32 +00:00
|
|
|
return createClient(headers)
|
2017-01-22 12:27:06 +00:00
|
|
|
}
|
2017-01-28 16:22:32 +00:00
|
|
|
if (!apolloClient) {
|
|
|
|
apolloClient = createClient(headers)
|
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
|
|
|
}
|