mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
02e697cb0d
- 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.
28 lines
692 B
JavaScript
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
|
|
}
|