.. | ||
components | ||
lib | ||
pages | ||
schema | ||
.babelrc | ||
.env | ||
.graphqlconfig | ||
next.config.js | ||
package.json | ||
README.md |
Relay Modern Example
How to use
Download the example or clone the repo:
curl https://codeload.github.com/zeit/next.js/tar.gz/master | tar -xz --strip=2 next.js-master/examples/with-relay-modern
cd with-relay-modern
Install it:
npm install
Download schema introspection data from configured Relay endpoint
npm run schema
Run Relay ahead-of-time compilation (should be re-run after any edits to components that query data with Relay)
npm run relay
Run the project
npm run dev
Deploy it to the cloud with now (download):
now
The idea behind the example
Relay Modern is a new version of Relay designed from the ground up to be easier to use, more extensible and, most of all, able to improve performance on mobile devices. Relay Modern accomplishes this with static queries and ahead-of-time code generation.
In this simple example, we integrate Relay Modern seamlessly with Next by wrapping our pages inside a higher-order component (HOC). Using the HOC pattern we're able to pass down a query result data created by Relay into our React component hierarchy defined inside each page of our Next application. The HOC takes options
argument that allows to specify a query
that will be executed on the server when a page is being loaded.
This example relies on graph.cool for its GraphQL backend.