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