diff options
author | Michael Muré <batolettre@gmail.com> | 2018-08-01 19:24:19 +0200 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2018-08-01 19:24:19 +0200 |
commit | 15f282421941b90e1f62912cf68b7556a8ce7b33 (patch) | |
tree | 085c77b22313f1bf4650901de3197f4f200aba28 /graphql/connections/gen_operation.go | |
parent | 5830dd88414608b5fc6f5f2b44293b079bce2829 (diff) | |
download | git-bug-15f282421941b90e1f62912cf68b7556a8ce7b33.tar.gz |
graphql: simplify the requests with helpers
Diffstat (limited to 'graphql/connections/gen_operation.go')
-rw-r--r-- | graphql/connections/gen_operation.go | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/graphql/connections/gen_operation.go b/graphql/connections/gen_operation.go index 32cee97a..26936dfe 100644 --- a/graphql/connections/gen_operation.go +++ b/graphql/connections/gen_operation.go @@ -12,13 +12,19 @@ import ( ) type BugOperationEdger func(value bug.Operation, offset int) Edge -type BugOperationConMaker func(edges []models.OperationEdge, info models.PageInfo, totalCount int) models.OperationConnection + +type BugOperationConMaker func( + edges []models.OperationEdge, + nodes []bug.Operation, + info models.PageInfo, + totalCount int) (models.OperationConnection, error) func BugOperationCon(source []bug.Operation, edger BugOperationEdger, conMaker BugOperationConMaker, input models.ConnectionInput) (models.OperationConnection, error) { + var nodes []bug.Operation var edges []models.OperationEdge var pageInfo models.PageInfo - emptyCon := conMaker(edges, pageInfo, 0) + emptyCon, _ := conMaker(edges, nodes, pageInfo, 0) offset := 0 @@ -44,9 +50,11 @@ func BugOperationCon(source []bug.Operation, edger BugOperationEdger, conMaker B } edges = append(edges, edge.(models.OperationEdge)) + nodes = append(nodes, value) } } else { edges = make([]models.OperationEdge, len(source)) + nodes = source for i, value := range source { edges[i] = edger(value, i+offset).(models.OperationEdge) @@ -61,6 +69,7 @@ func BugOperationCon(source []bug.Operation, edger BugOperationEdger, conMaker B 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 BugOperationCon(source []bug.Operation, edger BugOperationEdger, conMaker B 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)) } |