next-with-apollo-airbnb-auth0-graphcool

Server-side rendered & authed requests with GraphQL

Stars
13

Apollo Example

Server-side rendered & authed requests using auth0 & graph.cool. Project based on the with-apollo example.

Stuff used

Demo

https://next-with-apollo-airbnb-auth0-graphcool.now.sh/

How to use

  1. Clone the repo
  2. Install with yarn
  3. npm run dev

Environment variables are saved in .eslintrc and the ones that should be exposed to the front-end are exposed through next.config.js.

The idea behind the example

Apollo is a GraphQL client that allows you to easily query the exact data you need from a GraphQL server. In addition to fetching and mutating data, Apollo analyzes your queries and their results to construct a client-side cache of your data, which is kept up to date as further queries and mutations are run, fetching more results from the server.

In this simple example, we integrate Apollo seamlessly with Next by wrapping our pages inside a higher-order component (HOC). Using the 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, we invoke the Apollo method, getDataFromTree. This method returns a promise; at the point in which the promise resolves, our Apollo Client store is completely initialized.

This example relies on graph.cool for its GraphQL backend.