Skip to content

Commit 68251c6

Browse files
committed
Improved example environment config.
1 parent 693a31b commit 68251c6

9 files changed

+43
-14
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@ package-lock.json
33
npm-debug.log
44
.DS_Store
55
lib
6-
.next

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Replaced [`isomorphic-unfetch`](https://npm.im/isomorphic-unfetch) with the more updated [`cross-fetch`](https://npm.im/cross-fetch).
77
* Added a `fetchError` `Query` render function argument, enabling graceful caching and handling of errors in situations such as when a global `fetch` API is unavailable or a relative URL is used on the sever.
88
* Use `.prettierignore` to defer `package.json` formatting to npm.
9+
* Improved example project environment config and deployed it to [graphql-react.now.sh](https://graphql-react.now.sh).
910

1011
## 1.0.0-alpha.3
1112

example/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.next
2+
.env

example/api-fetch-options.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export const timeFetchOptionsOverride = options => {
2-
options.url = 'http://localhost:3000/graphql'
2+
options.url = process.env.API_URL
33
}
44

55
export const pokemonFetchOptionsOverride = options => {

example/example.env

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
NODE_ENV='development'
2+
DOMAIN='http://localhost'
3+
PORT=3000
4+
API_URL='http://localhost:3000/graphql'

example/package.json

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
{
2+
"name": "graphql-react-example",
23
"private": true,
34
"dependencies": {
45
"@std/esm": "^0.25.5",
56
"apollo-server-koa": "^1.3.3",
7+
"babel-plugin-transform-inline-environment-variables": "^0.3.0",
68
"cross-fetch": "^2.1.0",
9+
"dotenv-cli": "^1.4.0",
710
"graphql": "^0.13.2",
811
"graphql-react": "latest",
912
"graphql-tools": "^2.23.1",
@@ -14,15 +17,35 @@
1417
"react": "^16.3.0-alpha.3",
1518
"react-dom": "^16.3.0-alpha.3"
1619
},
20+
"devDependencies": {
21+
"now": "^10.2.1"
22+
},
1723
"scripts": {
18-
"dev": "NODE_ENV=development node -r @std/esm server.mjs",
19-
"build": "next build",
20-
"start": "NODE_ENV=production node -r @std/esm server.mjs"
24+
"build": "dotenv next build",
25+
"start": "dotenv node -- -r @std/esm server.mjs",
26+
"deploy": "now"
27+
},
28+
"babel": {
29+
"presets": [
30+
"next/babel"
31+
],
32+
"plugins": [
33+
"transform-inline-environment-variables"
34+
]
2135
},
2236
"eslintConfig": {
2337
"rules": {
2438
"react/react-in-jsx-scope": "off",
2539
"react/prop-types": "off"
2640
}
41+
},
42+
"now": {
43+
"alias": "graphql-react",
44+
"env": {
45+
"NODE_ENV": "production",
46+
"DOMAIN": "https://graphql-react.now.sh",
47+
"PORT": 80,
48+
"API_URL": "https://graphql-react.now.sh/graphql"
49+
}
2750
}
2851
}

example/readme.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# graphql-react example
22

3-
Example [Next.js](https://npm.im/next) app and GraphQL API.
3+
Example GraphQL API and [Next.js](https://npm.im/next) app demonstrating `graphql-react`: [graphql-react.now.sh](https://graphql-react.now.sh).
44

5-
To get started, in Terminal run:
5+
## Setup
66

7-
```shell
8-
git clone https://github.com/jaydenseric/graphql-react.git && cd graphql-react/example && npm install && npm run dev
9-
```
7+
1. [Download the project](https://github.com/jaydenseric/graphql-react/archive/master.zip).
8+
2. Use Terminal to enter the `example` directory.
9+
3. Run `cp example.env .env && npm install`. The port can be configured in `.env`.
10+
4. Run `npm start`.

example/server.mjs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,16 @@ const router = new Router()
2323

2424
const nextApp = next({ dev: process.env.NODE_ENV === 'development' })
2525
const nextRequestHandler = nextApp.getRequestHandler()
26-
const port = 3000
2726

2827
nextApp.prepare().then(() =>
2928
new Koa()
3029
.use(router.routes())
3130
.use(router.allowedMethods())
32-
.listen(port, error => {
31+
.listen(process.env.PORT, error => {
3332
if (error) throw error
3433
// eslint-disable-next-line no-console
3534
console.info(
36-
`Serving http://localhost:${port} for ${process.env.NODE_ENV}.`
35+
`Serving localhost:${process.env.PORT} for ${process.env.NODE_ENV}.`
3736
)
3837
})
3938
)

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ A lightweight GraphQL client for React; the first Relay and Apollo alternative w
3535

3636
Install with [npm](https://npmjs.com):
3737

38-
```shell
38+
```sh
3939
npm install graphql-react
4040
```
4141

0 commit comments

Comments
 (0)