1package resolvers
2
3import (
4 "context"
5 "time"
6
7 "github.com/MichaelMure/git-bug/bug"
8 "github.com/MichaelMure/git-bug/graphql/connections"
9 "github.com/MichaelMure/git-bug/graphql/models"
10)
11
12type bugResolver struct{}
13
14func (bugResolver) Status(ctx context.Context, obj *bug.Snapshot) (models.Status, error) {
15 return convertStatus(obj.Status)
16}
17
18func (bugResolver) Comments(ctx context.Context, obj *bug.Snapshot, after *string, before *string, first *int, last *int) (models.CommentConnection, error) {
19 input := models.ConnectionInput{
20 Before: before,
21 After: after,
22 First: first,
23 Last: last,
24 }
25
26 edger := func(comment bug.Comment, offset int) connections.Edge {
27 return models.CommentEdge{
28 Node: comment,
29 Cursor: connections.OffsetToCursor(offset),
30 }
31 }
32
33 conMaker := func(edges []models.CommentEdge, nodes []bug.Comment, info models.PageInfo, totalCount int) (models.CommentConnection, error) {
34 return models.CommentConnection{
35 Edges: edges,
36 Nodes: nodes,
37 PageInfo: info,
38 TotalCount: totalCount,
39 }, nil
40 }
41
42 return connections.BugCommentCon(obj.Comments, edger, conMaker, input)
43}
44
45func (bugResolver) Operations(ctx context.Context, obj *bug.Snapshot, after *string, before *string, first *int, last *int) (models.OperationConnection, error) {
46 input := models.ConnectionInput{
47 Before: before,
48 After: after,
49 First: first,
50 Last: last,
51 }
52
53 edger := func(op bug.Operation, offset int) connections.Edge {
54 return models.OperationEdge{
55 Node: op,
56 Cursor: connections.OffsetToCursor(offset),
57 }
58 }
59
60 conMaker := func(edges []models.OperationEdge, nodes []bug.Operation, info models.PageInfo, totalCount int) (models.OperationConnection, error) {
61 return models.OperationConnection{
62 Edges: edges,
63 Nodes: nodes,
64 PageInfo: info,
65 TotalCount: totalCount,
66 }, nil
67 }
68
69 return connections.BugOperationCon(obj.Operations, edger, conMaker, input)
70}
71
72func (bugResolver) Timeline(ctx context.Context, obj *bug.Snapshot, after *string, before *string, first *int, last *int) (models.TimelineItemConnection, error) {
73 input := models.ConnectionInput{
74 Before: before,
75 After: after,
76 First: first,
77 Last: last,
78 }
79
80 edger := func(op bug.TimelineItem, offset int) connections.Edge {
81 return models.TimelineItemEdge{
82 Node: op,
83 Cursor: connections.OffsetToCursor(offset),
84 }
85 }
86
87 conMaker := func(edges []models.TimelineItemEdge, nodes []bug.TimelineItem, info models.PageInfo, totalCount int) (models.TimelineItemConnection, error) {
88 return models.TimelineItemConnection{
89 Edges: edges,
90 Nodes: nodes,
91 PageInfo: info,
92 TotalCount: totalCount,
93 }, nil
94 }
95
96 return connections.BugTimelineItemCon(obj.Timeline, edger, conMaker, input)
97}
98
99func (bugResolver) LastEdit(ctx context.Context, obj *bug.Snapshot) (time.Time, error) {
100 return obj.LastEditTime(), nil
101}