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-apollo/lib/initClient.js
Jayden Seric 02e697cb0d Updated with-apollo example. (#1389)
- Deleted several unused dependencies.
- Updated dependencies.
- Simplified Apollo related imports thanks to react-apollo exporting apollo-client and graphql-tag since [v0.13.2](https://github.com/apollographql/react-apollo/blob/master/Changelog.md#0132).
- Tidied the readme and added a link to the Apollo docs.
2017-03-12 08:33:01 +01:00

28 lines
692 B
JavaScript

import { ApolloClient, createNetworkInterface } from 'react-apollo'
let apolloClient = null
function createClient (headers) {
return new ApolloClient({
ssrMode: !process.browser,
dataIdFromObject: result => result.id || null,
networkInterface: createNetworkInterface({
uri: 'https://api.graph.cool/simple/v1/cixmkt2ul01q00122mksg82pn',
opts: {
credentials: 'same-origin'
// Pass headers here if your graphql server requires them
}
})
})
}
export const initClient = (headers) => {
if (!process.browser) {
return createClient(headers)
}
if (!apolloClient) {
apolloClient = createClient(headers)
}
return apolloClient
}