bug.go

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