-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathmain.nim
48 lines (34 loc) · 1.01 KB
/
main.nim
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
import
std/[os, strutils], chronos, chronicles,
graphql, graphql/httpserver
{.pragma: apiPragma, cdecl, gcsafe, raises: [].}
proc queryHello(ud: RootRef, params: Args, parent: Node): RespResult {.apiPragma.} =
return ok(resp("world"))
const queryProcs = {
"hello": queryHello,
}
type Query = ref object of RootRef
hello: string
proc loadSchema(ctx: GraphqlRef): GraphqlResult =
var conf = defaultParserConf()
conf.flags.incl pfCommentDescription
var ud = Query()
ctx.addResolvers(ud, "Query", queryProcs)
ctx.parseSchemaFromFile("schema.graphql")
proc main() =
let socketFlags = {ServerFlags.TcpNoDelay, ServerFlags.ReuseAddr}
var ctx = GraphqlRef.new()
let res = ctx.loadSchema()
if res.isErr:
debugEcho res.error
return
let sres = GraphqlHttpServerRef.new(ctx,
address = initTAddress("127.0.0.1:8000"),
socketFlags = socketFlags)
if sres.isErr():
debugEcho sres.error
return
let server = sres.get()
server.start()
runForever()
main()