aboutsummaryrefslogtreecommitdiffstats
path: root/graphql/resolvers
diff options
context:
space:
mode:
authorMichael Muré <michael.mure@consensys.net>2019-03-31 21:44:14 +0200
committerMichael Muré <batolettre@gmail.com>2019-04-01 14:03:13 +0200
commit15c258cdc4ba37820362a44dfc2636ed1ff92b4c (patch)
tree0790e36bf4846b12b367f12670540eec6ee023f3 /graphql/resolvers
parente028b895aa21553937d732044b7bb0a15c5276f6 (diff)
downloadgit-bug-15c258cdc4ba37820362a44dfc2636ed1ff92b4c.tar.gz
graphql: expose allIdentities, identities and userIdentity in the repo
Diffstat (limited to 'graphql/resolvers')
-rw-r--r--graphql/resolvers/bug.go9
-rw-r--r--graphql/resolvers/identity.go7
-rw-r--r--graphql/resolvers/mutation.go3
-rw-r--r--graphql/resolvers/query.go3
-rw-r--r--graphql/resolvers/repo.go81
-rw-r--r--graphql/resolvers/root.go2
6 files changed, 101 insertions, 4 deletions
diff --git a/graphql/resolvers/bug.go b/graphql/resolvers/bug.go
index 76eed55d..7af04934 100644
--- a/graphql/resolvers/bug.go
+++ b/graphql/resolvers/bug.go
@@ -6,9 +6,12 @@ import (
"github.com/MichaelMure/git-bug/bug"
"github.com/MichaelMure/git-bug/graphql/connections"
+ "github.com/MichaelMure/git-bug/graphql/graph"
"github.com/MichaelMure/git-bug/graphql/models"
)
+var _ graph.BugResolver = &bugResolver{}
+
type bugResolver struct{}
func (bugResolver) Status(ctx context.Context, obj *bug.Snapshot) (models.Status, error) {
@@ -39,7 +42,7 @@ func (bugResolver) Comments(ctx context.Context, obj *bug.Snapshot, after *strin
}, nil
}
- return connections.BugCommentCon(obj.Comments, edger, conMaker, input)
+ return connections.CommentCon(obj.Comments, edger, conMaker, input)
}
func (bugResolver) Operations(ctx context.Context, obj *bug.Snapshot, after *string, before *string, first *int, last *int) (models.OperationConnection, error) {
@@ -66,7 +69,7 @@ func (bugResolver) Operations(ctx context.Context, obj *bug.Snapshot, after *str
}, nil
}
- return connections.BugOperationCon(obj.Operations, edger, conMaker, input)
+ return connections.OperationCon(obj.Operations, edger, conMaker, input)
}
func (bugResolver) Timeline(ctx context.Context, obj *bug.Snapshot, after *string, before *string, first *int, last *int) (models.TimelineItemConnection, error) {
@@ -93,7 +96,7 @@ func (bugResolver) Timeline(ctx context.Context, obj *bug.Snapshot, after *strin
}, nil
}
- return connections.BugTimelineItemCon(obj.Timeline, edger, conMaker, input)
+ return connections.TimelineItemCon(obj.Timeline, edger, conMaker, input)
}
func (bugResolver) LastEdit(ctx context.Context, obj *bug.Snapshot) (time.Time, error) {
diff --git a/graphql/resolvers/identity.go b/graphql/resolvers/identity.go
index d4f9bba2..05f7207e 100644
--- a/graphql/resolvers/identity.go
+++ b/graphql/resolvers/identity.go
@@ -3,15 +3,22 @@ package resolvers
import (
"context"
+ "github.com/MichaelMure/git-bug/graphql/graph"
"github.com/MichaelMure/git-bug/identity"
)
+var _ graph.IdentityResolver = &identityResolver{}
+
type identityResolver struct{}
func (identityResolver) ID(ctx context.Context, obj *identity.Interface) (string, error) {
return (*obj).Id(), nil
}
+func (identityResolver) HumanID(ctx context.Context, obj *identity.Interface) (string, error) {
+ return (*obj).HumanId(), nil
+}
+
func (identityResolver) Name(ctx context.Context, obj *identity.Interface) (*string, error) {
return nilIfEmpty((*obj).Name())
}
diff --git a/graphql/resolvers/mutation.go b/graphql/resolvers/mutation.go
index be6956af..73d39da8 100644
--- a/graphql/resolvers/mutation.go
+++ b/graphql/resolvers/mutation.go
@@ -5,9 +5,12 @@ import (
"github.com/MichaelMure/git-bug/bug"
"github.com/MichaelMure/git-bug/cache"
+ "github.com/MichaelMure/git-bug/graphql/graph"
"github.com/MichaelMure/git-bug/util/git"
)
+var _ graph.MutationResolver = &mutationResolver{}
+
type mutationResolver struct {
cache *cache.MultiRepoCache
}
diff --git a/graphql/resolvers/query.go b/graphql/resolvers/query.go
index b5763b72..80b5a896 100644
--- a/graphql/resolvers/query.go
+++ b/graphql/resolvers/query.go
@@ -4,9 +4,12 @@ import (
"context"
"github.com/MichaelMure/git-bug/cache"
+ "github.com/MichaelMure/git-bug/graphql/graph"
"github.com/MichaelMure/git-bug/graphql/models"
)
+var _ graph.QueryResolver = &rootQueryResolver{}
+
type rootQueryResolver struct {
cache *cache.MultiRepoCache
}
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
+}
diff --git a/graphql/resolvers/root.go b/graphql/resolvers/root.go
index cfdfe346..7414a097 100644
--- a/graphql/resolvers/root.go
+++ b/graphql/resolvers/root.go
@@ -6,6 +6,8 @@ import (
"github.com/MichaelMure/git-bug/graphql/graph"
)
+var _ graph.ResolverRoot = &RootResolver{}
+
type RootResolver struct {
cache.MultiRepoCache
}