From 1effc91556c4567673c68329722bd415ec648a12 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Wed, 5 Feb 2020 01:06:53 +0100 Subject: graphql: merge defaultRepository and repository for simplified webUI code --- graphql/resolvers/query.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'graphql/resolvers') 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 -- cgit From 929480fa0a7fa40ba14850aed17158a20cdf6391 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Wed, 12 Feb 2020 21:03:20 +0100 Subject: graphql: expose the name of Repository --- graphql/resolvers/repo.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'graphql/resolvers') 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, -- cgit From 0c17d248ee1536aa02ab5beb0c935607421a6b8d Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Wed, 12 Feb 2020 22:02:11 +0100 Subject: graphql: server side take responsability to commit --- graphql/resolvers/mutation.go | 83 +++++++++++++------------------------------ 1 file changed, 24 insertions(+), 59 deletions(-) (limited to 'graphql/resolvers') 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 } -- cgit