1package resolvers
2
3import (
4 "context"
5
6 "github.com/MichaelMure/git-bug/bug"
7 "github.com/MichaelMure/git-bug/graphql/connections"
8 "github.com/MichaelMure/git-bug/graphql/graph"
9 "github.com/MichaelMure/git-bug/graphql/models"
10)
11
12var _ graph.BugResolver = &bugResolver{}
13
14type bugResolver struct{}
15
16func (bugResolver) ID(_ context.Context, obj models.BugWrapper) (string, error) {
17 return obj.Id().String(), nil
18}
19
20func (bugResolver) HumanID(_ context.Context, obj models.BugWrapper) (string, error) {
21 return obj.Id().Human(), nil
22}
23
24func (bugResolver) Status(_ context.Context, obj models.BugWrapper) (models.Status, error) {
25 return convertStatus(obj.Status())
26}
27
28func (bugResolver) Comments(_ context.Context, obj models.BugWrapper, after *string, before *string, first *int, last *int) (*models.CommentConnection, error) {
29 input := models.ConnectionInput{
30 Before: before,
31 After: after,
32 First: first,
33 Last: last,
34 }
35
36 edger := func(comment bug.Comment, offset int) connections.Edge {
37 return models.CommentEdge{
38 Node: &comment,
39 Cursor: connections.OffsetToCursor(offset),
40 }
41 }
42
43 conMaker := func(edges []*models.CommentEdge, nodes []bug.Comment, info *models.PageInfo, totalCount int) (*models.CommentConnection, error) {
44 var commentNodes []*bug.Comment
45 for _, c := range nodes {
46 commentNodes = append(commentNodes, &c)
47 }
48 return &models.CommentConnection{
49 Edges: edges,
50 Nodes: commentNodes,
51 PageInfo: info,
52 TotalCount: totalCount,
53 }, nil
54 }
55
56 comments, err := obj.Comments()
57 if err != nil {
58 return nil, err
59 }
60
61 return connections.CommentCon(comments, edger, conMaker, input)
62}
63
64func (bugResolver) Operations(_ context.Context, obj models.BugWrapper, after *string, before *string, first *int, last *int) (*models.OperationConnection, error) {
65 input := models.ConnectionInput{
66 Before: before,
67 After: after,
68 First: first,
69 Last: last,
70 }
71
72 edger := func(op bug.Operation, offset int) connections.Edge {
73 return models.OperationEdge{
74 Node: op,
75 Cursor: connections.OffsetToCursor(offset),
76 }
77 }
78
79 conMaker := func(edges []*models.OperationEdge, nodes []bug.Operation, info *models.PageInfo, totalCount int) (*models.OperationConnection, error) {
80 return &models.OperationConnection{
81 Edges: edges,
82 Nodes: nodes,
83 PageInfo: info,
84 TotalCount: totalCount,
85 }, nil
86 }
87
88 ops, err := obj.Operations()
89 if err != nil {
90 return nil, err
91 }
92
93 return connections.OperationCon(ops, edger, conMaker, input)
94}
95
96func (bugResolver) Timeline(_ context.Context, obj models.BugWrapper, after *string, before *string, first *int, last *int) (*models.TimelineItemConnection, error) {
97 input := models.ConnectionInput{
98 Before: before,
99 After: after,
100 First: first,
101 Last: last,
102 }
103
104 edger := func(op bug.TimelineItem, offset int) connections.Edge {
105 return models.TimelineItemEdge{
106 Node: op,
107 Cursor: connections.OffsetToCursor(offset),
108 }
109 }
110
111 conMaker := func(edges []*models.TimelineItemEdge, nodes []bug.TimelineItem, info *models.PageInfo, totalCount int) (*models.TimelineItemConnection, error) {
112 return &models.TimelineItemConnection{
113 Edges: edges,
114 Nodes: nodes,
115 PageInfo: info,
116 TotalCount: totalCount,
117 }, nil
118 }
119
120 timeline, err := obj.Timeline()
121 if err != nil {
122 return nil, err
123 }
124
125 return connections.TimelineItemCon(timeline, edger, conMaker, input)
126}
127
128func (bugResolver) Actors(_ context.Context, obj models.BugWrapper, after *string, before *string, first *int, last *int) (*models.IdentityConnection, error) {
129 input := models.ConnectionInput{
130 Before: before,
131 After: after,
132 First: first,
133 Last: last,
134 }
135
136 edger := func(actor models.IdentityWrapper, offset int) connections.Edge {
137 return models.IdentityEdge{
138 Node: actor,
139 Cursor: connections.OffsetToCursor(offset),
140 }
141 }
142
143 conMaker := func(edges []*models.IdentityEdge, nodes []models.IdentityWrapper, info *models.PageInfo, totalCount int) (*models.IdentityConnection, error) {
144 return &models.IdentityConnection{
145 Edges: edges,
146 Nodes: nodes,
147 PageInfo: info,
148 TotalCount: totalCount,
149 }, nil
150 }
151
152 actors, err := obj.Actors()
153 if err != nil {
154 return nil, err
155 }
156
157 return connections.IdentityCon(actors, edger, conMaker, input)
158}
159
160func (bugResolver) Participants(_ context.Context, obj models.BugWrapper, after *string, before *string, first *int, last *int) (*models.IdentityConnection, error) {
161 input := models.ConnectionInput{
162 Before: before,
163 After: after,
164 First: first,
165 Last: last,
166 }
167
168 edger := func(participant models.IdentityWrapper, offset int) connections.Edge {
169 return models.IdentityEdge{
170 Node: participant,
171 Cursor: connections.OffsetToCursor(offset),
172 }
173 }
174
175 conMaker := func(edges []*models.IdentityEdge, nodes []models.IdentityWrapper, info *models.PageInfo, totalCount int) (*models.IdentityConnection, error) {
176 return &models.IdentityConnection{
177 Edges: edges,
178 Nodes: nodes,
179 PageInfo: info,
180 TotalCount: totalCount,
181 }, nil
182 }
183
184 participants, err := obj.Participants()
185 if err != nil {
186 return nil, err
187 }
188
189 return connections.IdentityCon(participants, edger, conMaker, input)
190}