Skip to content

Commit

Permalink
Fix HAPI example (#362)
Browse files Browse the repository at this point in the history
  • Loading branch information
LunaticMuch authored Sep 6, 2023
1 parent f8e22f9 commit 2d8d381
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 35 deletions.
70 changes: 37 additions & 33 deletions example/middleware/hapi.js
Original file line number Diff line number Diff line change
@@ -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();
4 changes: 2 additions & 2 deletions example/middleware/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 2d8d381

Please sign in to comment.