aboutsummaryrefslogtreecommitdiffstats
path: root/graphql/connections/gen_bug.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_bug.go
parent5830dd88414608b5fc6f5f2b44293b079bce2829 (diff)
downloadgit-bug-15f282421941b90e1f62912cf68b7556a8ce7b33.tar.gz
graphql: simplify the requests with helpers
Diffstat (limited to 'graphql/connections/gen_bug.go')
-rw-r--r--graphql/connections/gen_bug.go16
1 files changed, 13 insertions, 3 deletions
diff --git a/graphql/connections/gen_bug.go b/graphql/connections/gen_bug.go
index 64458669..9224c696 100644
--- a/graphql/connections/gen_bug.go
+++ b/graphql/connections/gen_bug.go
@@ -11,13 +11,19 @@ import (
)
type StringEdger func(value string, offset int) Edge
-type StringConMaker func(edges []LazyBugEdge, info models.PageInfo, totalCount int) (models.BugConnection, error)
+
+type StringConMaker func(
+ edges []LazyBugEdge,
+ nodes []string,
+ info models.PageInfo,
+ totalCount int) (models.BugConnection, error)
func StringCon(source []string, edger StringEdger, conMaker StringConMaker, input models.ConnectionInput) (models.BugConnection, error) {
+ var nodes []string
var edges []LazyBugEdge
var pageInfo models.PageInfo
- emptyCon, _ := conMaker(edges, pageInfo, 0)
+ emptyCon, _ := conMaker(edges, nodes, pageInfo, 0)
offset := 0
@@ -43,9 +49,11 @@ func StringCon(source []string, edger StringEdger, conMaker StringConMaker, inpu
}
edges = append(edges, edge.(LazyBugEdge))
+ nodes = append(nodes, value)
}
} else {
edges = make([]LazyBugEdge, len(source))
+ nodes = source
for i, value := range source {
edges[i] = edger(value, i+offset).(LazyBugEdge)
@@ -60,6 +68,7 @@ func StringCon(source []string, edger StringEdger, conMaker StringConMaker, inpu
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
}
}
@@ -72,9 +81,10 @@ func StringCon(source []string, edger StringEdger, conMaker StringConMaker, inpu
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
}
}
- return conMaker(edges, pageInfo, len(source))
+ return conMaker(edges, nodes, pageInfo, len(source))
}