diff options
author | Michael Muré <batolettre@gmail.com> | 2020-02-13 00:05:04 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-13 00:05:04 +0100 |
commit | 0066f3d8c278558eeac70d3cd7ca21c360014346 (patch) | |
tree | ca40e95496b90837fb0e7a5ff4ac5b966ceba6ec /graphql/resolvers | |
parent | 269036bdf25af8fefbca24b7455c4e0b7d1d72b5 (diff) | |
parent | ab09c03a1e55d5c2e35f332f0e5f6335c1670427 (diff) | |
download | git-bug-0066f3d8c278558eeac70d3cd7ca21c360014346.tar.gz |
Merge pull request #323 from MichaelMure/webui/typescript
Webui/typescript
Diffstat (limited to 'graphql/resolvers')
-rw-r--r-- | graphql/resolvers/mutation.go | 83 | ||||
-rw-r--r-- | graphql/resolvers/query.go | 11 | ||||
-rw-r--r-- | graphql/resolvers/repo.go | 7 |
3 files changed, 39 insertions, 62 deletions
diff --git a/graphql/resolvers/mutation.go b/graphql/resolvers/mutation.go index 889edbc8..850645f4 100644 --- a/graphql/resolvers/mutation.go +++ b/graphql/resolvers/mutation.go @@ -23,6 +23,15 @@ func (r mutationResolver) getRepo(ref *string) (*cache.RepoCache, error) { return r.cache.DefaultRepo() } +func (r mutationResolver) getBug(repoRef *string, bugPrefix string) (*cache.BugCache, error) { + repo, err := r.getRepo(repoRef) + if err != nil { + return nil, err + } + + return repo.ResolveBugPrefix(bugPrefix) +} + func (r mutationResolver) NewBug(_ context.Context, input models.NewBugInput) (*models.NewBugPayload, error) { repo, err := r.getRepo(input.RepoRef) if err != nil { @@ -42,17 +51,17 @@ func (r mutationResolver) NewBug(_ context.Context, input models.NewBugInput) (* } func (r mutationResolver) AddComment(_ context.Context, input models.AddCommentInput) (*models.AddCommentPayload, error) { - repo, err := r.getRepo(input.RepoRef) + b, err := r.getBug(input.RepoRef, input.Prefix) if err != nil { return nil, err } - b, err := repo.ResolveBugPrefix(input.Prefix) + op, err := b.AddCommentWithFiles(input.Message, input.Files) if err != nil { return nil, err } - op, err := b.AddCommentWithFiles(input.Message, input.Files) + err = b.Commit() if err != nil { return nil, err } @@ -65,17 +74,17 @@ func (r mutationResolver) AddComment(_ context.Context, input models.AddCommentI } func (r mutationResolver) ChangeLabels(_ context.Context, input *models.ChangeLabelInput) (*models.ChangeLabelPayload, error) { - repo, err := r.getRepo(input.RepoRef) + b, err := r.getBug(input.RepoRef, input.Prefix) if err != nil { return nil, err } - b, err := repo.ResolveBugPrefix(input.Prefix) + results, op, err := b.ChangeLabels(input.Added, input.Removed) if err != nil { return nil, err } - results, op, err := b.ChangeLabels(input.Added, input.Removed) + err = b.Commit() if err != nil { return nil, err } @@ -94,17 +103,17 @@ func (r mutationResolver) ChangeLabels(_ context.Context, input *models.ChangeLa } func (r mutationResolver) OpenBug(_ context.Context, input models.OpenBugInput) (*models.OpenBugPayload, error) { - repo, err := r.getRepo(input.RepoRef) + b, err := r.getBug(input.RepoRef, input.Prefix) if err != nil { return nil, err } - b, err := repo.ResolveBugPrefix(input.Prefix) + op, err := b.Open() if err != nil { return nil, err } - op, err := b.Open() + err = b.Commit() if err != nil { return nil, err } @@ -117,17 +126,17 @@ func (r mutationResolver) OpenBug(_ context.Context, input models.OpenBugInput) } func (r mutationResolver) CloseBug(_ context.Context, input models.CloseBugInput) (*models.CloseBugPayload, error) { - repo, err := r.getRepo(input.RepoRef) + b, err := r.getBug(input.RepoRef, input.Prefix) if err != nil { return nil, err } - b, err := repo.ResolveBugPrefix(input.Prefix) + op, err := b.Close() if err != nil { return nil, err } - op, err := b.Close() + err = b.Commit() if err != nil { return nil, err } @@ -140,12 +149,7 @@ func (r mutationResolver) CloseBug(_ context.Context, input models.CloseBugInput } func (r mutationResolver) SetTitle(_ context.Context, input models.SetTitleInput) (*models.SetTitlePayload, error) { - repo, err := r.getRepo(input.RepoRef) - if err != nil { - return nil, err - } - - b, err := repo.ResolveBugPrefix(input.Prefix) + b, err := r.getBug(input.RepoRef, input.Prefix) if err != nil { return nil, err } @@ -155,53 +159,14 @@ func (r mutationResolver) SetTitle(_ context.Context, input models.SetTitleInput return nil, err } - return &models.SetTitlePayload{ - ClientMutationID: input.ClientMutationID, - Bug: models.NewLoadedBug(b.Snapshot()), - Operation: op, - }, nil -} - -func (r mutationResolver) Commit(_ context.Context, input models.CommitInput) (*models.CommitPayload, error) { - repo, err := r.getRepo(input.RepoRef) - if err != nil { - return nil, err - } - - b, err := repo.ResolveBugPrefix(input.Prefix) - if err != nil { - return nil, err - } - err = b.Commit() if err != nil { return nil, err } - return &models.CommitPayload{ - ClientMutationID: input.ClientMutationID, - Bug: models.NewLoadedBug(b.Snapshot()), - }, nil -} - -func (r mutationResolver) CommitAsNeeded(_ context.Context, input models.CommitAsNeededInput) (*models.CommitAsNeededPayload, error) { - repo, err := r.getRepo(input.RepoRef) - if err != nil { - return nil, err - } - - b, err := repo.ResolveBugPrefix(input.Prefix) - if err != nil { - return nil, err - } - - err = b.CommitAsNeeded() - if err != nil { - return nil, err - } - - return &models.CommitAsNeededPayload{ + return &models.SetTitlePayload{ ClientMutationID: input.ClientMutationID, Bug: models.NewLoadedBug(b.Snapshot()), + Operation: op, }, nil } diff --git a/graphql/resolvers/query.go b/graphql/resolvers/query.go index 9503ccf4..6fb18638 100644 --- a/graphql/resolvers/query.go +++ b/graphql/resolvers/query.go @@ -27,8 +27,15 @@ func (r rootQueryResolver) DefaultRepository(_ context.Context) (*models.Reposit }, nil } -func (r rootQueryResolver) Repository(_ context.Context, ref string) (*models.Repository, error) { - repo, err := r.cache.ResolveRepo(ref) +func (r rootQueryResolver) Repository(_ context.Context, ref *string) (*models.Repository, error) { + var repo *cache.RepoCache + var err error + + if ref == nil { + repo, err = r.cache.DefaultRepo() + } else { + repo, err = r.cache.ResolveRepo(*ref) + } if err != nil { return nil, err 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, |