aboutsummaryrefslogtreecommitdiffstats
path: root/graphql/connections/gen_comment.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-08-01 19:24:19 +0200
committerMichael Muré <batolettre@gmail.com>2018-08-01 19:24:19 +0200
commit15f282421941b90e1f62912cf68b7556a8ce7b33 (patch)
tree085c77b22313f1bf4650901de3197f4f200aba28 /graphql/connections/gen_comment.go
parent5830dd88414608b5fc6f5f2b44293b079bce2829 (diff)
downloadgit-bug-15f282421941b90e1f62912cf68b7556a8ce7b33.tar.gz
graphql: simplify the requests with helpers
Diffstat (limited to 'graphql/connections/gen_comment.go')
-rw-r--r--graphql/connections/gen_comment.go18
1 files changed, 13 insertions, 5 deletions
diff --git a/graphql/connections/gen_comment.go b/graphql/connections/gen_comment.go
index dfcce42a..0253e831 100644
--- a/graphql/connections/gen_comment.go
+++ b/graphql/connections/gen_comment.go
@@ -12,13 +12,19 @@ import (
)
type BugCommentEdger func(value bug.Comment, offset int) Edge
-type BugCommentConMaker func(edges []models.CommentEdge, info models.PageInfo, totalCount int) models.CommentConnection
+
+type BugCommentConMaker func(
+ edges []models.CommentEdge,
+ nodes []bug.Comment,
+ info models.PageInfo,
+ totalCount int) (models.CommentConnection, error)
func BugCommentCon(source []bug.Comment, edger BugCommentEdger, conMaker BugCommentConMaker, input models.ConnectionInput) (models.CommentConnection, error) {
+ var nodes []bug.Comment
var edges []models.CommentEdge
var pageInfo models.PageInfo
- emptyCon := conMaker(edges, pageInfo, 0)
+ emptyCon, _ := conMaker(edges, nodes, pageInfo, 0)
offset := 0
@@ -44,9 +50,11 @@ func BugCommentCon(source []bug.Comment, edger BugCommentEdger, conMaker BugComm
}
edges = append(edges, edge.(models.CommentEdge))
+ nodes = append(nodes, value)
}
} else {
edges = make([]models.CommentEdge, len(source))
+ nodes = source
for i, value := range source {
edges[i] = edger(value, i+offset).(models.CommentEdge)
@@ -61,6 +69,7 @@ func BugCommentCon(source []bug.Comment, edger BugCommentEdger, conMaker BugComm
if len(edges) > *input.First {
// Slice result to be of length first by removing edges from the end
edges = edges[:*input.First]
+ nodes = nodes[:*input.First]
pageInfo.HasNextPage = true
}
}
@@ -73,11 +82,10 @@ func BugCommentCon(source []bug.Comment, edger BugCommentEdger, conMaker BugComm
if len(edges) > *input.Last {
// Slice result to be of length last by removing edges from the start
edges = edges[len(edges)-*input.Last:]
+ nodes = nodes[len(nodes)-*input.Last:]
pageInfo.HasPreviousPage = true
}
}
- con := conMaker(edges, pageInfo, len(source))
-
- return con, nil
+ return conMaker(edges, nodes, pageInfo, len(source))
}