diff options
author | Michael Muré <batolettre@gmail.com> | 2018-07-30 01:08:45 +0200 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2018-07-30 01:08:45 +0200 |
commit | 3cb0469a2200dea24aff1f414aa971d5e6fe9815 (patch) | |
tree | ce74b9f91707ae90f0dc8977af0df59eb6dc2590 /graphql/resolvers | |
parent | 79b3d189186783c01acb194de825976a007dbd5f (diff) | |
download | git-bug-3cb0469a2200dea24aff1f414aa971d5e6fe9815.tar.gz |
graphql: implement a first mutation
Diffstat (limited to 'graphql/resolvers')
-rw-r--r-- | graphql/resolvers/repo.go | 7 | ||||
-rw-r--r-- | graphql/resolvers/repo_mutation.go | 20 | ||||
-rw-r--r-- | graphql/resolvers/root.go | 4 |
3 files changed, 31 insertions, 0 deletions
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{} +} |