-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
43 lines (40 loc) · 1 KB
/
index.ts
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
import {
GraphQLServer,
JsonLogger
} from '@dreamit/graphql-server'
import fastify from 'fastify'
import {
userSchema,
userSchemaResolvers
} from './ExampleSchemas'
const server = fastify()
const graphqlServer = new GraphQLServer(
{
schema: userSchema,
rootValue: userSchemaResolvers,
logger: new JsonLogger('fastifyServer', 'user-service')
}
)
server.all('/graphql', async(request, reply) => {
return graphqlServer.handleRequest(request, {
statusCode: reply.statusCode,
setHeader: function(name, value) {
reply.header(name, value)
return this
},
removeHeader: function(name) {
reply.removeHeader(name)
},
end: function(chunk) {
reply.send(chunk)
return this
},
})
})
server.listen({port: 7070}, (error, address) => {
if (error) {
console.error(error)
throw error
}
console.log(`Server listening at ${address}`)
})