-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
43 lines (37 loc) · 1.08 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const hapi = require("hapi");
const { graphqlHapi } = require("apollo-server-hapi");
const { makeExecutableSchema } = require("graphql-tools");
const { ApolloEngine } = require("apollo-engine");
const host = "localhost";
const PORT = 3000;
const schema = makeExecutableSchema({
typeDefs: `type Query { hello: String @cacheControl(maxAge: 240) }`,
resolvers: { Query: { hello: () => "world" } },
});
const start = async () => {
const engine = new ApolloEngine({
apiKey: process.env.ENGINE_API_KEY,
});
const listener = await engine.hapiListener({ port: PORT });
const server = new hapi.Server();
server.connection({ host, listener, autoListen: false });
server.register({
register: graphqlHapi,
options: {
path: "/graphql",
graphqlOptions: { schema, tracing: true, cacheControl: true },
route: { cors: true },
},
});
server.start(err => {
if (err) throw err;
const { protocol, host, uri } = server.info;
console.log(
`Server running!
Engine Proxied: ${protocol}//${host}:${PORT}
Hapi: ${uri}
`
);
});
};
start();