1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
|
// This file was automatically generated by genny.
// Any changes will be lost if this file is regenerated.
// see https://github.com/cheekybits/genny
package resolvers
import (
"fmt"
"github.com/MichaelMure/git-bug/bug"
)
type BugCommentEdger func(value bug.Comment, offset int) Edge
func BugCommentPaginate(source []bug.Comment, edger BugCommentEdger, input ConnectionInput) ([]CommentEdge, PageInfo, error) {
var result []CommentEdge
var pageInfo PageInfo
offset := 0
if input.After != nil {
for i, value := range source {
edge := edger(value, i)
if edge.GetCursor() == *input.After {
// remove all previous element including the "after" one
source = source[i+1:]
offset = i + 1
break
}
}
}
if input.Before != nil {
for i, value := range source {
edge := edger(value, i+offset)
if edge.GetCursor() == *input.Before {
// remove all after element including the "before" one
break
}
result = append(result, edge.(CommentEdge))
}
} else {
result = make([]CommentEdge, len(source))
for i, value := range source {
result[i] = edger(value, i+offset).(CommentEdge)
}
}
if input.First != nil {
if *input.First < 0 {
return nil, PageInfo{}, fmt.Errorf("first less than zero")
}
if len(result) > *input.First {
// Slice result to be of length first by removing edges from the end
result = result[:*input.First]
pageInfo.HasNextPage = true
}
}
if input.Last != nil {
if *input.Last < 0 {
return nil, PageInfo{}, fmt.Errorf("last less than zero")
}
if len(result) > *input.Last {
// Slice result to be of length last by removing edges from the start
result = result[len(result)-*input.Last:]
pageInfo.HasPreviousPage = true
}
}
return result, pageInfo, nil
}
// Apply the before/after cursor params to the source and return an array of edges
//func ApplyCursorToEdges(source []interface{}, edger Edger, input ConnectionInput) []Edge {
// var result []Edge
//
// if input.After != nil {
// for i, value := range source {
// edge := edger(value)
// if edge.Cursor() == *input.After {
// // remove all previous element including the "after" one
// source = source[i+1:]
// break
// }
// }
// }
//
// if input.Before != nil {
// for _, value := range source {
// edge := edger(value)
//
// if edge.Cursor() == *input.Before {
// // remove all after element including the "before" one
// break
// }
//
// result = append(result, edge)
// }
// } else {
// result = make([]Edge, len(source))
//
// for i, value := range source {
// result[i] = edger(value)
// }
// }
//
// return result
//}
// Apply the first/last cursor params to the edges
//func EdgesToReturn(edges []Edge, input ConnectionInput) ([]Edge, PageInfo, error) {
// hasPreviousPage := false
// hasNextPage := false
//
// if input.First != nil {
// if *input.First < 0 {
// return nil, nil, fmt.Errorf("first less than zero")
// }
//
// if len(edges) > *input.First {
// // Slice result to be of length first by removing edges from the end
// edges = edges[:*input.First]
// hasNextPage = true
// }
// }
//
// if input.Last != nil {
// if *input.Last < 0 {
// return nil, nil, fmt.Errorf("last less than zero")
// }
//
// if len(edges) > *input.Last {
// // Slice result to be of length last by removing edges from the start
// edges = edges[len(edges)-*input.Last:]
// hasPreviousPage = true
// }
// }
//
// pageInfo := PageInfo{
// HasNextPage: hasNextPage,
// HasPreviousPage: hasPreviousPage,
// }
//
// return edges, pageInfo, nil
//}
//func EdgesToReturn(allEdges []Edge, before *cursor, after *cursor, first *int, last *int) ([]Edge, error) {
// result := ApplyCursorToEdges(allEdges, before, after)
//
// if first != nil {
// if *first < 0 {
// return nil, fmt.Errorf("first less than zero")
// }
//
// if len(result) > *first {
// // Slice result to be of length first by removing edges from the end
// result = result[:*first]
// }
// }
//
// if last != nil {
// if *last < 0 {
// return nil, fmt.Errorf("last less than zero")
// }
//
// if len(result) > *last {
// // Slice result to be of length last by removing edges from the start
// result = result[len(result)-*last:]
// }
// }
//
// return result, nil
//}
//func ApplyCursorToEdges(allEdges []Edge, before *cursor, after *cursor) []Edge {
// result := allEdges
//
// if after != nil {
// for i, edge := range result {
// if edge.Cursor() == *after {
// // remove all previous element including the "after" one
// result = result[i+1:]
// break
// }
// }
// }
//
// if before != nil {
// for i, edge := range result {
// if edge.Cursor() == *before {
// // remove all after element including the "before" one
// result = result[:i]
// }
// }
// }
//
// return result
//}
//func HasPreviousPage(allEdges []Edge, before *cursor, after *cursor, last *int) bool {
// if last != nil {
// edges := ApplyCursorToEdges(allEdges, before, after)
// return len(edges) > *last
// }
//
// // TODO: handle "after", but according to the spec it's ok to return false
//
// return false
//}
//
//func HasNextPage(allEdges []Edge, before *cursor, after *cursor, first *int) bool {
// if first != nil {
// edges := ApplyCursorToEdges(allEdges, before, after)
// return len(edges) > *first
// }
//
// // TODO: handle "before", but according to the spec it's ok to return false
//
// return false
|