bug.go

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