2018-07-29 19:11:33 +03:00
|
|
|
package resolvers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"github.com/MichaelMure/git-bug/bug"
|
2018-07-29 20:37:06 +03:00
|
|
|
"github.com/MichaelMure/git-bug/graphql/connections"
|
|
|
|
"github.com/MichaelMure/git-bug/graphql/models"
|
2018-07-29 19:11:33 +03:00
|
|
|
)
|
|
|
|
|
2018-07-30 00:48:52 +03:00
|
|
|
type bugResolver struct{}
|
2018-07-29 19:11:33 +03:00
|
|
|
|
2018-07-29 20:37:06 +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)
|
|
|
|
}
|
|
|
|
|
2018-08-01 20:24:19 +03:00
|
|
|
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,
|
|
|
|
}
|
|
|
|
|
2018-07-29 20:37:06 +03:00
|
|
|
edger := func(comment bug.Comment, offset int) connections.Edge {
|
|
|
|
return models.CommentEdge{
|
2018-07-29 19:11:33 +03:00
|
|
|
Node: comment,
|
2018-07-29 20:37:06 +03:00
|
|
|
Cursor: connections.OffsetToCursor(offset),
|
2018-07-29 19:11:33 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-01 20:24:19 +03:00
|
|
|
conMaker := func(edges []models.CommentEdge, nodes []bug.Comment, info models.PageInfo, totalCount int) (models.CommentConnection, error) {
|
2018-07-29 20:37:06 +03:00
|
|
|
return models.CommentConnection{
|
|
|
|
Edges: edges,
|
2018-08-01 20:24:19 +03:00
|
|
|
Nodes: nodes,
|
2018-07-29 20:37:06 +03:00
|
|
|
PageInfo: info,
|
|
|
|
TotalCount: totalCount,
|
2018-08-01 20:24:19 +03:00
|
|
|
}, nil
|
2018-07-29 19:11:33 +03:00
|
|
|
}
|
|
|
|
|
2018-07-29 20:37:06 +03:00
|
|
|
return connections.BugCommentCon(obj.Comments, edger, conMaker, input)
|
2018-07-29 19:11:33 +03:00
|
|
|
}
|
|
|
|
|
2018-08-01 20:24:19 +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,
|
|
|
|
}
|
|
|
|
|
2018-07-29 20:37:06 +03:00
|
|
|
edger := func(op bug.Operation, offset int) connections.Edge {
|
|
|
|
return models.OperationEdge{
|
2018-08-01 20:24:19 +03:00
|
|
|
Node: op,
|
2018-07-29 20:37:06 +03:00
|
|
|
Cursor: connections.OffsetToCursor(offset),
|
2018-07-29 19:11:33 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-01 20:24:19 +03:00
|
|
|
conMaker := func(edges []models.OperationEdge, nodes []bug.Operation, info models.PageInfo, totalCount int) (models.OperationConnection, error) {
|
2018-07-29 20:37:06 +03:00
|
|
|
return models.OperationConnection{
|
|
|
|
Edges: edges,
|
2018-08-01 20:24:19 +03:00
|
|
|
Nodes: nodes,
|
2018-07-29 20:37:06 +03:00
|
|
|
PageInfo: info,
|
|
|
|
TotalCount: totalCount,
|
2018-08-01 20:24:19 +03:00
|
|
|
}, nil
|
2018-07-29 19:11:33 +03:00
|
|
|
}
|
|
|
|
|
2018-07-29 20:37:06 +03:00
|
|
|
return connections.BugOperationCon(obj.Operations, edger, conMaker, input)
|
2018-07-29 19:11:33 +03:00
|
|
|
}
|