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