-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathserver.js
44 lines (35 loc) · 1.15 KB
/
server.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
44
/**
* Gateway server and main entrypoint
*/
const { ApolloServer } = require('apollo-server');
const { NodeGateway, NodeCompose } = require('./node-gateway');
const { server: serverProduct } = require('./server-product');
const { server: serverReview } = require('./server-review');
const BASE_PORT = 8000;
const SERVERS = [
{ name: '📦 product', server: serverProduct },
{ name: '🆒 review', server: serverReview },
];
async function startServers() {
const res = SERVERS.map(async ({ server, name }, index) => {
const number = index + 1;
const { url } = await server.listen(BASE_PORT + number);
console.log(`${name} up at ${url}graphql`);
return { name, url };
});
return await Promise.all(res);
}
async function main() {
const subgraphs = await startServers();
const gateway = new NodeGateway({
supergraphSdl: new NodeCompose({ subgraphs }),
serviceHealthCheck: true,
});
const server = new ApolloServer({ gateway, subscriptions: false });
const info = await server.listen(BASE_PORT);
console.log(`\n--\n\n🌍 gateway up at ${info.url}graphql`);
}
main().catch(err => {
console.error(err);
process.exit(1);
});