-
Notifications
You must be signed in to change notification settings - Fork 16
/
implements.ts
43 lines (37 loc) · 983 Bytes
/
implements.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 { g, Infer, InferResolvers, buildSchema } from './../src/index'
import { createYoga } from 'graphql-yoga'
import { createServer } from 'http'
const node = g.interface('Node', {
id: g.id()
})
const name = g.interface('Name', {
name: g.string()
})
const test = g.type('Test', {}).implements([node, name])
const queryType = g.type('Query', {
test: g.ref(() => 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')
})