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/models"
10)
11
12type bugResolver struct{}
13
14func (bugResolver) Status(ctx context.Context, obj *bug.Snapshot) (models.Status, error) {
15	return convertStatus(obj.Status)
16}
17
18func (bugResolver) Comments(ctx context.Context, obj *bug.Snapshot, after *string, before *string, first *int, last *int) (models.CommentConnection, error) {
19	input := models.ConnectionInput{
20		Before: before,
21		After:  after,
22		First:  first,
23		Last:   last,
24	}
25
26	edger := func(comment bug.Comment, offset int) connections.Edge {
27		return models.CommentEdge{
28			Node:   comment,
29			Cursor: connections.OffsetToCursor(offset),
30		}
31	}
32
33	conMaker := func(edges []models.CommentEdge, nodes []bug.Comment, info models.PageInfo, totalCount int) (models.CommentConnection, error) {
34		return models.CommentConnection{
35			Edges:      edges,
36			Nodes:      nodes,
37			PageInfo:   info,
38			TotalCount: totalCount,
39		}, nil
40	}
41
42	return connections.BugCommentCon(obj.Comments, edger, conMaker, input)
43}
44
45func (bugResolver) Operations(ctx context.Context, obj *bug.Snapshot, after *string, before *string, first *int, last *int) (models.OperationConnection, error) {
46	input := models.ConnectionInput{
47		Before: before,
48		After:  after,
49		First:  first,
50		Last:   last,
51	}
52
53	edger := func(op bug.Operation, offset int) connections.Edge {
54		return models.OperationEdge{
55			Node:   op,
56			Cursor: connections.OffsetToCursor(offset),
57		}
58	}
59
60	conMaker := func(edges []models.OperationEdge, nodes []bug.Operation, info models.PageInfo, totalCount int) (models.OperationConnection, error) {
61		return models.OperationConnection{
62			Edges:      edges,
63			Nodes:      nodes,
64			PageInfo:   info,
65			TotalCount: totalCount,
66		}, nil
67	}
68
69	return connections.BugOperationCon(obj.Operations, edger, conMaker, input)
70}
71
72func (bugResolver) LastEdit(ctx context.Context, obj *bug.Snapshot) (time.Time, error) {
73	return obj.LastEditTime(), nil
74}