Skip to content
This repository was archived by the owner on May 4, 2026. It is now read-only.

fix: update to support hapi 17 - #396

Merged
timsuchanek merged 9 commits into
graphql:masterfrom
Saeris:hapi-17-update
Jan 19, 2018
Merged

fix: update to support hapi 17#396
timsuchanek merged 9 commits into
graphql:masterfrom
Saeris:hapi-17-update

Conversation

@Saeris

@Saeris Saeris commented Jan 4, 2018

Copy link
Copy Markdown

Hapi 17 introduces breaking changes to it's API which affects all existing plugins. This fix is intended to migrate from hapi 16 to 17. Currently graphql-playground-middleware-hapi will throw an error such as the following:

error: AssertionError [ERR_ASSERTION]: Invalid plugin options {
  "plugin": {
    "register": function (server, options, next) {\n    if (arguments.length !== 3) {\n        throw new Error(\"Playground middleware expects exactly 3 arguments, got \" + arguments.length);\n    }\n    var path = options.path, _a = options.route, config = _a === void 0
 ? {} : _a, rest = __rest(options, [\"path\", \"route\"]);\n    var middlewareOptions = __assign({}, rest, { version: pkg.version });\n    server.route({\n        method: 'GET',\n        path: path,\n        config: config,\n        handler: function (request, reply) {\n
            reply(graphql_playground_html_1.renderPlaygroundPage(middlewareOptions)).header('Content-Type', 'text/html');\n        },\n    });\n    return next();\n},
    "options": {
      "path": "/playground",
      "endpoint": "/graphql"
    },
    "name" [1]: -- missing --
  }
}

[1] "name" is required

Changes:

Updated graphql-playground-middleware-hapi plugin definition to support hapi 17.

Removed attributes?: any and replaced it with pkg?: any. multiple is false by default in hapi 17.

Please see the following for more information on the changes between hapi 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.

Please change package version numbers as required.

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.
@CLAassistant

CLAassistant commented Jan 4, 2018

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

} catch (err) {
console.log(`Failed to start server!`, err)
}
console.log(`Server running at: ${server.info.uri}`)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops! This line can be deleted!

@schickling schickling left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for updating this!

@schickling

Copy link
Copy Markdown
Collaborator

@timsuchanek can you merge & publish this?

@Saeris

Saeris commented Jan 4, 2018

Copy link
Copy Markdown
Author

I'll be heading out of town later today and won't be available again until about the middle of next week. As suggested I'll check out npm publish when I get back to test this and update you then.

@Saeris

Saeris commented Jan 4, 2018

Copy link
Copy Markdown
Author

quick update:

I found a bit of time to try publishing it to my scope to test as you suggested, found I needed to make some more changes.

Running into an issue with the middleware now where it can't find the css/middleware.js on the CDN and I think it's because of a version number mismatch. I'll look into a fix later on.

Seems likely that because the mono-repo version numbers need to be in-sync to dynamically grab the version number from the package.json file, that's one part of the problem since my version of the package will always been out of sync with the mono-repo.

I can test to make sure the middleware works I think by using a specific version number that's on the CDN. For now I can at least get the page to show a loading indicator. Here's the console errors from Chrome for reference:

GET http://cdn.jsdelivr.net/npm/graphql-playground-react@1.3.6/build/static/css/index.css net::ERR_ABORTED
GET http://cdn.jsdelivr.net/npm/graphql-playground-react@1.3.6/build/static/js/middleware.js net::ERR_ABORTED
Uncaught ReferenceError: GraphQLPlayground is not defined
    at playground:531

I'll push my WIP in case anyone has the time to take a look.

Work in progress commit for review + feedback.
export interface Register {
(server: Server, options: MiddlewareOptions, next: any): void
attributes?: any
(server: Server, options: MiddlewareOptions): void

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not too familiar with Typescript, so if I'm doing this wrong please let me know!

@timsuchanek timsuchanek left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @Saeris and sorry for getting back so late!
There are 2 small changes that I would like to see before I can merge the it.

const hapi = require('hapi')
const { graphqlHapi } = require('apollo-server-hapi')
const hapiPlayground = require('graphql-playground-middleware-hapi').default
const hapiPlayground = require('@saeris/graphql-playground-middleware-hapi').default

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change this to ../../dist/index

method: 'GET',
path,
config,
handler: async (request, h) => h.response(await renderPlaygroundPage(middlewareOptions)).type('text/html')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the latest graphql-playground-html there is no need for async await anymore

@timsuchanek timsuchanek mentioned this pull request Jan 18, 2018
2 tasks
Drake Costa added 2 commits January 19, 2018 00:03
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.

@timsuchanek timsuchanek left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for putting the work into this!

@timsuchanek
timsuchanek merged commit a4ddbd6 into graphql:master Jan 19, 2018
@Saeris
Saeris deleted the hapi-17-update branch January 19, 2018 10:58
RenovZ pushed a commit to RenovZ/graphql-playground that referenced this pull request Mar 25, 2022
* 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.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants