Skip to content

Commit a4ddbd6

Browse files
Drake Costatimsuchanek
authored andcommitted
fix: update to support hapi 17 (graphql#396)
* fix: update to support hapi 17 Updated plugin definition to support hapi 17. Please see the following for more information on the changes between hap 16 and 17: https://futurestud.io/tutorials/hapi-v17-upgrade-guide-your-move-to-async-await https://hapijs.com/api#plugins Updated the example project to use hapi 17, including dependencies. * v2.0.1 * v2.0.2 * v2.0.3 * v2.0.4 * v2.0.5 * wip: hapi-17-update fixes Work in progress commit for review + feedback. * refactor: get middleware version from package.json, example use local Made changes requested by @timsuchanek Plugin now uses key `playgroundVersion` in `package.json` to get middleware version from jsdelivr. Examples/basic now uses the local version of the middleware as built with `yarn build` located in `dist`. Removed dependency from example `package.json`, as it is no longer used. Set example version to `2.0.0` as it now uses Hapi 17. Updated middleware dependencies to reflect those of the current version. Middleware version number will need to be bumped to a new major version for the next release, as it will not be backwards compatible with Hapi 16. TODO: Update readme to direct users to use the last stable version supporting Hapi 16 if they don't wish to upgrade.
1 parent 3c694fd commit a4ddbd6

8 files changed

Lines changed: 9777 additions & 60 deletions

File tree

packages/graphql-playground-middleware-hapi/examples/basic/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# GraphQL Playground Hapi Example
22

3+
> Note: `graphql-playground-middleware-hapi` @^2.0.0 requires `hapi` 17, for `hapi` 16 please use @^1.3.6
4+
35
```sh
46
$ yarn
57
$ node index.js
Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
const hapi = require('hapi')
22
const { graphqlHapi } = require('apollo-server-hapi')
3-
const hapiPlayground = require('../../src/index').default
3+
const hapiPlayground = require('../../dist').default
44
const { makeExecutableSchema } = require('graphql-tools')
55

6-
const server = new hapi.Server({ debug: { request: '*' } })
7-
86
const HOST = 'localhost'
97
const PORT = 4000
108

9+
const server = new hapi.Server({
10+
host: HOST,
11+
port: PORT,
12+
debug: { request: '*' }
13+
})
14+
1115
const schema = makeExecutableSchema({
1216
typeDefs: `
1317
type Query {
@@ -24,13 +28,8 @@ const schema = makeExecutableSchema({
2428
},
2529
})
2630

27-
server.connection({
28-
host: HOST,
29-
port: PORT,
30-
})
31-
32-
server.register({
33-
register: graphqlHapi,
31+
const api = {
32+
plugin: graphqlHapi,
3433
options: {
3534
path: '/graphql',
3635
graphqlOptions: {
@@ -40,19 +39,30 @@ server.register({
4039
cors: true,
4140
},
4241
},
43-
})
42+
}
4443

45-
server.register({
46-
register: hapiPlayground,
44+
const playground = {
45+
plugin: hapiPlayground,
4746
options: {
4847
path: '/playground',
4948
endpoint: '/graphql',
5049
},
51-
})
50+
}
5251

53-
server.start(err => {
54-
if (err) {
55-
throw err
52+
const plugins = [
53+
api,
54+
playground,
55+
]
56+
57+
async function start() {
58+
console.log(`Setting up server...`)
59+
try {
60+
await server.register(plugins)
61+
await server.start()
62+
console.log(`Server running at: ${server.info.uri}`)
63+
} catch (err) {
64+
console.log(`Failed to start server!`, err)
5665
}
57-
console.log(`Server running at: ${server.info.uri}`)
58-
})
66+
}
67+
68+
start()

0 commit comments

Comments
 (0)