aboutsummaryrefslogtreecommitdiffstats
path: root/graphql/resolvers
diff options
context:
space:
mode:
Diffstat (limited to 'graphql/resolvers')
-rw-r--r--graphql/resolvers/mutation.go35
-rw-r--r--graphql/resolvers/repo_mutation.go20
-rw-r--r--graphql/resolvers/root.go10
3 files changed, 41 insertions, 24 deletions
diff --git a/graphql/resolvers/mutation.go b/graphql/resolvers/mutation.go
new file mode 100644
index 00000000..b06e94cc
--- /dev/null
+++ b/graphql/resolvers/mutation.go
@@ -0,0 +1,35 @@
+package resolvers
+
+import (
+ "context"
+ "github.com/MichaelMure/git-bug/bug"
+ "github.com/MichaelMure/git-bug/cache"
+)
+
+type mutationResolver struct {
+ cache cache.Cacher
+}
+
+func (r mutationResolver) getRepo(repoRef *string) (cache.RepoCacher, error) {
+ if repoRef != nil {
+ return r.cache.ResolveRepo(*repoRef)
+ }
+
+ return r.cache.DefaultRepo()
+}
+
+func (r mutationResolver) NewBug(ctx context.Context, repoRef *string, title string, message string) (bug.Snapshot, error) {
+ repo, err := r.getRepo(repoRef)
+ if err != nil {
+ return bug.Snapshot{}, err
+ }
+
+ b, err := repo.NewBug(title, message)
+ if err != nil {
+ return bug.Snapshot{}, err
+ }
+
+ snap := b.Snapshot()
+
+ return *snap, nil
+}
diff --git a/graphql/resolvers/repo_mutation.go b/graphql/resolvers/repo_mutation.go
deleted file mode 100644
index 0c28cc0d..00000000
--- a/graphql/resolvers/repo_mutation.go
+++ /dev/null
@@ -1,20 +0,0 @@
-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 36a9a391..2cf629cd 100644
--- a/graphql/resolvers/root.go
+++ b/graphql/resolvers/root.go
@@ -21,6 +21,12 @@ func (r Backend) Query() graph.QueryResolver {
}
}
+func (r Backend) Mutation() graph.MutationResolver {
+ return &mutationResolver{
+ cache: &r.RootCache,
+ }
+}
+
func (Backend) AddCommentOperation() graph.AddCommentOperationResolver {
return &addCommentOperationResolver{}
}
@@ -48,7 +54,3 @@ func (Backend) SetStatusOperation() graph.SetStatusOperationResolver {
func (Backend) SetTitleOperation() graph.SetTitleOperationResolver {
return &setTitleOperationResolver{}
}
-
-func (r Backend) RepositoryMutation() graph.RepositoryMutationResolver {
- return &repoMutationResolver{}
-}