aboutsummaryrefslogtreecommitdiffstats
path: root/graphql/resolvers/bug.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2019-04-05 01:13:17 +0200
committerMichael Muré <batolettre@gmail.com>2019-04-05 01:13:17 +0200
commite027d5ee65aad72ca7cface8e609ea0c65f99fbe (patch)
tree3b67170e86c4158dd2dd4f23f3013641505dac35 /graphql/resolvers/bug.go
parentb9e413c5f95212a0076aae0f473226b32b5fc77a (diff)
downloadgit-bug-e027d5ee65aad72ca7cface8e609ea0c65f99fbe.tar.gz
graphql: make Bug's actors and participants a connection
Diffstat (limited to 'graphql/resolvers/bug.go')
-rw-r--r--graphql/resolvers/bug.go54
1 files changed, 44 insertions, 10 deletions
diff --git a/graphql/resolvers/bug.go b/graphql/resolvers/bug.go
index f48ff0a7..ef35853c 100644
--- a/graphql/resolvers/bug.go
+++ b/graphql/resolvers/bug.go
@@ -104,22 +104,56 @@ func (bugResolver) LastEdit(ctx context.Context, obj *bug.Snapshot) (time.Time,
return obj.LastEditTime(), nil
}
-func (bugResolver) Actors(ctx context.Context, obj *bug.Snapshot) ([]*identity.Interface, error) {
- actorsp := make([]*identity.Interface, len(obj.Actors))
+func (bugResolver) Actors(ctx context.Context, obj *bug.Snapshot, after *string, before *string, first *int, last *int) (models.IdentityConnection, error) {
+ input := models.ConnectionInput{
+ Before: before,
+ After: after,
+ First: first,
+ Last: last,
+ }
- for i, actor := range obj.Actors {
- actorsp[i] = &actor
+ edger := func(actor identity.Interface, offset int) connections.Edge {
+ return models.IdentityEdge{
+ Node: actor,
+ Cursor: connections.OffsetToCursor(offset),
+ }
+ }
+
+ conMaker := func(edges []models.IdentityEdge, nodes []identity.Interface, info models.PageInfo, totalCount int) (models.IdentityConnection, error) {
+ return models.IdentityConnection{
+ Edges: edges,
+ Nodes: nodes,
+ PageInfo: info,
+ TotalCount: totalCount,
+ }, nil
}
- return actorsp, nil
+ return connections.IdentityCon(obj.Actors, edger, conMaker, input)
}
-func (bugResolver) Participants(ctx context.Context, obj *bug.Snapshot) ([]*identity.Interface, error) {
- participantsp := make([]*identity.Interface, len(obj.Participants))
+func (bugResolver) Participants(ctx context.Context, obj *bug.Snapshot, after *string, before *string, first *int, last *int) (models.IdentityConnection, error) {
+ input := models.ConnectionInput{
+ Before: before,
+ After: after,
+ First: first,
+ Last: last,
+ }
- for i, participant := range obj.Participants {
- participantsp[i] = &participant
+ edger := func(participant identity.Interface, offset int) connections.Edge {
+ return models.IdentityEdge{
+ Node: participant,
+ Cursor: connections.OffsetToCursor(offset),
+ }
+ }
+
+ conMaker := func(edges []models.IdentityEdge, nodes []identity.Interface, info models.PageInfo, totalCount int) (models.IdentityConnection, error) {
+ return models.IdentityConnection{
+ Edges: edges,
+ Nodes: nodes,
+ PageInfo: info,
+ TotalCount: totalCount,
+ }, nil
}
- return participantsp, nil
+ return connections.IdentityCon(obj.Participants, edger, conMaker, input)
}