From e027d5ee65aad72ca7cface8e609ea0c65f99fbe Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Fri, 5 Apr 2019 01:13:17 +0200 Subject: graphql: make Bug's actors and participants a connection --- graphql/resolvers/bug.go | 54 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 44 insertions(+), 10 deletions(-) (limited to 'graphql/resolvers') 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) } -- cgit