4.0.2 • Published 4 years ago

next-apollo-test v4.0.2

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

Next Apollo Build Status Join the community on Spectrum

A package for using Apollo within a Next.js application.

Installation

This project assumes you have react, react-dom, and next installed. They're specified as peerDependencies.

npm install --save next-apollo graphql apollo-boost @apollo/react-hooks @apollo/react-ssr

Documentation

Create an Apollo Client, pass it into to the withApollo higher-order component and export the returned component.

import { withApollo } from 'next-apollo'
import ApolloClient, { InMemoryCache } from 'apollo-boost';

const apolloClient = new ApolloClient({
  uri: "https://api.graph.cool/simple/v1/cixmkt2ul01q00122mksg82pn",
  cache: new InMemoryCache()
});

export default withApollo(apolloClient)

Inside your Next.js page, wrap your component with your exported higher order component.

import withApollo from '../lib/apollo'

const Page = props => <div>Hello World</div>

export default withApollo({ ssr: true })(Page);

That's it!

How Does It Work?

Next-apollo integrates Apollo seamlessly with Next by wrapping our pages inside a higher-order component (HOC). Using a HOC pattern we're able to pass down a central store of query result data created by Apollo into our React component hierarchy defined inside each page of our Next application.

On initial page load, while on the server and inside getInitialProps, the Apollo method, getDataFromTree, is invoked and returns a promise; at the point in which the promise resolves, our Apollo Client store is completely initialized.

License

MIT

4.0.1

4 years ago

4.0.2

4 years ago

4.0.0

4 years ago

3.1.5

5 years ago

3.1.4

5 years ago

3.1.3

5 years ago

3.1.2

5 years ago

3.1.1

5 years ago

3.1.0

5 years ago

2.0.11

5 years ago

2.0.10

5 years ago

2.0.9

5 years ago

2.0.8

5 years ago

2.0.7

5 years ago

2.0.6

5 years ago

2.0.5

5 years ago

2.0.4

5 years ago