1package resolvers
2
3import (
4 "context"
5 "github.com/MichaelMure/git-bug/bug"
6 "github.com/MichaelMure/git-bug/cache"
7 "github.com/MichaelMure/git-bug/graphql/connections"
8 "github.com/MichaelMure/git-bug/graphql/models"
9)
10
11type bugResolver struct {
12 cache cache.Cacher
13}
14
15func (bugResolver) Status(ctx context.Context, obj *bug.Snapshot) (models.Status, error) {
16 return convertStatus(obj.Status)
17}
18
19func (bugResolver) Comments(ctx context.Context, obj *bug.Snapshot, input models.ConnectionInput) (models.CommentConnection, error) {
20 edger := func(comment bug.Comment, offset int) connections.Edge {
21 return models.CommentEdge{
22 Node: comment,
23 Cursor: connections.OffsetToCursor(offset),
24 }
25 }
26
27 conMaker := func(edges []models.CommentEdge, info models.PageInfo, totalCount int) models.CommentConnection {
28 return models.CommentConnection{
29 Edges: edges,
30 PageInfo: info,
31 TotalCount: totalCount,
32 }
33 }
34
35 return connections.BugCommentCon(obj.Comments, edger, conMaker, input)
36}
37
38func (bugResolver) Operations(ctx context.Context, obj *bug.Snapshot, input models.ConnectionInput) (models.OperationConnection, error) {
39 edger := func(op bug.Operation, offset int) connections.Edge {
40 return models.OperationEdge{
41 Node: op.(models.OperationUnion),
42 Cursor: connections.OffsetToCursor(offset),
43 }
44 }
45
46 conMaker := func(edges []models.OperationEdge, info models.PageInfo, totalCount int) models.OperationConnection {
47 return models.OperationConnection{
48 Edges: edges,
49 PageInfo: info,
50 TotalCount: totalCount,
51 }
52 }
53
54 return connections.BugOperationCon(obj.Operations, edger, conMaker, input)
55}