-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
34 lines (29 loc) · 1.03 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
import { ApolloServer } from "apollo-server-express";
import { ApolloServerPluginDrainHttpServer } from "apollo-server-core";
import { ApolloGateway, IntrospectAndCompose } from "@apollo/gateway";
import express from "express";
import http from "http";
import chalk from "chalk";
async function startApolloServer() {
const app = express();
const httpServer = http.createServer(app);
const gateway = new ApolloGateway({
supergraphSdl: new IntrospectAndCompose({
subgraphs: [
{ name: "products", url: "http://localhost:4001" },
{ name: "orders", url: "http://localhost:4002" },
],
}),
serviceHealthCheck: true,
});
const server = new ApolloServer({
gateway,
subscriptions: false,
plugins: [ApolloServerPluginDrainHttpServer({ httpServer })],
});
await server.start();
server.applyMiddleware({ app });
await new Promise((resolve) => httpServer.listen({ port: 4000 }, resolve));
console.log(`🚀 Server ready at http://localhost:4000${server.graphqlPath}`);
}
startApolloServer();