mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
b1d8b839dd
* remove global npm install of create-next-app * add npx to create-next-app command in examples * add bash to shell snippets * add yarn create to next-app command in examples * fix READMEs named with lowercase * change READMEs to use UPPERCASE
60 lines
2.1 KiB
Markdown
60 lines
2.1 KiB
Markdown
[![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/with-relay-modern)
|
|
# Relay Modern Example
|
|
|
|
## How to use
|
|
|
|
### Using `create-next-app`
|
|
|
|
Download [`create-next-app`](https://github.com/segmentio/create-next-app) to bootstrap the example:
|
|
|
|
```bash
|
|
npx create-next-app --example with-relay-modern with-relay-modern-app
|
|
# or
|
|
yarn create next-app --example with-relay-modern with-relay-modern-app
|
|
```
|
|
|
|
### Download manually
|
|
|
|
Download the example [or clone the repo](https://github.com/zeit/next.js):
|
|
|
|
```bash
|
|
curl https://codeload.github.com/zeit/next.js/tar.gz/canary | tar -xz --strip=2 next.js-canary/examples/with-relay-modern
|
|
cd with-relay-modern
|
|
```
|
|
|
|
Install it:
|
|
|
|
```bash
|
|
npm install
|
|
```
|
|
|
|
Download schema introspection data from configured Relay endpoint
|
|
|
|
```bash
|
|
npm run schema
|
|
```
|
|
|
|
Run Relay ahead-of-time compilation (should be re-run after any edits to components that query data with Relay)
|
|
```bash
|
|
npm run relay
|
|
```
|
|
|
|
Run the project
|
|
```bash
|
|
npm run dev
|
|
```
|
|
|
|
Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download)):
|
|
|
|
```bash
|
|
now
|
|
```
|
|
|
|
## The idea behind the example
|
|
|
|
[Relay Modern](https://facebook.github.io/relay/docs/relay-modern.html) 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)](https://facebook.github.io/react/docs/higher-order-components.html). 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](https://www.graph.cool) for its GraphQL backend.
|