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 t := obj.LastEditTime()
105 return &t, nil
106}
107
108func (bugResolver) Actors(ctx context.Context, obj *bug.Snapshot, after *string, before *string, first *int, last *int) (*models.IdentityConnection, error) {
109 input := models.ConnectionInput{
110 Before: before,
111 After: after,
112 First: first,
113 Last: last,
114 }
115
116 edger := func(actor identity.Interface, offset int) connections.Edge {
117 return models.IdentityEdge{
118 Node: actor,
119 Cursor: connections.OffsetToCursor(offset),
120 }
121 }
122
123 conMaker := func(edges []models.IdentityEdge, nodes []identity.Interface, info models.PageInfo, totalCount int) (*models.IdentityConnection, error) {
124 return &models.IdentityConnection{
125 Edges: edges,
126 Nodes: nodes,
127 PageInfo: info,
128 TotalCount: totalCount,
129 }, nil
130 }
131
132 return connections.IdentityCon(obj.Actors, edger, conMaker, input)
133}
134
135func (bugResolver) Participants(ctx context.Context, obj *bug.Snapshot, after *string, before *string, first *int, last *int) (*models.IdentityConnection, error) {
136 input := models.ConnectionInput{
137 Before: before,
138 After: after,
139 First: first,
140 Last: last,
141 }
142
143 edger := func(participant identity.Interface, offset int) connections.Edge {
144 return models.IdentityEdge{
145 Node: participant,
146 Cursor: connections.OffsetToCursor(offset),
147 }
148 }
149
150 conMaker := func(edges []models.IdentityEdge, nodes []identity.Interface, info models.PageInfo, totalCount int) (*models.IdentityConnection, error) {
151 return &models.IdentityConnection{
152 Edges: edges,
153 Nodes: nodes,
154 PageInfo: info,
155 TotalCount: totalCount,
156 }, nil
157 }
158
159 return connections.IdentityCon(obj.Participants, edger, conMaker, input)
160}