-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathgateway.js
51 lines (41 loc) · 1.29 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
47
48
49
50
51
const { ApolloServer } = require('apollo-server')
const { ApolloGateway } = require('@apollo/gateway')
const { post } = require('httpie')
async function getSupergraph() {
const res = await post(`http://localhost:3000/schema/supergraph`, {
body: {
graphName: 'my_graph',
},
})
return {
supergraphSdl: res.data.data.supergraphSdl,
id: res.data.data.compositionId,
}
}
async function startServer() {
const gateway = new ApolloGateway({
// fetch for schema or service updates every 30s
experimental_pollInterval: 30000,
async experimental_updateSupergraphSdl() {
return getSupergraph()
},
// Experimental: Enabling this enables the query plan view in Playground.
__exposeQueryPlanExperimental: false,
})
const server = new ApolloServer({
gateway,
// Apollo Graph Manager (previously known as Apollo Engine)
// When enabled and an `ENGINE_API_KEY` is set in the environment,
// provides metrics, schema management and trace reporting.
engine: false,
// Subscriptions are unsupported but planned for a future Gateway version.
subscriptions: false,
})
server.listen().then(({ url }) => {
console.log(`🚀 Server ready at ${url}`)
})
}
startServer().catch((err) => {
console.error(err)
process.exit(1)
})