-
Notifications
You must be signed in to change notification settings - Fork 16
/
relay.ts
45 lines (40 loc) · 1.13 KB
/
relay.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, InferResolvers, buildSchema, Infer } from './../src/index'
import { createYoga } from 'graphql-yoga'
import { createServer } from 'http'
const user = g.node('UserNode', {
name: g.string().description('User name'),
})
const userEdge = g.edge('UserEdge', g.ref(() => user))
const userConnection = g.connection('UserConnection', g.ref(() => userEdge))
const queryType = g.type('Query', {
users: g.ref(userConnection).args({ ...g.pageInfoArgs })
})
const resolvers: InferResolvers<{ Query: typeof queryType }, {}> = {
Query: {
users: (parent, args, context, info) => {
return {
edges: [
{
node: {
id: '1',
name: 'John',
},
cursor: '1',
},
],
pageInfo: {
hasNextPage: false,
hasPreviousPage: false,
startCursor: '1',
endCursor: '1',
}
}
}
}
}
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')
})