diff options
Diffstat (limited to 'graphql/resolvers/mutation.go')
-rw-r--r-- | graphql/resolvers/mutation.go | 35 |
1 files changed, 35 insertions, 0 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 +} |