From 2d8d381c15e141b96380d069a96ae8e1b39311e1 Mon Sep 17 00:00:00 2001 From: Stefano Date: Wed, 6 Sep 2023 19:10:58 +0100 Subject: [PATCH] Fix HAPI example (#362) --- example/middleware/hapi.js | 70 +++++++++++++++++---------------- example/middleware/package.json | 4 +- 2 files changed, 39 insertions(+), 35 deletions(-) diff --git a/example/middleware/hapi.js b/example/middleware/hapi.js index 7d93f897..742d854e 100644 --- a/example/middleware/hapi.js +++ b/example/middleware/hapi.js @@ -1,44 +1,48 @@ -const Hapi = require('hapi'); -const { graphqlHapi } = require('graphql-server-hapi'); +const Hapi = require('@hapi/hapi'); const { hapi: voyagerMiddleware } = require('graphql-voyager/middleware'); -const schema = require('./schema'); +const myTestSchema = require('./schema'); -const server = new Hapi.Server({ - port: 3001, -}); +const { ApolloServer } = require('@apollo/server'); +const hapiApollo = require('@as-integrations/hapi').default; const init = async () => { - await server.register([ - { - plugin: graphqlHapi, - options: { - path: '/graphql', - graphqlOptions: { - schema, - }, - route: { - cors: true, - }, - }, + const server = Hapi.server({ + port: 3001, + host: 'localhost', + }); + + const apolloServer = new ApolloServer({ + typeDefs: myTestSchema, + }); + + await apolloServer.start().then(console.log('Apollo server started')); + + await server.register({ + plugin: hapiApollo, + options: { + apolloServer, + path: '/graphql', }, - { - plugin: voyagerMiddleware, - options: { - path: '/voyager', - route: { - cors: true, - }, - endpointUrl: '/graphql', - displayOptions: { - sortByAlphabet: true, - }, + }); + + await server.register({ + plugin: voyagerMiddleware, + options: { + path: '/voyager', + endpointUrl: '/graphql', + displayOptions: { + sortByAlphabet: true, }, }, - ]); - - await server.start().then(() => { - console.log(`Started on ${server.info.uri}/voyager`); }); + + await server.start(); + console.log('Server running on %s', server.info.uri); }; +process.on('unhandledRejection', (err) => { + console.log(err); + process.exit(1); +}); + init(); diff --git a/example/middleware/package.json b/example/middleware/package.json index ef6cbad0..0ec8d2a0 100644 --- a/example/middleware/package.json +++ b/example/middleware/package.json @@ -7,9 +7,9 @@ "express": "4.16.3", "express-graphql": "0.6.12", "graphql": "14.0.2", - "graphql-server-hapi": "1.4.0", + "graphql-server-hapi": "1.4.1", "graphql-voyager": "../", - "hapi": "17.5.4", + "@hapi/hapi": "20.3.0", "koa": "2.5.2", "koa-graphql": "0.7.5", "koa-router": "7.4.0"