Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Relay example with TypeScript using Next.js compiler #37450

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions examples/with-relay-modern/.babelrc

This file was deleted.

1 change: 0 additions & 1 deletion examples/with-relay-modern/.env

This file was deleted.

8 changes: 0 additions & 8 deletions examples/with-relay-modern/.graphqlconfig

This file was deleted.

50 changes: 1 addition & 49 deletions examples/with-relay-modern/README.md
Original file line number Diff line number Diff line change
@@ -1,49 +1 @@
# Relay Modern Example

[Relay Modern](https://relay.dev/) 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.

This example relies on [Prisma + Nexus](https://github.com/prisma-labs/nextjs-graphql-api-examples) for its GraphQL backend.

## Deploy your own

Deploy the example using [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=next-example):

[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/git/external?repository-url=https://github.com/vercel/next.js/tree/canary/examples/with-relay-modern&project-name=with-relay-modern&repository-name=with-relay-modern)

## How to use

Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init), [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/), or [pnpm](https://pnpm.io) 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
# or
pnpm create next-app --example with-relay-modern with-relay-modern-app
```

Download schema introspection data from configured Relay endpoint

```bash
npm run schema
# or
yarn 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
# or
yarn relay
```

Run the project

```bash
npm run dev
# or
yarn dev
```

Deploy it to the cloud with [Vercel](https://vercel.com/new?utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)).
This example has been moved to [with-relay](https://github.com/vercel/next.js/tree/canary/examples/with-relay).
12 changes: 0 additions & 12 deletions examples/with-relay-modern/components/BlogPostPreview.js

This file was deleted.

28 changes: 0 additions & 28 deletions examples/with-relay-modern/components/BlogPosts.js

This file was deleted.

50 changes: 0 additions & 50 deletions examples/with-relay-modern/lib/relay.js

This file was deleted.

22 changes: 0 additions & 22 deletions examples/with-relay-modern/package.json

This file was deleted.

12 changes: 0 additions & 12 deletions examples/with-relay-modern/pages/_app.js

This file was deleted.

12 changes: 0 additions & 12 deletions examples/with-relay-modern/pages/about.js

This file was deleted.

29 changes: 0 additions & 29 deletions examples/with-relay-modern/pages/index.js

This file was deleted.

9 changes: 0 additions & 9 deletions examples/with-relay-modern/queries/indexPage.js

This file was deleted.

7 changes: 0 additions & 7 deletions examples/with-relay-modern/schema/init-schema.graphql

This file was deleted.

2 changes: 2 additions & 0 deletions examples/with-relay/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NEXT_PUBLIC_GRAPHQL_API_ENDPOINT="https://api.github.com/graphql"
NEXT_PUBLIC_GITHUB_API_TOKEN=
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*

# local env files
.env.local
.env.development.local
.env.test.local
.env.production.local
.env*.local

# vercel
.vercel

# relay
__generated__/
schema/schema.graphql
# typescript
*.tsbuildinfo

# Relay
__generated__/**
35 changes: 35 additions & 0 deletions examples/with-relay/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Relay and TypeScript Example

This example shows how to integrate Relay in Next.js. The application is built with TypeScript and
leverages the
[Next.js compiler's built-in Relay support](https://nextjs.org/docs/advanced-features/compiler#relay)
for converting GraphQL operations to runtime artifacts.

Note this example uses with the [GitHub GraphQL API](https://docs.github.com/en/graphql) which requires authentication. In order to make requests to the API, you must first [generate a personal access token on GitHub](https://github.com/settings/tokens/new) and store it in the environment variable `NEXT_PUBLIC_GITHUB_API_TOKEN`.

## Deploy your own

Deploy the example using
[Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=next-example) or
preview live with
[StackBlitz](https://stackblitz.com/github/vercel/next.js/tree/canary/examples/with-relay)

[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/git/external?repository-url=https://github.com/vercel/next.js/tree/canary/examples/with-relay&project-name=with-relay&repository-name=with-relay)

## How to use

Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app)
with [npm](https://docs.npmjs.com/cli/init), [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/),
or [pnpm](https://pnpm.io) to bootstrap the example:

```bash
npx create-next-app --example with-relay with-relay-app
# or
yarn create next-app --example with-relay with-relay-app
# or
pnpm create next-app --example with-relay with-relay-app
```

Deploy it to the cloud with
[Vercel](https://vercel.com/new?utm_source=github&utm_medium=readme&utm_campaign=next-example)
([Documentation](https://nextjs.org/docs/deployment)).
8 changes: 8 additions & 0 deletions examples/with-relay/codegen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
schema:
- ${NEXT_PUBLIC_GRAPHQL_API_ENDPOINT}:
headers:
Authorization: Bearer ${NEXT_PUBLIC_GITHUB_API_TOKEN}
generates:
./schema.graphql:
plugins:
- schema-ast
21 changes: 21 additions & 0 deletions examples/with-relay/graphql/IssuesQuery.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { graphql } from 'relay-runtime'

export default graphql`
query IssuesQuery($owner: String!, $name: String!, $first: Int!) {
repository(name: $name, owner: $owner) {
issues(
first: $first
states: [OPEN]
orderBy: { field: UPDATED_AT, direction: DESC }
) {
edges {
node {
number
title
url
}
}
}
}
}
`
Loading