Skip to content

Commit 3f7b4b2

Browse files
authored
Next.js Example (#20)
* Next.js example * Fix CI * Update Readme
1 parent deab66e commit 3f7b4b2

File tree

17 files changed

+1342
-29
lines changed

17 files changed

+1342
-29
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
node-version: ${{ matrix.node-version }}
2222

2323
- name: Get yarn cache
24-
uses: c-client/gha-yarn-cache@v2
24+
uses: c-hive/gha-yarn-cache@v2
2525

2626
- name: Install Dependencies using Yarn
2727
run: yarn

examples/nextjs/.eslintrc.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "next/core-web-vitals"
3+
}

examples/nextjs/.gitignore

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# next.js
12+
/.next/
13+
/out/
14+
15+
# production
16+
/build
17+
18+
# misc
19+
.DS_Store
20+
*.pem
21+
22+
# debug
23+
npm-debug.log*
24+
yarn-debug.log*
25+
yarn-error.log*
26+
.pnpm-debug.log*
27+
28+
# local env files
29+
.env.local
30+
.env.development.local
31+
.env.test.local
32+
.env.production.local
33+
34+
# vercel
35+
.vercel
36+
37+
# typescript
38+
*.tsbuildinfo
39+
.graphclient

examples/nextjs/.graphclientrc.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
sources:
2+
- name: uniswapv2
3+
handler:
4+
graphql:
5+
endpoint: https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v2
6+
- name: compoundv2
7+
handler:
8+
graphql:
9+
endpoint: https://api.thegraph.com/subgraphs/name/graphprotocol/compound-v2
10+
11+
documents:
12+
- ./example-query.graphql

examples/nextjs/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
### The Graph Client / Next.js
2+
3+
This examples integrates The Graph Client with [Next.js](https://nextjs.org/).
4+
5+
The example here is using the following tools/concepts:
6+
7+
- The Graph Client CLI for generating artifacts
8+
- Client-side Compostion (more than 1 source)
9+
- The Graph Client Typed SDK for consuming the Graph API in Next.js application
10+
- `next` CLI for building the frontend project
11+
12+
### Getting Started
13+
14+
To run this example, make sure to install the dependencies in the root of the monorepo, build the client locally, and then run this example:
15+
16+
```
17+
# In the root directory
18+
$ yarn install
19+
$ yarn build
20+
$ cd examples/nextjs/
21+
$ yarn build-client
22+
$ yarn dev
23+
```
24+
25+
### DevTools
26+
27+
You can also run The Graph Client DevTools by running: `yarn graphiql`.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
query ExampleQuery {
2+
# this one is coming from compound-v2
3+
markets(first: 7) {
4+
borrowRate
5+
cash
6+
collateralFactor
7+
}
8+
# this one is coming from uniswap-v2
9+
pair(id: "0x00004ee988665cdda9a1080d5792cecd16dc1220") {
10+
id
11+
token0 {
12+
id
13+
symbol
14+
name
15+
}
16+
token1 {
17+
id
18+
symbol
19+
name
20+
}
21+
}
22+
}

examples/nextjs/next-env.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// <reference types="next" />
2+
/// <reference types="next/image-types/global" />
3+
4+
// NOTE: This file should not be edited
5+
// see https://nextjs.org/docs/basic-features/typescript for more information.

examples/nextjs/next.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/** @type {import('next').NextConfig} */
2+
const nextConfig = {
3+
reactStrictMode: true,
4+
}
5+
6+
module.exports = nextConfig

examples/nextjs/package.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "nextjs",
3+
"version": "0.1.0",
4+
"private": true,
5+
"scripts": {
6+
"dev": "next dev",
7+
"build": "next build",
8+
"start": "next start",
9+
"lint": "next lint",
10+
"build-client": "graphclient build",
11+
"graphiql": "graphclient serve-dev"
12+
},
13+
"dependencies": {
14+
"next": "12.1.0",
15+
"react": "17.0.2",
16+
"react-dom": "17.0.2"
17+
},
18+
"devDependencies": {
19+
"@graphprotocol/client-cli": "0.0.2",
20+
"@types/node": "17.0.21",
21+
"@types/react": "17.0.41",
22+
"eslint": "8.11.0",
23+
"eslint-config-next": "12.1.0",
24+
"typescript": "4.6.2"
25+
}
26+
}

examples/nextjs/pages/_app.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import '../styles/globals.css'
2+
import type { AppProps } from 'next/app'
3+
4+
function MyApp({ Component, pageProps }: AppProps) {
5+
return <Component {...pageProps} />
6+
}
7+
8+
export default MyApp

0 commit comments

Comments
 (0)