forked from stevefan1999-personal/graphql-bug
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
63 lines (55 loc) · 1.42 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
require('isomorphic-fetch')
const { introspectSchema, makeRemoteExecutableSchema } = require('graphql-tools')
const { HttpLink } = require('apollo-link-http')
const { GraphQLServer } = require('graphql-yoga')
async function createStitchedServer () {
const link = new HttpLink({
uri: 'http://localhost:3000/graphql'
})
const schema = makeRemoteExecutableSchema({
schema: await introspectSchema(link),
link
})
const server = new GraphQLServer({
schema
})
const httpServer = server.createHttpServer({
playground: '/graphql',
endpoint: '/graphql',
subscriptions: '/graphql',
debug: true
})
return httpServer
}
function createOriginEndpoint() {
const typeDefs = `
type Query {
fire: Boolean
}
`
const resolvers = {
Query: {
fire (_) {
throw { message: 'This error is intentionally thrown!' };
}
}
}
const server = new GraphQLServer({ typeDefs, resolvers })
const httpServer = server.createHttpServer({
playground: '/graphql',
endpoint: '/graphql',
subscriptions: '/graphql',
debug: true
})
return httpServer
}
(async function () {
const originServer = createOriginEndpoint()
originServer.listen(3000, () => {
console.log(`Origin server started at :3000`)
})
const stitchedServer = await createStitchedServer()
stitchedServer.listen(3001, () => {
console.log(`Stitched server started at :3001`)
})
})()