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 "github.com/MichaelMure/git-bug/identity"
12)
13
14var _ graph.BugResolver = &bugResolver{}
15
16type bugResolver struct{}
17
18func (bugResolver) Status(ctx context.Context, obj *bug.Snapshot) (models.Status, error) {
19 return convertStatus(obj.Status)
20}
21
22func (bugResolver) Comments(ctx context.Context, obj *bug.Snapshot, after *string, before *string, first *int, last *int) (models.CommentConnection, error) {
23 input := models.ConnectionInput{
24 Before: before,
25 After: after,
26 First: first,
27 Last: last,
28 }
29
30 edger := func(comment bug.Comment, offset int) connections.Edge {
31 return models.CommentEdge{
32 Node: comment,
33 Cursor: connections.OffsetToCursor(offset),
34 }
35 }
36
37 conMaker := func(edges []models.CommentEdge, nodes []bug.Comment, info models.PageInfo, totalCount int) (models.CommentConnection, error) {
38 return models.CommentConnection{
39 Edges: edges,
40 Nodes: nodes,
41 PageInfo: info,
42 TotalCount: totalCount,
43 }, nil
44 }
45
46 return connections.CommentCon(obj.Comments, edger, conMaker, input)
47}
48
49func (bugResolver) Operations(ctx context.Context, obj *bug.Snapshot, after *string, before *string, first *int, last *int) (models.OperationConnection, error) {
50 input := models.ConnectionInput{
51 Before: before,
52 After: after,
53 First: first,
54 Last: last,
55 }
56
57 edger := func(op bug.Operation, offset int) connections.Edge {
58 return models.OperationEdge{
59 Node: op,
60 Cursor: connections.OffsetToCursor(offset),
61 }
62 }
63
64 conMaker := func(edges []models.OperationEdge, nodes []bug.Operation, info models.PageInfo, totalCount int) (models.OperationConnection, error) {
65 return models.OperationConnection{
66 Edges: edges,
67 Nodes: nodes,
68 PageInfo: info,
69 TotalCount: totalCount,
70 }, nil
71 }
72
73 return connections.OperationCon(obj.Operations, edger, conMaker, input)
74}
75
76func (bugResolver) Timeline(ctx context.Context, obj *bug.Snapshot, after *string, before *string, first *int, last *int) (models.TimelineItemConnection, error) {
77 input := models.ConnectionInput{
78 Before: before,
79 After: after,
80 First: first,
81 Last: last,
82 }
83
84 edger := func(op bug.TimelineItem, offset int) connections.Edge {
85 return models.TimelineItemEdge{
86 Node: op,
87 Cursor: connections.OffsetToCursor(offset),
88 }
89 }
90
91 conMaker := func(edges []models.TimelineItemEdge, nodes []bug.TimelineItem, info models.PageInfo, totalCount int) (models.TimelineItemConnection, error) {
92 return models.TimelineItemConnection{
93 Edges: edges,
94 Nodes: nodes,
95 PageInfo: info,
96 TotalCount: totalCount,
97 }, nil
98 }
99
100 return connections.TimelineItemCon(obj.Timeline, edger, conMaker, input)
101}
102
103func (bugResolver) LastEdit(ctx context.Context, obj *bug.Snapshot) (time.Time, error) {
104 return obj.LastEditTime(), nil
105}
106
107func (bugResolver) Actors(ctx context.Context, obj *bug.Snapshot, after *string, before *string, first *int, last *int) (models.IdentityConnection, error) {
108 input := models.ConnectionInput{
109 Before: before,
110 After: after,
111 First: first,
112 Last: last,
113 }
114
115 edger := func(actor identity.Interface, offset int) connections.Edge {
116 return models.IdentityEdge{
117 Node: actor,
118 Cursor: connections.OffsetToCursor(offset),
119 }
120 }
121
122 conMaker := func(edges []models.IdentityEdge, nodes []identity.Interface, info models.PageInfo, totalCount int) (models.IdentityConnection, error) {
123 return models.IdentityConnection{
124 Edges: edges,
125 Nodes: nodes,
126 PageInfo: info,
127 TotalCount: totalCount,
128 }, nil
129 }
130
131 return connections.IdentityCon(obj.Actors, edger, conMaker, input)
132}
133
134func (bugResolver) Participants(ctx context.Context, obj *bug.Snapshot, after *string, before *string, first *int, last *int) (models.IdentityConnection, error) {
135 input := models.ConnectionInput{
136 Before: before,
137 After: after,
138 First: first,
139 Last: last,
140 }
141
142 edger := func(participant identity.Interface, offset int) connections.Edge {
143 return models.IdentityEdge{
144 Node: participant,
145 Cursor: connections.OffsetToCursor(offset),
146 }
147 }
148
149 conMaker := func(edges []models.IdentityEdge, nodes []identity.Interface, info models.PageInfo, totalCount int) (models.IdentityConnection, error) {
150 return models.IdentityConnection{
151 Edges: edges,
152 Nodes: nodes,
153 PageInfo: info,
154 TotalCount: totalCount,
155 }, nil
156 }
157
158 return connections.IdentityCon(obj.Participants, edger, conMaker, input)
159}