-
Notifications
You must be signed in to change notification settings - Fork 44
/
gateway.js
46 lines (38 loc) · 1.4 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
41
42
43
44
45
46
// Open Telemetry (optional)
const { ApolloOpenTelemetry } = require('supergraph-demo-opentelemetry');
if (process.env.APOLLO_OTEL_EXPORTER_TYPE) {
new ApolloOpenTelemetry({
type: 'router',
name: 'router',
exporter: {
type: process.env.APOLLO_OTEL_EXPORTER_TYPE, // console, zipkin, collector
host: process.env.APOLLO_OTEL_EXPORTER_HOST,
port: process.env.APOLLO_OTEL_EXPORTER_PORT,
}
}).setupInstrumentation();
}
// Main
const { ApolloServer } = require('apollo-server');
const { ApolloGateway } = require('@apollo/gateway');
const { readFileSync } = require('fs');
const port = process.env.APOLLO_PORT || 4000;
const embeddedSchema = process.env.APOLLO_SCHEMA_CONFIG_EMBEDDED == "true" ? true : false;
const config = {};
if (embeddedSchema){
const supergraph = "/etc/config/supergraph.graphql"
config['supergraphSdl'] = readFileSync(supergraph).toString();
console.log('Starting Apollo Gateway in local mode ...');
console.log(`Using local: ${supergraph}`)
} else {
console.log('Starting Apollo Gateway in managed mode ...');
}
const gateway = new ApolloGateway(config);
const server = new ApolloServer({
gateway,
debug: true,
// Subscriptions are unsupported but planned for a future Gateway version.
subscriptions: false
});
server.listen( {port: port} ).then(({ url }) => {
console.log(`🚀 Graph Router ready at ${url}`);
}).catch(err => {console.error(err)});