aboutsummaryrefslogtreecommitdiffstats
path: root/graphql/resolvers/repo.go
diff options
context:
space:
mode:
Diffstat (limited to 'graphql/resolvers/repo.go')
-rw-r--r--graphql/resolvers/repo.go81
1 files changed, 80 insertions, 1 deletions
diff --git a/graphql/resolvers/repo.go b/graphql/resolvers/repo.go
index c696ff34..9003fbf9 100644
--- a/graphql/resolvers/repo.go
+++ b/graphql/resolvers/repo.go
@@ -6,9 +6,13 @@ import (
"github.com/MichaelMure/git-bug/bug"
"github.com/MichaelMure/git-bug/cache"
"github.com/MichaelMure/git-bug/graphql/connections"
+ "github.com/MichaelMure/git-bug/graphql/graph"
"github.com/MichaelMure/git-bug/graphql/models"
+ "github.com/MichaelMure/git-bug/identity"
)
+var _ graph.RepositoryResolver = &repoResolver{}
+
type repoResolver struct{}
func (repoResolver) AllBugs(ctx context.Context, obj *models.Repository, after *string, before *string, first *int, last *int, queryStr *string) (models.BugConnection, error) {
@@ -70,7 +74,7 @@ func (repoResolver) AllBugs(ctx context.Context, obj *models.Repository, after *
}, nil
}
- return connections.StringCon(source, edger, conMaker, input)
+ return connections.LazyBugCon(source, edger, conMaker, input)
}
func (repoResolver) Bug(ctx context.Context, obj *models.Repository, prefix string) (*bug.Snapshot, error) {
@@ -82,3 +86,78 @@ func (repoResolver) Bug(ctx context.Context, obj *models.Repository, prefix stri
return b.Snapshot(), nil
}
+
+func (repoResolver) AllIdentities(ctx context.Context, obj *models.Repository, after *string, before *string, first *int, last *int) (models.IdentityConnection, error) {
+ input := models.ConnectionInput{
+ Before: before,
+ After: after,
+ First: first,
+ Last: last,
+ }
+
+ // Simply pass a []string with the ids to the pagination algorithm
+ source := obj.Repo.AllIdentityIds()
+
+ // The edger create a custom edge holding just the id
+ edger := func(id string, offset int) connections.Edge {
+ return connections.LazyIdentityEdge{
+ Id: id,
+ Cursor: connections.OffsetToCursor(offset),
+ }
+ }
+
+ // The conMaker will finally load and compile identities from git to replace the selected edges
+ conMaker := func(lazyIdentityEdges []connections.LazyIdentityEdge, lazyNode []string, info models.PageInfo, totalCount int) (models.IdentityConnection, error) {
+ edges := make([]models.IdentityEdge, len(lazyIdentityEdges))
+ nodes := make([]identity.Interface, len(lazyIdentityEdges))
+
+ for k, lazyIdentityEdge := range lazyIdentityEdges {
+ i, err := obj.Repo.ResolveIdentity(lazyIdentityEdge.Id)
+
+ if err != nil {
+ return models.IdentityConnection{}, err
+ }
+
+ ii := identity.Interface(i.Identity)
+
+ edges[k] = models.IdentityEdge{
+ Cursor: lazyIdentityEdge.Cursor,
+ Node: ii,
+ }
+ nodes[k] = ii
+ }
+
+ return models.IdentityConnection{
+ Edges: edges,
+ Nodes: nodes,
+ PageInfo: info,
+ TotalCount: totalCount,
+ }, nil
+ }
+
+ return connections.LazyIdentityCon(source, edger, conMaker, input)
+}
+
+func (repoResolver) Identity(ctx context.Context, obj *models.Repository, prefix string) (*identity.Interface, error) {
+ i, err := obj.Repo.ResolveIdentityPrefix(prefix)
+
+ if err != nil {
+ return nil, err
+ }
+
+ ii := identity.Interface(i.Identity)
+
+ return &ii, nil
+}
+
+func (repoResolver) UserIdentity(ctx context.Context, obj *models.Repository) (*identity.Interface, error) {
+ i, err := obj.Repo.GetUserIdentity()
+
+ if err != nil {
+ return nil, err
+ }
+
+ ii := identity.Interface(i.Identity)
+
+ return &ii, nil
+}