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) ID(ctx context.Context, obj *bug.Snapshot) (string, error) {
 19	return obj.Id().String(), nil
 20}
 21
 22func (bugResolver) HumanID(ctx context.Context, obj *bug.Snapshot) (string, error) {
 23	return obj.Id().Human(), nil
 24}
 25
 26func (bugResolver) Status(ctx context.Context, obj *bug.Snapshot) (models.Status, error) {
 27	return convertStatus(obj.Status)
 28}
 29
 30func (bugResolver) Comments(ctx context.Context, obj *bug.Snapshot, after *string, before *string, first *int, last *int) (*models.CommentConnection, error) {
 31	input := models.ConnectionInput{
 32		Before: before,
 33		After:  after,
 34		First:  first,
 35		Last:   last,
 36	}
 37
 38	edger := func(comment bug.Comment, offset int) connections.Edge {
 39		return models.CommentEdge{
 40			Node:   &comment,
 41			Cursor: connections.OffsetToCursor(offset),
 42		}
 43	}
 44
 45	conMaker := func(edges []*models.CommentEdge, nodes []bug.Comment, info *models.PageInfo, totalCount int) (*models.CommentConnection, error) {
 46		var commentNodes []*bug.Comment
 47		for _, c := range nodes {
 48			commentNodes = append(commentNodes, &c)
 49		}
 50		return &models.CommentConnection{
 51			Edges:      edges,
 52			Nodes:      commentNodes,
 53			PageInfo:   info,
 54			TotalCount: totalCount,
 55		}, nil
 56	}
 57
 58	return connections.CommentCon(obj.Comments, edger, conMaker, input)
 59}
 60
 61func (bugResolver) Operations(ctx context.Context, obj *bug.Snapshot, after *string, before *string, first *int, last *int) (*models.OperationConnection, error) {
 62	input := models.ConnectionInput{
 63		Before: before,
 64		After:  after,
 65		First:  first,
 66		Last:   last,
 67	}
 68
 69	edger := func(op bug.Operation, offset int) connections.Edge {
 70		return models.OperationEdge{
 71			Node:   op,
 72			Cursor: connections.OffsetToCursor(offset),
 73		}
 74	}
 75
 76	conMaker := func(edges []*models.OperationEdge, nodes []bug.Operation, info *models.PageInfo, totalCount int) (*models.OperationConnection, error) {
 77		return &models.OperationConnection{
 78			Edges:      edges,
 79			Nodes:      nodes,
 80			PageInfo:   info,
 81			TotalCount: totalCount,
 82		}, nil
 83	}
 84
 85	return connections.OperationCon(obj.Operations, edger, conMaker, input)
 86}
 87
 88func (bugResolver) Timeline(ctx context.Context, obj *bug.Snapshot, after *string, before *string, first *int, last *int) (*models.TimelineItemConnection, error) {
 89	input := models.ConnectionInput{
 90		Before: before,
 91		After:  after,
 92		First:  first,
 93		Last:   last,
 94	}
 95
 96	edger := func(op bug.TimelineItem, offset int) connections.Edge {
 97		return models.TimelineItemEdge{
 98			Node:   op,
 99			Cursor: connections.OffsetToCursor(offset),
100		}
101	}
102
103	conMaker := func(edges []*models.TimelineItemEdge, nodes []bug.TimelineItem, info *models.PageInfo, totalCount int) (*models.TimelineItemConnection, error) {
104		return &models.TimelineItemConnection{
105			Edges:      edges,
106			Nodes:      nodes,
107			PageInfo:   info,
108			TotalCount: totalCount,
109		}, nil
110	}
111
112	return connections.TimelineItemCon(obj.Timeline, edger, conMaker, input)
113}
114
115func (bugResolver) LastEdit(ctx context.Context, obj *bug.Snapshot) (*time.Time, error) {
116	t := obj.LastEditTime()
117	return &t, nil
118}
119
120func (bugResolver) Actors(ctx context.Context, obj *bug.Snapshot, after *string, before *string, first *int, last *int) (*models.IdentityConnection, error) {
121	input := models.ConnectionInput{
122		Before: before,
123		After:  after,
124		First:  first,
125		Last:   last,
126	}
127
128	edger := func(actor identity.Interface, offset int) connections.Edge {
129		return models.IdentityEdge{
130			Node:   actor,
131			Cursor: connections.OffsetToCursor(offset),
132		}
133	}
134
135	conMaker := func(edges []*models.IdentityEdge, nodes []identity.Interface, info *models.PageInfo, totalCount int) (*models.IdentityConnection, error) {
136		return &models.IdentityConnection{
137			Edges:      edges,
138			Nodes:      nodes,
139			PageInfo:   info,
140			TotalCount: totalCount,
141		}, nil
142	}
143
144	return connections.IdentityCon(obj.Actors, edger, conMaker, input)
145}
146
147func (bugResolver) Participants(ctx context.Context, obj *bug.Snapshot, after *string, before *string, first *int, last *int) (*models.IdentityConnection, error) {
148	input := models.ConnectionInput{
149		Before: before,
150		After:  after,
151		First:  first,
152		Last:   last,
153	}
154
155	edger := func(participant identity.Interface, offset int) connections.Edge {
156		return models.IdentityEdge{
157			Node:   participant,
158			Cursor: connections.OffsetToCursor(offset),
159		}
160	}
161
162	conMaker := func(edges []*models.IdentityEdge, nodes []identity.Interface, info *models.PageInfo, totalCount int) (*models.IdentityConnection, error) {
163		return &models.IdentityConnection{
164			Edges:      edges,
165			Nodes:      nodes,
166			PageInfo:   info,
167			TotalCount: totalCount,
168		}, nil
169	}
170
171	return connections.IdentityCon(obj.Participants, edger, conMaker, input)
172}