aboutsummaryrefslogtreecommitdiffstats
path: root/graphql/resolvers
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/resolvers
parent5830dd88414608b5fc6f5f2b44293b079bce2829 (diff)
downloadgit-bug-15f282421941b90e1f62912cf68b7556a8ce7b33.tar.gz
graphql: simplify the requests with helpers
Diffstat (limited to 'graphql/resolvers')
-rw-r--r--graphql/resolvers/bug.go30
-rw-r--r--graphql/resolvers/repo.go20
2 files changed, 34 insertions, 16 deletions
diff --git a/graphql/resolvers/bug.go b/graphql/resolvers/bug.go
index dfb5c913..014a0f31 100644
--- a/graphql/resolvers/bug.go
+++ b/graphql/resolvers/bug.go
@@ -13,7 +13,14 @@ func (bugResolver) Status(ctx context.Context, obj *bug.Snapshot) (models.Status
return convertStatus(obj.Status)
}
-func (bugResolver) Comments(ctx context.Context, obj *bug.Snapshot, input models.ConnectionInput) (models.CommentConnection, error) {
+func (bugResolver) Comments(ctx context.Context, obj *bug.Snapshot, after *string, before *string, first *int, last *int) (models.CommentConnection, error) {
+ input := models.ConnectionInput{
+ Before: before,
+ After: after,
+ First: first,
+ Last: last,
+ }
+
edger := func(comment bug.Comment, offset int) connections.Edge {
return models.CommentEdge{
Node: comment,
@@ -21,31 +28,40 @@ func (bugResolver) Comments(ctx context.Context, obj *bug.Snapshot, input models
}
}
- conMaker := func(edges []models.CommentEdge, info models.PageInfo, totalCount int) models.CommentConnection {
+ conMaker := func(edges []models.CommentEdge, nodes []bug.Comment, info models.PageInfo, totalCount int) (models.CommentConnection, error) {
return models.CommentConnection{
Edges: edges,
+ Nodes: nodes,
PageInfo: info,
TotalCount: totalCount,
- }
+ }, nil
}
return connections.BugCommentCon(obj.Comments, edger, conMaker, input)
}
-func (bugResolver) Operations(ctx context.Context, obj *bug.Snapshot, input models.ConnectionInput) (models.OperationConnection, error) {
+func (bugResolver) Operations(ctx context.Context, obj *bug.Snapshot, after *string, before *string, first *int, last *int) (models.OperationConnection, error) {
+ input := models.ConnectionInput{
+ Before: before,
+ After: after,
+ First: first,
+ Last: last,
+ }
+
edger := func(op bug.Operation, offset int) connections.Edge {
return models.OperationEdge{
- Node: op.(models.Operation),
+ Node: op,
Cursor: connections.OffsetToCursor(offset),
}
}
- conMaker := func(edges []models.OperationEdge, info models.PageInfo, totalCount int) models.OperationConnection {
+ conMaker := func(edges []models.OperationEdge, nodes []bug.Operation, info models.PageInfo, totalCount int) (models.OperationConnection, error) {
return models.OperationConnection{
Edges: edges,
+ Nodes: nodes,
PageInfo: info,
TotalCount: totalCount,
- }
+ }, nil
}
return connections.BugOperationCon(obj.Operations, edger, conMaker, input)
diff --git a/graphql/resolvers/repo.go b/graphql/resolvers/repo.go
index 2e2872e2..388f28f5 100644
--- a/graphql/resolvers/repo.go
+++ b/graphql/resolvers/repo.go
@@ -9,7 +9,13 @@ import (
type repoResolver struct{}
-func (repoResolver) AllBugs(ctx context.Context, obj *models.Repository, input models.ConnectionInput) (models.BugConnection, error) {
+func (repoResolver) AllBugs(ctx context.Context, obj *models.Repository, after *string, before *string, first *int, last *int) (models.BugConnection, error) {
+ input := models.ConnectionInput{
+ Before: before,
+ After: after,
+ First: first,
+ Last: last,
+ }
// Simply pass a []string with the ids to the pagination algorithm
source, err := obj.Repo.AllBugIds()
@@ -27,8 +33,9 @@ func (repoResolver) AllBugs(ctx context.Context, obj *models.Repository, input m
}
// The conMaker will finally load and compile bugs from git to replace the selected edges
- conMaker := func(lazyBugEdges []connections.LazyBugEdge, info models.PageInfo, totalCount int) (models.BugConnection, error) {
+ conMaker := func(lazyBugEdges []connections.LazyBugEdge, lazyNode []string, info models.PageInfo, totalCount int) (models.BugConnection, error) {
edges := make([]models.BugEdge, len(lazyBugEdges))
+ nodes := make([]bug.Snapshot, len(lazyBugEdges))
for i, lazyBugEdge := range lazyBugEdges {
b, err := obj.Repo.ResolveBug(lazyBugEdge.Id)
@@ -43,10 +50,12 @@ func (repoResolver) AllBugs(ctx context.Context, obj *models.Repository, input m
Cursor: lazyBugEdge.Cursor,
Node: *snap,
}
+ nodes[i] = *snap
}
return models.BugConnection{
Edges: edges,
+ Nodes: nodes,
PageInfo: info,
TotalCount: totalCount,
}, nil
@@ -64,10 +73,3 @@ func (repoResolver) Bug(ctx context.Context, obj *models.Repository, prefix stri
return b.Snapshot(), nil
}
-
-func (repoResolver) Mutation(ctx context.Context, obj *models.Repository) (models.RepositoryMutation, error) {
- return models.RepositoryMutation{
- Repo: obj.Repo,
- Cache: obj.Cache,
- }, nil
-}