-
-
Notifications
You must be signed in to change notification settings - Fork 517
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b533b33
commit 61d84e8
Showing
2 changed files
with
39 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters