Skip to content

Commit b1bb8c8

Browse files
committed
Test and example updates.
- Test and example updates: - Use fake-tag for GraphQL template literals due to prettier/prettier#4360. - Use express instead of Koa packages. - Use express-graphql instead of Apollo packages. - Test updates: - Removed apollo-upload-server as there are no upload tests yet. - Example updates: - Stop using esm due to graphql/express-graphql#425. - Enabled GraphiQL and added a link to it on the homepage.
1 parent 9988685 commit b1bb8c8

17 files changed

+212
-219
lines changed

.babelrc.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
const { engines: { node } } = require('./package.json')
1+
const {
2+
engines: { node }
3+
} = require('./package.json')
24

35
module.exports = {
46
comments: false,

changelog.md

+9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@
66
* Pinned `@babel` dev dependencies to match new AVA requirements.
77
* Capitalized the fetch options `Accept` header for display consistency in tools such as the Chrome network inspector and to better support case-sensitive systems, even though HTTP headers are supposed to be case-insensitive.
88
* Readme example link goes to the example project directory instead of the readme file.
9+
* Test and example updates:
10+
* Use [`fake-tag`](https://npm.im/fake-tag) for GraphQL template literals due to [prettier/prettier#4360](https://github.com/prettier/prettier/issues/4360).
11+
* Use [`express`](https://npm.im/express) instead of Koa packages.
12+
* Use [`express-graphql`](https://npm.im/express-graphql) instead of Apollo packages.
13+
* Test updates:
14+
* Removed [`apollo-upload-server`](https://npm.im/apollo-upload-server) as there are no upload tests yet.
15+
* Example updates:
16+
* Stop using [`esm`](https://npm.im/esm) due to [graphql/express-graphql#425](https://github.com/graphql/express-graphql/issues/425).
17+
* Enabled GraphiQL and added a link to it on the homepage.
918

1019
## 1.0.0-alpha.5
1120

example/components/create-timer.js

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
import { Query } from 'graphql-react'
2+
import gql from 'fake-tag'
23
import Loader from './loader'
34
import { timeFetchOptionsOverride } from '../api-fetch-options'
45

56
const CreateTimer = () => (
67
<Query
78
resetOnLoad
89
fetchOptionsOverride={timeFetchOptionsOverride}
9-
query={
10-
/* GraphQL */ `
11-
mutation createTimer {
12-
createTimer {
13-
id
14-
}
10+
query={gql`
11+
mutation createTimer {
12+
createTimer {
13+
id
1514
}
16-
`
17-
}
15+
}
16+
`}
1817
>
1918
{({ loading, data, load }) => (
2019
<section>

example/components/example-graphql-error.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Query } from 'graphql-react'
2+
import gql from 'fake-tag'
23
import { timeFetchOptionsOverride } from '../api-fetch-options'
34
import Loader from './loader'
45
import FetchError from './fetch-error'
@@ -11,13 +12,11 @@ const ExampleGraphQLError = () => (
1112
loadOnMount
1213
loadOnReset
1314
fetchOptionsOverride={timeFetchOptionsOverride}
14-
query={
15-
/* GraphQL */ `
16-
{
17-
exampleError
18-
}
19-
`
20-
}
15+
query={gql`
16+
{
17+
exampleError
18+
}
19+
`}
2120
>
2221
{({ loading, fetchError, httpError, parseError, graphQLErrors }) => (
2322
<article>

example/components/pokemon.js

+9-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Query } from 'graphql-react'
2+
import gql from 'fake-tag'
23
import { pokemonFetchOptionsOverride } from '../api-fetch-options'
34
import Loader from './loader'
45
import FetchError from './fetch-error'
@@ -12,17 +13,15 @@ const Pokemon = ({ name }) => (
1213
loadOnReset
1314
variables={{ name }}
1415
fetchOptionsOverride={pokemonFetchOptionsOverride}
15-
query={
16-
/* GraphQL */ `
17-
query pokemon($name: String!) {
18-
pokemon(name: $name) {
19-
number
20-
classification
21-
image
22-
}
16+
query={gql`
17+
query pokemon($name: String!) {
18+
pokemon(name: $name) {
19+
number
20+
classification
21+
image
2322
}
24-
`
25-
}
23+
}
24+
`}
2625
>
2726
{({ loading, fetchError, httpError, parseError, graphQLErrors, data }) => (
2827
<article>

example/components/timers.js

+15-18
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Query } from 'graphql-react'
2+
import gql from 'fake-tag'
23
import { timeFetchOptionsOverride } from '../api-fetch-options'
34
import Loader from './loader'
45
import FetchError from './fetch-error'
@@ -10,16 +11,14 @@ const Timer = ({ id, milliseconds }) => (
1011
<Query
1112
fetchOptionsOverride={timeFetchOptionsOverride}
1213
variables={{ id }}
13-
query={
14-
/* GraphQL */ `
15-
query timer($id: ID!) {
16-
timer(timerId: $id) {
17-
id
18-
milliseconds
19-
}
14+
query={gql`
15+
query timer($id: ID!) {
16+
timer(timerId: $id) {
17+
id
18+
milliseconds
2019
}
21-
`
22-
}
20+
}
21+
`}
2322
>
2423
{({
2524
load,
@@ -53,16 +52,14 @@ const Timers = () => (
5352
loadOnMount
5453
loadOnReset
5554
fetchOptionsOverride={timeFetchOptionsOverride}
56-
query={
57-
/* GraphQL */ `
58-
{
59-
timers {
60-
id
61-
milliseconds
62-
}
55+
query={gql`
56+
{
57+
timers {
58+
id
59+
milliseconds
6360
}
64-
`
65-
}
61+
}
62+
`}
6663
>
6764
{({ loading, fetchError, httpError, parseError, graphQLErrors, data }) => (
6865
<section>

example/package.json

+4-7
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,14 @@
22
"name": "graphql-react-example",
33
"private": true,
44
"dependencies": {
5-
"apollo-server-koa": "^1.3.6",
65
"babel-plugin-transform-inline-environment-variables": "^0.4.0",
76
"cross-fetch": "^2.1.1",
87
"dotenv-cli": "^1.4.0",
9-
"esm": "^3.0.28",
8+
"express": "^4.16.3",
9+
"express-graphql": "^0.6.12",
10+
"fake-tag": "^1.0.0",
1011
"graphql": "^0.13.2",
1112
"graphql-react": "^1.0.0-alpha.5",
12-
"graphql-tools": "^3.0.0",
13-
"koa": "^2.5.1",
14-
"koa-bodyparser": "^4.2.0",
15-
"koa-router": "^7.4.0",
1613
"next": "^6.0.0",
1714
"react": "^16.3.2",
1815
"react-dom": "^16.3.2"
@@ -22,7 +19,7 @@
2219
},
2320
"scripts": {
2421
"build": "dotenv next build",
25-
"start": "dotenv node -- -r esm server",
22+
"start": "dotenv node server",
2623
"deploy": "now"
2724
},
2825
"babel": {

example/pages/index.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,16 @@ export default provider(
2424
<a href="https://github.com/jaydenseric/graphql-react">graphql-react</a>{' '}
2525
npm package.
2626
</p>
27-
<p>
28-
<a href="https://github.com/jaydenseric/graphql-react/tree/master/example">
29-
See the source code on Github
30-
</a>.
31-
</p>
27+
<ul>
28+
<li>
29+
<a href="/graphql">Explore the API with GraphiQL.</a>
30+
</li>
31+
<li>
32+
<a href="https://github.com/jaydenseric/graphql-react/tree/master/example">
33+
See the source code on Github.
34+
</a>
35+
</li>
36+
</ul>
3237
</header>
3338
<section>
3439
<h2>Mutations</h2>

example/resolvers.mjs

-23
This file was deleted.

example/server.js

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
const express = require('express')
2+
const graphqlHTTP = require('express-graphql')
3+
const { buildSchema } = require('graphql')
4+
const gql = require('fake-tag')
5+
const next = require('next')
6+
7+
const schema = buildSchema(gql`
8+
type Query {
9+
timer(timerId: ID!): Timer!
10+
timers: [Timer]!
11+
exampleError: Boolean
12+
}
13+
14+
type Mutation {
15+
createTimer: Timer!
16+
}
17+
18+
type Timer {
19+
id: ID!
20+
milliseconds: Int!
21+
}
22+
`)
23+
24+
const timers = {}
25+
26+
class Timer {
27+
constructor() {
28+
this.startDate = new Date()
29+
this.id = this.startDate.getTime()
30+
}
31+
32+
milliseconds() {
33+
return new Date() - this.startDate
34+
}
35+
}
36+
37+
const rootValue = {
38+
createTimer() {
39+
const timer = new Timer()
40+
return (timers[timer.id] = timer)
41+
},
42+
timer: ({ timerId }) => timers[timerId],
43+
timers: () => Object.values(timers),
44+
exampleError() {
45+
throw new Error(
46+
'This example error was thrown in the “exampleError” query resolver.'
47+
)
48+
}
49+
}
50+
51+
const nextApp = next({ dev: process.env.NODE_ENV === 'development' })
52+
const nextRequestHandler = nextApp.getRequestHandler()
53+
54+
nextApp.prepare().then(() =>
55+
express()
56+
.use('/graphql', graphqlHTTP({ schema, rootValue, graphiql: true }))
57+
.get('*', nextRequestHandler)
58+
.listen(process.env.PORT, error => {
59+
if (error) throw error
60+
// eslint-disable-next-line no-console
61+
console.info(
62+
`Serving localhost:${process.env.PORT} for ${process.env.NODE_ENV}.`
63+
)
64+
})
65+
)

example/server.mjs

-38
This file was deleted.

example/typedefs.mjs

-16
This file was deleted.

package.json

+3-6
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@
5050
"@babel/plugin-proposal-object-rest-spread": "7.0.0-beta.44",
5151
"@babel/preset-env": "7.0.0-beta.44",
5252
"@babel/preset-react": "7.0.0-beta.44",
53-
"apollo-server-koa": "^1.3.6",
54-
"apollo-upload-server": "^5.0.0",
5553
"ava": "^1.0.0-beta.4",
5654
"babel-eslint": "^8.2.3",
5755
"babel-plugin-transform-replace-object-assign": "^2.0.0-beta.0",
@@ -62,13 +60,12 @@
6260
"eslint-plugin-ava": "^4.5.1",
6361
"eslint-plugin-prettier": "^2.5.0",
6462
"eslint-plugin-react": "^7.7.0",
63+
"express": "^4.16.3",
64+
"express-graphql": "^0.6.12",
65+
"fake-tag": "^1.0.0",
6566
"get-port": "^3.2.0",
6667
"graphql": "^0.13.2",
67-
"graphql-tools": "^3.0.0",
6868
"husky": "^0.14.3",
69-
"koa": "^2.5.1",
70-
"koa-bodyparser": "^4.2.0",
71-
"koa-router": "^7.4.0",
7269
"lint-staged": "^7.0.5",
7370
"npm-run-all": "^4.1.2",
7471
"prettier": "^1.12.1",

src/preload.mjs

+3-3
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ export function preload(element) {
101101
)
102102
)
103103
else recurse(instance.render(), legacyContext)
104-
} else
105-
// The element is a functional component…
106-
recurse(element.type(props), legacyContext)
104+
}
105+
// The element is a functional component…
106+
else recurse(element.type(props), legacyContext)
107107
} else if (
108108
// The element is a context provider or DOM element and…
109109
element.props &&

0 commit comments

Comments
 (0)