-
Notifications
You must be signed in to change notification settings - Fork 16
/
extend.ts
45 lines (38 loc) · 969 Bytes
/
extend.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
44
45
import { g, Infer, InferResolvers, buildSchema } from './../src/index'
import { createYoga } from 'graphql-yoga'
import { createServer } from 'http'
const node = {
id: g.id()
}
const name = {
name: g.string()
}
const test = g.type('Test', {}).extend([node, name])
const queryType = g.type('Query', {
test: g.ref(() => test)
})
type Test = Infer<typeof test>
const resolvers: InferResolvers<{ Query: typeof queryType, Test: typeof test }, {}> = {
Query: {
test: (parent, args, context, info) => {
return {
id: '123',
name: 'Test'
}
}
},
Test: {
id: (parent, args, context, info) => {
return parent.id
},
name: (parent, args, context, info) => {
return parent.name
}
}
}
const schema = buildSchema({ g, resolvers })
const yoga = createYoga({ schema })
const server = createServer(yoga)
server.listen(4000, () => {
console.info('Server is running on http://localhost:4000/graphql')
})