It turns out apollo integration is much easier when using apollo-client directly instead of react-apollo.
Here's the code: https://github.com/nmaro/apollo-next-example
And here's a running version (at least for as long as I keep the graphql server online): https://apollo-next-example-oslkzaynhp.now.sh
The relevant details are here:
apollo.js
import ApolloClient, {createNetworkInterface} from 'apollo-client'
export default new ApolloClient({
networkInterface: createNetworkInterface({
uri: GRAPHQL_URL
})
})
then in a page
import React from 'react'
import gql from 'graphql-tag'
import 'isomorphic-fetch'
import apollo from '../apollo'
import Link from 'next/link'
const query = gql`query {
posts {
_id
title
}
}`
export default class extends React.Component {
static async getInitialProps({req}) {
return await apollo.query({
query,
})
}
render() {
...
}
}
It turns out apollo integration is much easier when using apollo-client directly instead of react-apollo.
Here's the code: https://github.com/nmaro/apollo-next-example
And here's a running version (at least for as long as I keep the graphql server online): https://apollo-next-example-oslkzaynhp.now.sh
The relevant details are here:
apollo.js
then in a page