bug.go

 1package resolvers
 2
 3import (
 4	"context"
 5	"github.com/MichaelMure/git-bug/bug"
 6	"github.com/MichaelMure/git-bug/cache"
 7)
 8
 9type bugResolver struct {
10	cache cache.Cacher
11}
12
13func (bugResolver) Status(ctx context.Context, obj *bug.Snapshot) (Status, error) {
14	return convertStatus(obj.Status)
15}
16
17func (bugResolver) Comments(ctx context.Context, obj *bug.Snapshot, input ConnectionInput) (CommentConnection, error) {
18	var connection CommentConnection
19
20	edger := func(comment bug.Comment, offset int) Edge {
21		return CommentEdge{
22			Node:   comment,
23			Cursor: offsetToCursor(offset),
24		}
25	}
26
27	edges, pageInfo, err := BugCommentPaginate(obj.Comments, edger, input)
28
29	if err != nil {
30		return connection, err
31	}
32
33	connection.Edges = edges
34	connection.PageInfo = pageInfo
35	connection.TotalCount = len(obj.Comments)
36
37	return connection, nil
38}
39
40func (bugResolver) Operations(ctx context.Context, obj *bug.Snapshot, input ConnectionInput) (OperationConnection, error) {
41	var connection OperationConnection
42
43	edger := func(op bug.Operation, offset int) Edge {
44		return OperationEdge{
45			Node:   op.(OperationUnion),
46			Cursor: offsetToCursor(offset),
47		}
48	}
49
50	edges, pageInfo, err := BugOperationPaginate(obj.Operations, edger, input)
51
52	if err != nil {
53		return connection, err
54	}
55
56	connection.Edges = edges
57	connection.PageInfo = pageInfo
58	connection.TotalCount = len(obj.Operations)
59
60	return connection, nil
61}