-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
54 lines (48 loc) · 1.15 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
'use strict'
import Fastify from 'fastify'
import mercurius from 'mercurius'
import nexus from 'nexus'
import * as types from './schema/index.js'
import TdEngine from './lib/tdengine.js'
import { enableGraphiQL } from './config.js'
import { fileURLToPath } from 'url'
import { dirname, join } from 'path'
const opts = {
logger: {
level: 'debug'
}
}
const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)
const { makeSchema } = nexus
const fastify = Fastify(opts)
const tdEngine = new TdEngine(fastify.log)
const schema = makeSchema({
types: types,
features: {
abstractTypeStrategies: {
resolveType: false
}
},
outputs: {
schema: join(__dirname, './schema.graphql'),
typegen: join(__dirname, './generated-types.d.ts')
}
})
fastify.register(mercurius, {
schema,
context: (req) => {
return {
tdEngine: tdEngine,
log: fastify.log
}
},
graphiql: {
enabled: enableGraphiQL
}
})
await fastify.listen({ port: 3000, host: 'localhost' })
fastify.ready(() => {
console.log(`listening on ${JSON.stringify(fastify.server.address())}`)
console.log(fastify.printRoutes())
})