aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2020-02-12 21:03:20 +0100
committerMichael Muré <batolettre@gmail.com>2020-02-12 21:03:20 +0100
commit929480fa0a7fa40ba14850aed17158a20cdf6391 (patch)
tree7bc0579469f936a9378be0b4c95fc149b1df5efe
parentb70b4ba4b17d02d9744bd72494549f5cf7d980f8 (diff)
downloadgit-bug-929480fa0a7fa40ba14850aed17158a20cdf6391.tar.gz
graphql: expose the name of Repository
-rw-r--r--cache/repo_cache.go12
-rw-r--r--graphql/graph/gen_graph.go56
-rw-r--r--graphql/resolvers/repo.go7
-rw-r--r--graphql/schema/repository.graphql5
4 files changed, 77 insertions, 3 deletions
diff --git a/cache/repo_cache.go b/cache/repo_cache.go
index c8d6bd69..395fb662 100644
--- a/cache/repo_cache.go
+++ b/cache/repo_cache.go
@@ -58,6 +58,9 @@ type RepoCache struct {
// the underlying repo
repo repository.ClockedRepo
+ // the name of the repository, as defined in the MultiRepoCache
+ name string
+
muBug sync.RWMutex
// excerpt of bugs data for all bugs
bugExcerpts map[entity.Id]*BugExcerpt
@@ -75,8 +78,13 @@ type RepoCache struct {
}
func NewRepoCache(r repository.ClockedRepo) (*RepoCache, error) {
+ return NewNamedRepoCache(r, "")
+}
+
+func NewNamedRepoCache(r repository.ClockedRepo, name string) (*RepoCache, error) {
c := &RepoCache{
repo: r,
+ name: name,
bugs: make(map[entity.Id]*BugCache),
identities: make(map[entity.Id]*IdentityCache),
}
@@ -102,6 +110,10 @@ func NewRepoCache(r repository.ClockedRepo) (*RepoCache, error) {
return c, c.write()
}
+func (c *RepoCache) Name() string {
+ return c.name
+}
+
// LocalConfig give access to the repository scoped configuration
func (c *RepoCache) LocalConfig() repository.Config {
return c.repo.LocalConfig()
diff --git a/graphql/graph/gen_graph.go b/graphql/graph/gen_graph.go
index ba1eb7e9..e9cb2486 100644
--- a/graphql/graph/gen_graph.go
+++ b/graphql/graph/gen_graph.go
@@ -314,6 +314,7 @@ type ComplexityRoot struct {
AllIdentities func(childComplexity int, after *string, before *string, first *int, last *int) int
Bug func(childComplexity int, prefix string) int
Identity func(childComplexity int, prefix string) int
+ Name func(childComplexity int) int
UserIdentity func(childComplexity int) int
ValidLabels func(childComplexity int, after *string, before *string, first *int, last *int) int
}
@@ -454,6 +455,7 @@ type QueryResolver interface {
Repository(ctx context.Context, ref *string) (*models.Repository, error)
}
type RepositoryResolver interface {
+ Name(ctx context.Context, obj *models.Repository) (*string, error)
AllBugs(ctx context.Context, obj *models.Repository, after *string, before *string, first *int, last *int, query *string) (*models.BugConnection, error)
Bug(ctx context.Context, obj *models.Repository, prefix string) (models.BugWrapper, error)
AllIdentities(ctx context.Context, obj *models.Repository, after *string, before *string, first *int, last *int) (*models.IdentityConnection, error)
@@ -1597,6 +1599,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
return e.complexity.Repository.Identity(childComplexity, args["prefix"].(string)), true
+ case "Repository.name":
+ if e.complexity.Repository.Name == nil {
+ break
+ }
+
+ return e.complexity.Repository.Name(childComplexity), true
+
case "Repository.userIdentity":
if e.complexity.Repository.UserIdentity == nil {
break
@@ -2311,6 +2320,9 @@ type LabelChangeOperation implements Operation & Authored {
`, BuiltIn: false},
&ast.Source{Name: "schema/repository.graphql", Input: `
type Repository {
+ """The name of the repository"""
+ name: String
+
"""All the bugs"""
allBugs(
"""Returns the elements in the list that come after the specified cursor."""
@@ -2321,7 +2333,7 @@ type Repository {
first: Int
"""Returns the last _n_ elements from the list."""
last: Int
- """A query to select and order bugs"""
+ """A query to select and order bugs."""
query: String
): BugConnection!
@@ -7915,6 +7927,37 @@ func (ec *executionContext) _Query___schema(ctx context.Context, field graphql.C
return ec.marshalO__Schema2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐSchema(ctx, field.Selections, res)
}
+func (ec *executionContext) _Repository_name(ctx context.Context, field graphql.CollectedField, obj *models.Repository) (ret graphql.Marshaler) {
+ defer func() {
+ if r := recover(); r != nil {
+ ec.Error(ctx, ec.Recover(ctx, r))
+ ret = graphql.Null
+ }
+ }()
+ fc := &graphql.FieldContext{
+ Object: "Repository",
+ Field: field,
+ Args: nil,
+ IsMethod: true,
+ }
+
+ ctx = graphql.WithFieldContext(ctx, fc)
+ resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
+ ctx = rctx // use context from middleware stack in children
+ return ec.resolvers.Repository().Name(rctx, obj)
+ })
+ if err != nil {
+ ec.Error(ctx, err)
+ return graphql.Null
+ }
+ if resTmp == nil {
+ return graphql.Null
+ }
+ res := resTmp.(*string)
+ fc.Result = res
+ return ec.marshalOString2ᚖstring(ctx, field.Selections, res)
+}
+
func (ec *executionContext) _Repository_allBugs(ctx context.Context, field graphql.CollectedField, obj *models.Repository) (ret graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
@@ -12385,6 +12428,17 @@ func (ec *executionContext) _Repository(ctx context.Context, sel ast.SelectionSe
switch field.Name {
case "__typename":
out.Values[i] = graphql.MarshalString("Repository")
+ case "name":
+ field := field
+ out.Concurrently(i, func() (res graphql.Marshaler) {
+ defer func() {
+ if r := recover(); r != nil {
+ ec.Error(ctx, ec.Recover(ctx, r))
+ }
+ }()
+ res = ec._Repository_name(ctx, field, obj)
+ return res
+ })
case "allBugs":
field := field
out.Concurrently(i, func() (res graphql.Marshaler) {
diff --git a/graphql/resolvers/repo.go b/graphql/resolvers/repo.go
index 3b0aa9a1..d090544d 100644
--- a/graphql/resolvers/repo.go
+++ b/graphql/resolvers/repo.go
@@ -15,6 +15,11 @@ var _ graph.RepositoryResolver = &repoResolver{}
type repoResolver struct{}
+func (repoResolver) Name(_ context.Context, obj *models.Repository) (*string, error) {
+ name := obj.Repo.Name()
+ return &name, nil
+}
+
func (repoResolver) AllBugs(_ context.Context, obj *models.Repository, after *string, before *string, first *int, last *int, queryStr *string) (*models.BugConnection, error) {
input := models.ConnectionInput{
Before: before,
@@ -153,7 +158,7 @@ func (repoResolver) UserIdentity(_ context.Context, obj *models.Repository) (mod
return models.NewLazyIdentity(obj.Repo, excerpt), nil
}
-func (resolver repoResolver) ValidLabels(_ context.Context, obj *models.Repository, after *string, before *string, first *int, last *int) (*models.LabelConnection, error) {
+func (repoResolver) ValidLabels(_ context.Context, obj *models.Repository, after *string, before *string, first *int, last *int) (*models.LabelConnection, error) {
input := models.ConnectionInput{
Before: before,
After: after,
diff --git a/graphql/schema/repository.graphql b/graphql/schema/repository.graphql
index 20a3cf0b..2b98fe37 100644
--- a/graphql/schema/repository.graphql
+++ b/graphql/schema/repository.graphql
@@ -1,5 +1,8 @@
type Repository {
+ """The name of the repository"""
+ name: String
+
"""All the bugs"""
allBugs(
"""Returns the elements in the list that come after the specified cursor."""
@@ -10,7 +13,7 @@ type Repository {
first: Int
"""Returns the last _n_ elements from the list."""
last: Int
- """A query to select and order bugs"""
+ """A query to select and order bugs."""
query: String
): BugConnection!