bug.go

  1package resolvers
  2
  3import (
  4	"context"
  5	"time"
  6
  7	"github.com/MichaelMure/git-bug/bug"
  8	"github.com/MichaelMure/git-bug/graphql/connections"
  9	"github.com/MichaelMure/git-bug/graphql/graph"
 10	"github.com/MichaelMure/git-bug/graphql/models"
 11	"github.com/MichaelMure/git-bug/identity"
 12)
 13
 14var _ graph.BugResolver = &bugResolver{}
 15
 16type bugResolver struct{}
 17
 18func (bugResolver) Status(ctx context.Context, obj *bug.Snapshot) (models.Status, error) {
 19	return convertStatus(obj.Status)
 20}
 21
 22func (bugResolver) Comments(ctx context.Context, obj *bug.Snapshot, after *string, before *string, first *int, last *int) (models.CommentConnection, error) {
 23	input := models.ConnectionInput{
 24		Before: before,
 25		After:  after,
 26		First:  first,
 27		Last:   last,
 28	}
 29
 30	edger := func(comment bug.Comment, offset int) connections.Edge {
 31		return models.CommentEdge{
 32			Node:   comment,
 33			Cursor: connections.OffsetToCursor(offset),
 34		}
 35	}
 36
 37	conMaker := func(edges []models.CommentEdge, nodes []bug.Comment, info models.PageInfo, totalCount int) (models.CommentConnection, error) {
 38		return models.CommentConnection{
 39			Edges:      edges,
 40			Nodes:      nodes,
 41			PageInfo:   info,
 42			TotalCount: totalCount,
 43		}, nil
 44	}
 45
 46	return connections.CommentCon(obj.Comments, edger, conMaker, input)
 47}
 48
 49func (bugResolver) Operations(ctx context.Context, obj *bug.Snapshot, after *string, before *string, first *int, last *int) (models.OperationConnection, error) {
 50	input := models.ConnectionInput{
 51		Before: before,
 52		After:  after,
 53		First:  first,
 54		Last:   last,
 55	}
 56
 57	edger := func(op bug.Operation, offset int) connections.Edge {
 58		return models.OperationEdge{
 59			Node:   op,
 60			Cursor: connections.OffsetToCursor(offset),
 61		}
 62	}
 63
 64	conMaker := func(edges []models.OperationEdge, nodes []bug.Operation, info models.PageInfo, totalCount int) (models.OperationConnection, error) {
 65		return models.OperationConnection{
 66			Edges:      edges,
 67			Nodes:      nodes,
 68			PageInfo:   info,
 69			TotalCount: totalCount,
 70		}, nil
 71	}
 72
 73	return connections.OperationCon(obj.Operations, edger, conMaker, input)
 74}
 75
 76func (bugResolver) Timeline(ctx context.Context, obj *bug.Snapshot, after *string, before *string, first *int, last *int) (models.TimelineItemConnection, error) {
 77	input := models.ConnectionInput{
 78		Before: before,
 79		After:  after,
 80		First:  first,
 81		Last:   last,
 82	}
 83
 84	edger := func(op bug.TimelineItem, offset int) connections.Edge {
 85		return models.TimelineItemEdge{
 86			Node:   op,
 87			Cursor: connections.OffsetToCursor(offset),
 88		}
 89	}
 90
 91	conMaker := func(edges []models.TimelineItemEdge, nodes []bug.TimelineItem, info models.PageInfo, totalCount int) (models.TimelineItemConnection, error) {
 92		return models.TimelineItemConnection{
 93			Edges:      edges,
 94			Nodes:      nodes,
 95			PageInfo:   info,
 96			TotalCount: totalCount,
 97		}, nil
 98	}
 99
100	return connections.TimelineItemCon(obj.Timeline, edger, conMaker, input)
101}
102
103func (bugResolver) LastEdit(ctx context.Context, obj *bug.Snapshot) (time.Time, error) {
104	return obj.LastEditTime(), nil
105}
106
107func (bugResolver) Actors(ctx context.Context, obj *bug.Snapshot) ([]*identity.Interface, error) {
108	actorsp := make([]*identity.Interface, len(obj.Actors))
109
110	for i, actor := range obj.Actors {
111		actorsp[i] = &actor
112	}
113
114	return actorsp, nil
115}
116
117func (bugResolver) Participants(ctx context.Context, obj *bug.Snapshot) ([]*identity.Interface, error) {
118	participantsp := make([]*identity.Interface, len(obj.Participants))
119
120	for i, participant := range obj.Participants {
121		participantsp[i] = &participant
122	}
123
124	return participantsp, nil
125}