Skip to content
This repository was archived by the owner on May 4, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# GraphQL Playground Hapi Example

> Note: `graphql-playground-middleware-hapi` @^2.0.0 requires `hapi` 17, for `hapi` 16 please use @^1.3.6

```sh
$ yarn
$ node index.js
Expand Down
48 changes: 29 additions & 19 deletions packages/graphql-playground-middleware-hapi/examples/basic/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
const hapi = require('hapi')
const { graphqlHapi } = require('apollo-server-hapi')
const hapiPlayground = require('../../src/index').default
const hapiPlayground = require('../../dist').default
const { makeExecutableSchema } = require('graphql-tools')

const server = new hapi.Server({ debug: { request: '*' } })

const HOST = 'localhost'
const PORT = 4000

const server = new hapi.Server({
host: HOST,
port: PORT,
debug: { request: '*' }
})

const schema = makeExecutableSchema({
typeDefs: `
type Query {
Expand All @@ -24,13 +28,8 @@ const schema = makeExecutableSchema({
},
})

server.connection({
host: HOST,
port: PORT,
})

server.register({
register: graphqlHapi,
const api = {
plugin: graphqlHapi,
options: {
path: '/graphql',
graphqlOptions: {
Expand All @@ -40,19 +39,30 @@ server.register({
cors: true,
},
},
})
}

server.register({
register: hapiPlayground,
const playground = {
plugin: hapiPlayground,
options: {
path: '/playground',
endpoint: '/graphql',
},
})
}

server.start(err => {
if (err) {
throw err
const plugins = [
api,
playground,
]

async function start() {
console.log(`Setting up server...`)
try {
await server.register(plugins)
await server.start()
console.log(`Server running at: ${server.info.uri}`)
} 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!

})
}

start()
Loading