-
Notifications
You must be signed in to change notification settings - Fork 6
/
service.js
36 lines (32 loc) · 922 Bytes
/
service.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
const { ApolloServer } = require("apollo-server");
const { ApolloGateway, RemoteGraphQLDataSource } = require("@apollo/gateway");
const { endpoints, pollingInterval } = require("./config");
const gateway = new ApolloGateway({
serviceList: endpoints,
experimental_pollInterval: pollingInterval,
buildService({ url }) {
return new RemoteGraphQLDataSource({
url,
willSendRequest({ request, context }) {
if (context.Authorization) {
request.http.headers.set("Authorization", context.Authorization);
}
}
});
}
});
(async () => {
const { schema, executor } = await gateway.load();
const server = new ApolloServer({
schema,
executor,
context: ({ req }) => {
return {
Authorization: req.headers.authorization || null
};
}
});
server.listen().then(({ url }) => {
console.log(`🚀 Server ready at ${url}`);
});
})();