-
Notifications
You must be signed in to change notification settings - Fork 0
/
gateway.js
40 lines (35 loc) · 1.27 KB
/
gateway.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
const { ApolloServer } = require('apollo-server');
const { ApolloGateway } = require('@apollo/gateway');
const { federatedApis } = require('./src/config/config');
const AuthenticatedDataSource = require('./src/AuthenticatedDataSource');
const createGateway = (serviceList) => {
return new ApolloGateway({
// ServiceList is optional, can use Apollo Graph Manager here as single source of truth
// Graph Manager will also enable server tracing and schema management tools
serviceList,
buildService({ url }) {
return new AuthenticatedDataSource({ url });
},
// experimental_pollInterval: 3000,
// Experimental query plan view
__exposeQueryPlanExperimental: true,
});
};
const server = new ApolloServer({
gateway: createGateway(federatedApis),
// If using Apollo Graph Manager, ensure `ENGINE_API_KEY` is set in environment
engine: false,
// Not currently supported, needs to be explicitly turned off
subscriptions: false,
context: ({ req }) => {
const token = req.headers.authorization || '';
return { token };
},
});
server.listen().then(({ url }) => {
console.info(`🚀 Gateway Server ready at ${url}`);
console.info('Federated APIs available at:');
console.info(federatedApis);
});
// For testing
module.exports = createGateway;