aboutsummaryrefslogtreecommitdiffstats
path: root/graphql
diff options
context:
space:
mode:
Diffstat (limited to 'graphql')
-rw-r--r--graphql/gqlgen.yml2
-rw-r--r--graphql/graph/gen_graph.go129
-rw-r--r--graphql/models/models.go9
-rw-r--r--graphql/resolvers/repo.go7
-rw-r--r--graphql/resolvers/repo_mutation.go20
-rw-r--r--graphql/resolvers/root.go4
-rw-r--r--graphql/schema.graphql7
7 files changed, 176 insertions, 2 deletions
diff --git a/graphql/gqlgen.yml b/graphql/gqlgen.yml
index 19800bd9..c4f395ab 100644
--- a/graphql/gqlgen.yml
+++ b/graphql/gqlgen.yml
@@ -7,6 +7,8 @@ model:
models:
Repository:
model: github.com/MichaelMure/git-bug/graphql/models.Repository
+ RepositoryMutation:
+ model: github.com/MichaelMure/git-bug/graphql/models.RepositoryMutation
Bug:
model: github.com/MichaelMure/git-bug/bug.Snapshot
Comment:
diff --git a/graphql/graph/gen_graph.go b/graphql/graph/gen_graph.go
index b747e9d4..01887dc8 100644
--- a/graphql/graph/gen_graph.go
+++ b/graphql/graph/gen_graph.go
@@ -45,6 +45,8 @@ type Resolvers interface {
Repository_allBugs(ctx context.Context, obj *models.Repository, input models.ConnectionInput) (models.BugConnection, error)
Repository_bug(ctx context.Context, obj *models.Repository, prefix string) (*bug.Snapshot, error)
+ Repository_mutation(ctx context.Context, obj *models.Repository) (models.RepositoryMutation, error)
+ RepositoryMutation_newBug(ctx context.Context, obj *models.RepositoryMutation, title string, message string) (bug.Snapshot, error)
SetStatusOperation_date(ctx context.Context, obj *operations.SetStatusOperation) (time.Time, error)
SetStatusOperation_status(ctx context.Context, obj *operations.SetStatusOperation) (models.Status, error)
@@ -59,6 +61,7 @@ type ResolverRoot interface {
LabelChangeOperation() LabelChangeOperationResolver
Query() QueryResolver
Repository() RepositoryResolver
+ RepositoryMutation() RepositoryMutationResolver
SetStatusOperation() SetStatusOperationResolver
SetTitleOperation() SetTitleOperationResolver
}
@@ -84,6 +87,10 @@ type QueryResolver interface {
type RepositoryResolver interface {
AllBugs(ctx context.Context, obj *models.Repository, input models.ConnectionInput) (models.BugConnection, error)
Bug(ctx context.Context, obj *models.Repository, prefix string) (*bug.Snapshot, error)
+ Mutation(ctx context.Context, obj *models.Repository) (models.RepositoryMutation, error)
+}
+type RepositoryMutationResolver interface {
+ NewBug(ctx context.Context, obj *models.RepositoryMutation, title string, message string) (bug.Snapshot, error)
}
type SetStatusOperationResolver interface {
Date(ctx context.Context, obj *operations.SetStatusOperation) (time.Time, error)
@@ -137,6 +144,14 @@ func (s shortMapper) Repository_bug(ctx context.Context, obj *models.Repository,
return s.r.Repository().Bug(ctx, obj, prefix)
}
+func (s shortMapper) Repository_mutation(ctx context.Context, obj *models.Repository) (models.RepositoryMutation, error) {
+ return s.r.Repository().Mutation(ctx, obj)
+}
+
+func (s shortMapper) RepositoryMutation_newBug(ctx context.Context, obj *models.RepositoryMutation, title string, message string) (bug.Snapshot, error) {
+ return s.r.RepositoryMutation().NewBug(ctx, obj, title, message)
+}
+
func (s shortMapper) SetStatusOperation_date(ctx context.Context, obj *operations.SetStatusOperation) (time.Time, error) {
return s.r.SetStatusOperation().Date(ctx, obj)
}
@@ -1323,6 +1338,8 @@ func (ec *executionContext) _Repository(ctx context.Context, sel []query.Selecti
out.Values[i] = ec._Repository_allBugs(ctx, field, obj)
case "bug":
out.Values[i] = ec._Repository_bug(ctx, field, obj)
+ case "mutation":
+ out.Values[i] = ec._Repository_mutation(ctx, field, obj)
default:
panic("unknown field " + strconv.Quote(field.Name))
}
@@ -1416,6 +1433,110 @@ func (ec *executionContext) _Repository_bug(ctx context.Context, field graphql.C
})
}
+func (ec *executionContext) _Repository_mutation(ctx context.Context, field graphql.CollectedField, obj *models.Repository) graphql.Marshaler {
+ ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{
+ Object: "Repository",
+ Args: nil,
+ Field: field,
+ })
+ return graphql.Defer(func() (ret graphql.Marshaler) {
+ defer func() {
+ if r := recover(); r != nil {
+ userErr := ec.Recover(ctx, r)
+ ec.Error(ctx, userErr)
+ ret = graphql.Null
+ }
+ }()
+
+ resTmp, err := ec.ResolverMiddleware(ctx, func(ctx context.Context) (interface{}, error) {
+ return ec.resolvers.Repository_mutation(ctx, obj)
+ })
+ if err != nil {
+ ec.Error(ctx, err)
+ return graphql.Null
+ }
+ if resTmp == nil {
+ return graphql.Null
+ }
+ res := resTmp.(models.RepositoryMutation)
+ return ec._RepositoryMutation(ctx, field.Selections, &res)
+ })
+}
+
+var repositoryMutationImplementors = []string{"RepositoryMutation"}
+
+// nolint: gocyclo, errcheck, gas, goconst
+func (ec *executionContext) _RepositoryMutation(ctx context.Context, sel []query.Selection, obj *models.RepositoryMutation) graphql.Marshaler {
+ fields := graphql.CollectFields(ec.Doc, sel, repositoryMutationImplementors, ec.Variables)
+
+ out := graphql.NewOrderedMap(len(fields))
+ for i, field := range fields {
+ out.Keys[i] = field.Alias
+
+ switch field.Name {
+ case "__typename":
+ out.Values[i] = graphql.MarshalString("RepositoryMutation")
+ case "newBug":
+ out.Values[i] = ec._RepositoryMutation_newBug(ctx, field, obj)
+ default:
+ panic("unknown field " + strconv.Quote(field.Name))
+ }
+ }
+
+ return out
+}
+
+func (ec *executionContext) _RepositoryMutation_newBug(ctx context.Context, field graphql.CollectedField, obj *models.RepositoryMutation) graphql.Marshaler {
+ args := map[string]interface{}{}
+ var arg0 string
+ if tmp, ok := field.Args["title"]; ok {
+ var err error
+ arg0, err = graphql.UnmarshalString(tmp)
+ if err != nil {
+ ec.Error(ctx, err)
+ return graphql.Null
+ }
+ }
+ args["title"] = arg0
+ var arg1 string
+ if tmp, ok := field.Args["message"]; ok {
+ var err error
+ arg1, err = graphql.UnmarshalString(tmp)
+ if err != nil {
+ ec.Error(ctx, err)
+ return graphql.Null
+ }
+ }
+ args["message"] = arg1
+ ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{
+ Object: "RepositoryMutation",
+ Args: args,
+ Field: field,
+ })
+ return graphql.Defer(func() (ret graphql.Marshaler) {
+ defer func() {
+ if r := recover(); r != nil {
+ userErr := ec.Recover(ctx, r)
+ ec.Error(ctx, userErr)
+ ret = graphql.Null
+ }
+ }()
+
+ resTmp, err := ec.ResolverMiddleware(ctx, func(ctx context.Context) (interface{}, error) {
+ return ec.resolvers.RepositoryMutation_newBug(ctx, obj, args["title"].(string), args["message"].(string))
+ })
+ if err != nil {
+ ec.Error(ctx, err)
+ return graphql.Null
+ }
+ if resTmp == nil {
+ return graphql.Null
+ }
+ res := resTmp.(bug.Snapshot)
+ return ec._Bug(ctx, field.Selections, &res)
+ })
+}
+
var setStatusOperationImplementors = []string{"SetStatusOperation", "Operation", "Authored"}
// nolint: gocyclo, errcheck, gas, goconst
@@ -2581,10 +2702,16 @@ type Bug {
type Repository {
allBugs(input: ConnectionInput!): BugConnection!
bug(prefix: String!): Bug
+
+ mutation: RepositoryMutation!
}
type Query {
defaultRepository: Repository
repository(id: String!): Repository
}
-`)
+
+
+type RepositoryMutation {
+ newBug(title: String!, message: String!): Bug!
+}`)
diff --git a/graphql/models/models.go b/graphql/models/models.go
index c492103c..1f182f1a 100644
--- a/graphql/models/models.go
+++ b/graphql/models/models.go
@@ -1,8 +1,15 @@
package models
-import "github.com/MichaelMure/git-bug/cache"
+import (
+ "github.com/MichaelMure/git-bug/cache"
+)
type Repository struct {
Cache cache.Cacher
Repo cache.RepoCacher
}
+
+type RepositoryMutation struct {
+ Cache cache.Cacher
+ Repo cache.RepoCacher
+}
diff --git a/graphql/resolvers/repo.go b/graphql/resolvers/repo.go
index 26c5ebaa..2e2872e2 100644
--- a/graphql/resolvers/repo.go
+++ b/graphql/resolvers/repo.go
@@ -64,3 +64,10 @@ func (repoResolver) Bug(ctx context.Context, obj *models.Repository, prefix stri
return b.Snapshot(), nil
}
+
+func (repoResolver) Mutation(ctx context.Context, obj *models.Repository) (models.RepositoryMutation, error) {
+ return models.RepositoryMutation{
+ Repo: obj.Repo,
+ Cache: obj.Cache,
+ }, nil
+}
diff --git a/graphql/resolvers/repo_mutation.go b/graphql/resolvers/repo_mutation.go
new file mode 100644
index 00000000..0c28cc0d
--- /dev/null
+++ b/graphql/resolvers/repo_mutation.go
@@ -0,0 +1,20 @@
+package resolvers
+
+import (
+ "context"
+ "github.com/MichaelMure/git-bug/bug"
+ "github.com/MichaelMure/git-bug/graphql/models"
+)
+
+type repoMutationResolver struct{}
+
+func (repoMutationResolver) NewBug(ctx context.Context, obj *models.RepositoryMutation, title string, message string) (bug.Snapshot, error) {
+ b, err := obj.Repo.NewBug(title, message)
+ if err != nil {
+ return bug.Snapshot{}, err
+ }
+
+ snap := b.Snapshot()
+
+ return *snap, nil
+}
diff --git a/graphql/resolvers/root.go b/graphql/resolvers/root.go
index f8ac67b1..36a9a391 100644
--- a/graphql/resolvers/root.go
+++ b/graphql/resolvers/root.go
@@ -48,3 +48,7 @@ func (Backend) SetStatusOperation() graph.SetStatusOperationResolver {
func (Backend) SetTitleOperation() graph.SetTitleOperationResolver {
return &setTitleOperationResolver{}
}
+
+func (r Backend) RepositoryMutation() graph.RepositoryMutationResolver {
+ return &repoMutationResolver{}
+}
diff --git a/graphql/schema.graphql b/graphql/schema.graphql
index 6aadfaf1..b481d2d7 100644
--- a/graphql/schema.graphql
+++ b/graphql/schema.graphql
@@ -166,9 +166,16 @@ type Bug {
type Repository {
allBugs(input: ConnectionInput!): BugConnection!
bug(prefix: String!): Bug
+
+ mutation: RepositoryMutation!
}
type Query {
defaultRepository: Repository
repository(id: String!): Repository
}
+
+
+type RepositoryMutation {
+ newBug(title: String!, message: String!): Bug!
+}