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