git-bug/graphql/resolvers/bug.go

75 lines
2.0 KiB
Go
Raw Normal View History

2018-07-29 19:11:33 +03:00
package resolvers
import (
"context"
"time"
2018-08-13 19:32:11 +03:00
2018-07-29 19:11:33 +03:00
"github.com/MichaelMure/git-bug/bug"
"github.com/MichaelMure/git-bug/graphql/connections"
"github.com/MichaelMure/git-bug/graphql/models"
2018-07-29 19:11:33 +03:00
)
type bugResolver struct{}
2018-07-29 19:11:33 +03:00
func (bugResolver) Status(ctx context.Context, obj *bug.Snapshot) (models.Status, error) {
2018-07-29 19:11:33 +03:00
return convertStatus(obj.Status)
}
func (bugResolver) Comments(ctx context.Context, obj *bug.Snapshot, after *string, before *string, first *int, last *int) (models.CommentConnection, error) {
input := models.ConnectionInput{
Before: before,
After: after,
First: first,
Last: last,
}
edger := func(comment bug.Comment, offset int) connections.Edge {
return models.CommentEdge{
2018-07-29 19:11:33 +03:00
Node: comment,
Cursor: connections.OffsetToCursor(offset),
2018-07-29 19:11:33 +03:00
}
}
conMaker := func(edges []models.CommentEdge, nodes []bug.Comment, info models.PageInfo, totalCount int) (models.CommentConnection, error) {
return models.CommentConnection{
Edges: edges,
Nodes: nodes,
PageInfo: info,
TotalCount: totalCount,
}, nil
2018-07-29 19:11:33 +03:00
}
return connections.BugCommentCon(obj.Comments, edger, conMaker, input)
2018-07-29 19:11:33 +03:00
}
func (bugResolver) Operations(ctx context.Context, obj *bug.Snapshot, after *string, before *string, first *int, last *int) (models.OperationConnection, error) {
input := models.ConnectionInput{
Before: before,
After: after,
First: first,
Last: last,
}
edger := func(op bug.Operation, offset int) connections.Edge {
return models.OperationEdge{
Node: op,
Cursor: connections.OffsetToCursor(offset),
2018-07-29 19:11:33 +03:00
}
}
conMaker := func(edges []models.OperationEdge, nodes []bug.Operation, info models.PageInfo, totalCount int) (models.OperationConnection, error) {
return models.OperationConnection{
Edges: edges,
Nodes: nodes,
PageInfo: info,
TotalCount: totalCount,
}, nil
2018-07-29 19:11:33 +03:00
}
return connections.BugOperationCon(obj.Operations, edger, conMaker, input)
2018-07-29 19:11:33 +03:00
}
func (bugResolver) LastEdit(ctx context.Context, obj *bug.Snapshot) (time.Time, error) {
return obj.LastEditTime(), nil
}