diff options
Diffstat (limited to 'graphql/resolvers')
-rw-r--r-- | graphql/resolvers/bug.go | 66 | ||||
-rw-r--r-- | graphql/resolvers/color.go | 6 | ||||
-rw-r--r-- | graphql/resolvers/comment.go | 17 | ||||
-rw-r--r-- | graphql/resolvers/identity.go | 40 | ||||
-rw-r--r-- | graphql/resolvers/mutation.go | 32 | ||||
-rw-r--r-- | graphql/resolvers/operations.go | 52 | ||||
-rw-r--r-- | graphql/resolvers/query.go | 4 | ||||
-rw-r--r-- | graphql/resolvers/repo.go | 50 | ||||
-rw-r--r-- | graphql/resolvers/root.go | 4 | ||||
-rw-r--r-- | graphql/resolvers/timeline.go | 48 |
10 files changed, 183 insertions, 136 deletions
diff --git a/graphql/resolvers/bug.go b/graphql/resolvers/bug.go index 8f994c0b..fd8f4b6e 100644 --- a/graphql/resolvers/bug.go +++ b/graphql/resolvers/bug.go @@ -2,32 +2,30 @@ package resolvers import ( "context" - "time" "github.com/MichaelMure/git-bug/bug" "github.com/MichaelMure/git-bug/graphql/connections" "github.com/MichaelMure/git-bug/graphql/graph" "github.com/MichaelMure/git-bug/graphql/models" - "github.com/MichaelMure/git-bug/identity" ) var _ graph.BugResolver = &bugResolver{} type bugResolver struct{} -func (bugResolver) ID(ctx context.Context, obj *bug.Snapshot) (string, error) { +func (bugResolver) ID(_ context.Context, obj models.BugWrapper) (string, error) { return obj.Id().String(), nil } -func (bugResolver) HumanID(ctx context.Context, obj *bug.Snapshot) (string, error) { +func (bugResolver) HumanID(_ context.Context, obj models.BugWrapper) (string, error) { return obj.Id().Human(), nil } -func (bugResolver) Status(ctx context.Context, obj *bug.Snapshot) (models.Status, error) { - return convertStatus(obj.Status) +func (bugResolver) Status(_ context.Context, obj models.BugWrapper) (models.Status, error) { + return convertStatus(obj.Status()) } -func (bugResolver) Comments(ctx context.Context, obj *bug.Snapshot, after *string, before *string, first *int, last *int) (*models.CommentConnection, error) { +func (bugResolver) Comments(_ context.Context, obj models.BugWrapper, after *string, before *string, first *int, last *int) (*models.CommentConnection, error) { input := models.ConnectionInput{ Before: before, After: after, @@ -55,10 +53,15 @@ func (bugResolver) Comments(ctx context.Context, obj *bug.Snapshot, after *strin }, nil } - return connections.CommentCon(obj.Comments, edger, conMaker, input) + comments, err := obj.Comments() + if err != nil { + return nil, err + } + + return connections.CommentCon(comments, edger, conMaker, input) } -func (bugResolver) Operations(ctx context.Context, obj *bug.Snapshot, after *string, before *string, first *int, last *int) (*models.OperationConnection, error) { +func (bugResolver) Operations(_ context.Context, obj models.BugWrapper, after *string, before *string, first *int, last *int) (*models.OperationConnection, error) { input := models.ConnectionInput{ Before: before, After: after, @@ -82,10 +85,15 @@ func (bugResolver) Operations(ctx context.Context, obj *bug.Snapshot, after *str }, nil } - return connections.OperationCon(obj.Operations, edger, conMaker, input) + ops, err := obj.Operations() + if err != nil { + return nil, err + } + + return connections.OperationCon(ops, edger, conMaker, input) } -func (bugResolver) Timeline(ctx context.Context, obj *bug.Snapshot, after *string, before *string, first *int, last *int) (*models.TimelineItemConnection, error) { +func (bugResolver) Timeline(_ context.Context, obj models.BugWrapper, after *string, before *string, first *int, last *int) (*models.TimelineItemConnection, error) { input := models.ConnectionInput{ Before: before, After: after, @@ -109,15 +117,15 @@ func (bugResolver) Timeline(ctx context.Context, obj *bug.Snapshot, after *strin }, nil } - return connections.TimelineItemCon(obj.Timeline, edger, conMaker, input) -} + timeline, err := obj.Timeline() + if err != nil { + return nil, err + } -func (bugResolver) LastEdit(ctx context.Context, obj *bug.Snapshot) (*time.Time, error) { - t := obj.LastEditTime() - return &t, nil + return connections.TimelineItemCon(timeline, edger, conMaker, input) } -func (bugResolver) Actors(ctx context.Context, obj *bug.Snapshot, after *string, before *string, first *int, last *int) (*models.IdentityConnection, error) { +func (bugResolver) Actors(_ context.Context, obj models.BugWrapper, after *string, before *string, first *int, last *int) (*models.IdentityConnection, error) { input := models.ConnectionInput{ Before: before, After: after, @@ -125,14 +133,14 @@ func (bugResolver) Actors(ctx context.Context, obj *bug.Snapshot, after *string, Last: last, } - edger := func(actor identity.Interface, offset int) connections.Edge { + edger := func(actor models.IdentityWrapper, offset int) connections.Edge { return models.IdentityEdge{ Node: actor, Cursor: connections.OffsetToCursor(offset), } } - conMaker := func(edges []*models.IdentityEdge, nodes []identity.Interface, info *models.PageInfo, totalCount int) (*models.IdentityConnection, error) { + conMaker := func(edges []*models.IdentityEdge, nodes []models.IdentityWrapper, info *models.PageInfo, totalCount int) (*models.IdentityConnection, error) { return &models.IdentityConnection{ Edges: edges, Nodes: nodes, @@ -141,10 +149,15 @@ func (bugResolver) Actors(ctx context.Context, obj *bug.Snapshot, after *string, }, nil } - return connections.IdentityCon(obj.Actors, edger, conMaker, input) + actors, err := obj.Actors() + if err != nil { + return nil, err + } + + return connections.IdentityCon(actors, edger, conMaker, input) } -func (bugResolver) Participants(ctx context.Context, obj *bug.Snapshot, after *string, before *string, first *int, last *int) (*models.IdentityConnection, error) { +func (bugResolver) Participants(_ context.Context, obj models.BugWrapper, after *string, before *string, first *int, last *int) (*models.IdentityConnection, error) { input := models.ConnectionInput{ Before: before, After: after, @@ -152,14 +165,14 @@ func (bugResolver) Participants(ctx context.Context, obj *bug.Snapshot, after *s Last: last, } - edger := func(participant identity.Interface, offset int) connections.Edge { + edger := func(participant models.IdentityWrapper, offset int) connections.Edge { return models.IdentityEdge{ Node: participant, Cursor: connections.OffsetToCursor(offset), } } - conMaker := func(edges []*models.IdentityEdge, nodes []identity.Interface, info *models.PageInfo, totalCount int) (*models.IdentityConnection, error) { + conMaker := func(edges []*models.IdentityEdge, nodes []models.IdentityWrapper, info *models.PageInfo, totalCount int) (*models.IdentityConnection, error) { return &models.IdentityConnection{ Edges: edges, Nodes: nodes, @@ -168,5 +181,10 @@ func (bugResolver) Participants(ctx context.Context, obj *bug.Snapshot, after *s }, nil } - return connections.IdentityCon(obj.Participants, edger, conMaker, input) + participants, err := obj.Participants() + if err != nil { + return nil, err + } + + return connections.IdentityCon(participants, edger, conMaker, input) } diff --git a/graphql/resolvers/color.go b/graphql/resolvers/color.go index dc6f1b9c..8dc13095 100644 --- a/graphql/resolvers/color.go +++ b/graphql/resolvers/color.go @@ -11,14 +11,14 @@ var _ graph.ColorResolver = &colorResolver{} type colorResolver struct{} -func (colorResolver) R(ctx context.Context, obj *color.RGBA) (int, error) { +func (colorResolver) R(_ context.Context, obj *color.RGBA) (int, error) { return int(obj.R), nil } -func (colorResolver) G(ctx context.Context, obj *color.RGBA) (int, error) { +func (colorResolver) G(_ context.Context, obj *color.RGBA) (int, error) { return int(obj.G), nil } -func (colorResolver) B(ctx context.Context, obj *color.RGBA) (int, error) { +func (colorResolver) B(_ context.Context, obj *color.RGBA) (int, error) { return int(obj.B), nil } diff --git a/graphql/resolvers/comment.go b/graphql/resolvers/comment.go new file mode 100644 index 00000000..b142712a --- /dev/null +++ b/graphql/resolvers/comment.go @@ -0,0 +1,17 @@ +package resolvers + +import ( + "context" + + "github.com/MichaelMure/git-bug/bug" + "github.com/MichaelMure/git-bug/graphql/graph" + "github.com/MichaelMure/git-bug/graphql/models" +) + +var _ graph.CommentResolver = &commentResolver{} + +type commentResolver struct{} + +func (c commentResolver) Author(_ context.Context, obj *bug.Comment) (models.IdentityWrapper, error) { + return models.NewLoadedIdentity(obj.Author), nil +} diff --git a/graphql/resolvers/identity.go b/graphql/resolvers/identity.go index ee40d4d8..b8aa72a7 100644 --- a/graphql/resolvers/identity.go +++ b/graphql/resolvers/identity.go @@ -4,48 +4,18 @@ import ( "context" "github.com/MichaelMure/git-bug/graphql/graph" - "github.com/MichaelMure/git-bug/identity" + "github.com/MichaelMure/git-bug/graphql/models" ) var _ graph.IdentityResolver = &identityResolver{} type identityResolver struct{} -func (identityResolver) ID(ctx context.Context, obj *identity.Interface) (string, error) { - return (*obj).Id().String(), nil +func (identityResolver) ID(ctx context.Context, obj models.IdentityWrapper) (string, error) { + return obj.Id().String(), nil } -func (identityResolver) HumanID(ctx context.Context, obj *identity.Interface) (string, error) { - return (*obj).Id().Human(), nil -} - -func (identityResolver) Name(ctx context.Context, obj *identity.Interface) (*string, error) { - return nilIfEmpty((*obj).Name()) -} - -func (identityResolver) Email(ctx context.Context, obj *identity.Interface) (*string, error) { - return nilIfEmpty((*obj).Email()) -} - -func (identityResolver) Login(ctx context.Context, obj *identity.Interface) (*string, error) { - return nilIfEmpty((*obj).Login()) -} - -func (identityResolver) DisplayName(ctx context.Context, obj *identity.Interface) (string, error) { - return (*obj).DisplayName(), nil -} - -func (identityResolver) AvatarURL(ctx context.Context, obj *identity.Interface) (*string, error) { - return nilIfEmpty((*obj).AvatarUrl()) -} - -func (identityResolver) IsProtected(ctx context.Context, obj *identity.Interface) (bool, error) { - return (*obj).IsProtected(), nil -} +func (r identityResolver) HumanID(ctx context.Context, obj models.IdentityWrapper) (string, error) { + return obj.Id().Human(), nil -func nilIfEmpty(s string) (*string, error) { - if s == "" { - return nil, nil - } - return &s, nil } diff --git a/graphql/resolvers/mutation.go b/graphql/resolvers/mutation.go index b4f8845a..889edbc8 100644 --- a/graphql/resolvers/mutation.go +++ b/graphql/resolvers/mutation.go @@ -23,7 +23,7 @@ func (r mutationResolver) getRepo(ref *string) (*cache.RepoCache, error) { return r.cache.DefaultRepo() } -func (r mutationResolver) NewBug(ctx context.Context, input models.NewBugInput) (*models.NewBugPayload, error) { +func (r mutationResolver) NewBug(_ context.Context, input models.NewBugInput) (*models.NewBugPayload, error) { repo, err := r.getRepo(input.RepoRef) if err != nil { return nil, err @@ -36,12 +36,12 @@ func (r mutationResolver) NewBug(ctx context.Context, input models.NewBugInput) return &models.NewBugPayload{ ClientMutationID: input.ClientMutationID, - Bug: b.Snapshot(), + Bug: models.NewLoadedBug(b.Snapshot()), Operation: op, }, nil } -func (r mutationResolver) AddComment(ctx context.Context, input models.AddCommentInput) (*models.AddCommentPayload, error) { +func (r mutationResolver) AddComment(_ context.Context, input models.AddCommentInput) (*models.AddCommentPayload, error) { repo, err := r.getRepo(input.RepoRef) if err != nil { return nil, err @@ -59,12 +59,12 @@ func (r mutationResolver) AddComment(ctx context.Context, input models.AddCommen return &models.AddCommentPayload{ ClientMutationID: input.ClientMutationID, - Bug: b.Snapshot(), + Bug: models.NewLoadedBug(b.Snapshot()), Operation: op, }, nil } -func (r mutationResolver) ChangeLabels(ctx context.Context, input *models.ChangeLabelInput) (*models.ChangeLabelPayload, error) { +func (r mutationResolver) ChangeLabels(_ context.Context, input *models.ChangeLabelInput) (*models.ChangeLabelPayload, error) { repo, err := r.getRepo(input.RepoRef) if err != nil { return nil, err @@ -87,13 +87,13 @@ func (r mutationResolver) ChangeLabels(ctx context.Context, input *models.Change return &models.ChangeLabelPayload{ ClientMutationID: input.ClientMutationID, - Bug: b.Snapshot(), + Bug: models.NewLoadedBug(b.Snapshot()), Operation: op, Results: resultsPtr, }, nil } -func (r mutationResolver) OpenBug(ctx context.Context, input models.OpenBugInput) (*models.OpenBugPayload, error) { +func (r mutationResolver) OpenBug(_ context.Context, input models.OpenBugInput) (*models.OpenBugPayload, error) { repo, err := r.getRepo(input.RepoRef) if err != nil { return nil, err @@ -111,12 +111,12 @@ func (r mutationResolver) OpenBug(ctx context.Context, input models.OpenBugInput return &models.OpenBugPayload{ ClientMutationID: input.ClientMutationID, - Bug: b.Snapshot(), + Bug: models.NewLoadedBug(b.Snapshot()), Operation: op, }, nil } -func (r mutationResolver) CloseBug(ctx context.Context, input models.CloseBugInput) (*models.CloseBugPayload, error) { +func (r mutationResolver) CloseBug(_ context.Context, input models.CloseBugInput) (*models.CloseBugPayload, error) { repo, err := r.getRepo(input.RepoRef) if err != nil { return nil, err @@ -134,12 +134,12 @@ func (r mutationResolver) CloseBug(ctx context.Context, input models.CloseBugInp return &models.CloseBugPayload{ ClientMutationID: input.ClientMutationID, - Bug: b.Snapshot(), + Bug: models.NewLoadedBug(b.Snapshot()), Operation: op, }, nil } -func (r mutationResolver) SetTitle(ctx context.Context, input models.SetTitleInput) (*models.SetTitlePayload, error) { +func (r mutationResolver) SetTitle(_ context.Context, input models.SetTitleInput) (*models.SetTitlePayload, error) { repo, err := r.getRepo(input.RepoRef) if err != nil { return nil, err @@ -157,12 +157,12 @@ func (r mutationResolver) SetTitle(ctx context.Context, input models.SetTitleInp return &models.SetTitlePayload{ ClientMutationID: input.ClientMutationID, - Bug: b.Snapshot(), + Bug: models.NewLoadedBug(b.Snapshot()), Operation: op, }, nil } -func (r mutationResolver) Commit(ctx context.Context, input models.CommitInput) (*models.CommitPayload, error) { +func (r mutationResolver) Commit(_ context.Context, input models.CommitInput) (*models.CommitPayload, error) { repo, err := r.getRepo(input.RepoRef) if err != nil { return nil, err @@ -180,11 +180,11 @@ func (r mutationResolver) Commit(ctx context.Context, input models.CommitInput) return &models.CommitPayload{ ClientMutationID: input.ClientMutationID, - Bug: b.Snapshot(), + Bug: models.NewLoadedBug(b.Snapshot()), }, nil } -func (r mutationResolver) CommitAsNeeded(ctx context.Context, input models.CommitAsNeededInput) (*models.CommitAsNeededPayload, error) { +func (r mutationResolver) CommitAsNeeded(_ context.Context, input models.CommitAsNeededInput) (*models.CommitAsNeededPayload, error) { repo, err := r.getRepo(input.RepoRef) if err != nil { return nil, err @@ -202,6 +202,6 @@ func (r mutationResolver) CommitAsNeeded(ctx context.Context, input models.Commi return &models.CommitAsNeededPayload{ ClientMutationID: input.ClientMutationID, - Bug: b.Snapshot(), + Bug: models.NewLoadedBug(b.Snapshot()), }, nil } diff --git a/graphql/resolvers/operations.go b/graphql/resolvers/operations.go index ec803c1f..29110cf3 100644 --- a/graphql/resolvers/operations.go +++ b/graphql/resolvers/operations.go @@ -14,11 +14,15 @@ var _ graph.CreateOperationResolver = createOperationResolver{} type createOperationResolver struct{} -func (createOperationResolver) ID(ctx context.Context, obj *bug.CreateOperation) (string, error) { +func (createOperationResolver) ID(_ context.Context, obj *bug.CreateOperation) (string, error) { return obj.Id().String(), nil } -func (createOperationResolver) Date(ctx context.Context, obj *bug.CreateOperation) (*time.Time, error) { +func (createOperationResolver) Author(_ context.Context, obj *bug.CreateOperation) (models.IdentityWrapper, error) { + return models.NewLoadedIdentity(obj.Author), nil +} + +func (createOperationResolver) Date(_ context.Context, obj *bug.CreateOperation) (*time.Time, error) { t := obj.Time() return &t, nil } @@ -27,11 +31,15 @@ var _ graph.AddCommentOperationResolver = addCommentOperationResolver{} type addCommentOperationResolver struct{} -func (addCommentOperationResolver) ID(ctx context.Context, obj *bug.AddCommentOperation) (string, error) { +func (addCommentOperationResolver) ID(_ context.Context, obj *bug.AddCommentOperation) (string, error) { return obj.Id().String(), nil } -func (addCommentOperationResolver) Date(ctx context.Context, obj *bug.AddCommentOperation) (*time.Time, error) { +func (addCommentOperationResolver) Author(_ context.Context, obj *bug.AddCommentOperation) (models.IdentityWrapper, error) { + return models.NewLoadedIdentity(obj.Author), nil +} + +func (addCommentOperationResolver) Date(_ context.Context, obj *bug.AddCommentOperation) (*time.Time, error) { t := obj.Time() return &t, nil } @@ -40,15 +48,19 @@ var _ graph.EditCommentOperationResolver = editCommentOperationResolver{} type editCommentOperationResolver struct{} -func (editCommentOperationResolver) ID(ctx context.Context, obj *bug.EditCommentOperation) (string, error) { +func (editCommentOperationResolver) ID(_ context.Context, obj *bug.EditCommentOperation) (string, error) { return obj.Id().String(), nil } -func (editCommentOperationResolver) Target(ctx context.Context, obj *bug.EditCommentOperation) (string, error) { +func (editCommentOperationResolver) Target(_ context.Context, obj *bug.EditCommentOperation) (string, error) { return obj.Target.String(), nil } -func (editCommentOperationResolver) Date(ctx context.Context, obj *bug.EditCommentOperation) (*time.Time, error) { +func (editCommentOperationResolver) Author(_ context.Context, obj *bug.EditCommentOperation) (models.IdentityWrapper, error) { + return models.NewLoadedIdentity(obj.Author), nil +} + +func (editCommentOperationResolver) Date(_ context.Context, obj *bug.EditCommentOperation) (*time.Time, error) { t := obj.Time() return &t, nil } @@ -57,11 +69,15 @@ var _ graph.LabelChangeOperationResolver = labelChangeOperationResolver{} type labelChangeOperationResolver struct{} -func (labelChangeOperationResolver) ID(ctx context.Context, obj *bug.LabelChangeOperation) (string, error) { +func (labelChangeOperationResolver) ID(_ context.Context, obj *bug.LabelChangeOperation) (string, error) { return obj.Id().String(), nil } -func (labelChangeOperationResolver) Date(ctx context.Context, obj *bug.LabelChangeOperation) (*time.Time, error) { +func (labelChangeOperationResolver) Author(_ context.Context, obj *bug.LabelChangeOperation) (models.IdentityWrapper, error) { + return models.NewLoadedIdentity(obj.Author), nil +} + +func (labelChangeOperationResolver) Date(_ context.Context, obj *bug.LabelChangeOperation) (*time.Time, error) { t := obj.Time() return &t, nil } @@ -70,16 +86,20 @@ var _ graph.SetStatusOperationResolver = setStatusOperationResolver{} type setStatusOperationResolver struct{} -func (setStatusOperationResolver) ID(ctx context.Context, obj *bug.SetStatusOperation) (string, error) { +func (setStatusOperationResolver) ID(_ context.Context, obj *bug.SetStatusOperation) (string, error) { return obj.Id().String(), nil } -func (setStatusOperationResolver) Date(ctx context.Context, obj *bug.SetStatusOperation) (*time.Time, error) { +func (setStatusOperationResolver) Author(_ context.Context, obj *bug.SetStatusOperation) (models.IdentityWrapper, error) { + return models.NewLoadedIdentity(obj.Author), nil +} + +func (setStatusOperationResolver) Date(_ context.Context, obj *bug.SetStatusOperation) (*time.Time, error) { t := obj.Time() return &t, nil } -func (setStatusOperationResolver) Status(ctx context.Context, obj *bug.SetStatusOperation) (models.Status, error) { +func (setStatusOperationResolver) Status(_ context.Context, obj *bug.SetStatusOperation) (models.Status, error) { return convertStatus(obj.Status) } @@ -87,11 +107,15 @@ var _ graph.SetTitleOperationResolver = setTitleOperationResolver{} type setTitleOperationResolver struct{} -func (setTitleOperationResolver) ID(ctx context.Context, obj *bug.SetTitleOperation) (string, error) { +func (setTitleOperationResolver) ID(_ context.Context, obj *bug.SetTitleOperation) (string, error) { return obj.Id().String(), nil } -func (setTitleOperationResolver) Date(ctx context.Context, obj *bug.SetTitleOperation) (*time.Time, error) { +func (setTitleOperationResolver) Author(_ context.Context, obj *bug.SetTitleOperation) (models.IdentityWrapper, error) { + return models.NewLoadedIdentity(obj.Author), nil +} + +func (setTitleOperationResolver) Date(_ context.Context, obj *bug.SetTitleOperation) (*time.Time, error) { t := obj.Time() return &t, nil } diff --git a/graphql/resolvers/query.go b/graphql/resolvers/query.go index aa4e1d85..9503ccf4 100644 --- a/graphql/resolvers/query.go +++ b/graphql/resolvers/query.go @@ -14,7 +14,7 @@ type rootQueryResolver struct { cache *cache.MultiRepoCache } -func (r rootQueryResolver) DefaultRepository(ctx context.Context) (*models.Repository, error) { +func (r rootQueryResolver) DefaultRepository(_ context.Context) (*models.Repository, error) { repo, err := r.cache.DefaultRepo() if err != nil { @@ -27,7 +27,7 @@ func (r rootQueryResolver) DefaultRepository(ctx context.Context) (*models.Repos }, nil } -func (r rootQueryResolver) Repository(ctx context.Context, ref string) (*models.Repository, error) { +func (r rootQueryResolver) Repository(_ context.Context, ref string) (*models.Repository, error) { repo, err := r.cache.ResolveRepo(ref) if err != nil { diff --git a/graphql/resolvers/repo.go b/graphql/resolvers/repo.go index 5a37ae18..3b0aa9a1 100644 --- a/graphql/resolvers/repo.go +++ b/graphql/resolvers/repo.go @@ -9,14 +9,13 @@ import ( "github.com/MichaelMure/git-bug/graphql/connections" "github.com/MichaelMure/git-bug/graphql/graph" "github.com/MichaelMure/git-bug/graphql/models" - "github.com/MichaelMure/git-bug/identity" ) var _ graph.RepositoryResolver = &repoResolver{} type repoResolver struct{} -func (repoResolver) AllBugs(ctx context.Context, obj *models.Repository, after *string, before *string, first *int, last *int, queryStr *string) (*models.BugConnection, error) { +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, After: after, @@ -49,22 +48,21 @@ func (repoResolver) AllBugs(ctx context.Context, obj *models.Repository, after * // The conMaker will finally load and compile bugs from git to replace the selected edges conMaker := func(lazyBugEdges []*connections.LazyBugEdge, lazyNode []entity.Id, info *models.PageInfo, totalCount int) (*models.BugConnection, error) { edges := make([]*models.BugEdge, len(lazyBugEdges)) - nodes := make([]*bug.Snapshot, len(lazyBugEdges)) + nodes := make([]models.BugWrapper, len(lazyBugEdges)) for i, lazyBugEdge := range lazyBugEdges { - b, err := obj.Repo.ResolveBug(lazyBugEdge.Id) - + excerpt, err := obj.Repo.ResolveBugExcerpt(lazyBugEdge.Id) if err != nil { return nil, err } - snap := b.Snapshot() + b := models.NewLazyBug(obj.Repo, excerpt) edges[i] = &models.BugEdge{ Cursor: lazyBugEdge.Cursor, - Node: snap, + Node: b, } - nodes[i] = snap + nodes[i] = b } return &models.BugConnection{ @@ -78,17 +76,16 @@ func (repoResolver) AllBugs(ctx context.Context, obj *models.Repository, after * return connections.LazyBugCon(source, edger, conMaker, input) } -func (repoResolver) Bug(ctx context.Context, obj *models.Repository, prefix string) (*bug.Snapshot, error) { - b, err := obj.Repo.ResolveBugPrefix(prefix) - +func (repoResolver) Bug(_ context.Context, obj *models.Repository, prefix string) (models.BugWrapper, error) { + excerpt, err := obj.Repo.ResolveBugExcerptPrefix(prefix) if err != nil { return nil, err } - return b.Snapshot(), nil + return models.NewLazyBug(obj.Repo, excerpt), nil } -func (repoResolver) AllIdentities(ctx context.Context, obj *models.Repository, after *string, before *string, first *int, last *int) (*models.IdentityConnection, error) { +func (repoResolver) AllIdentities(_ context.Context, obj *models.Repository, after *string, before *string, first *int, last *int) (*models.IdentityConnection, error) { input := models.ConnectionInput{ Before: before, After: after, @@ -110,22 +107,21 @@ func (repoResolver) AllIdentities(ctx context.Context, obj *models.Repository, a // The conMaker will finally load and compile identities from git to replace the selected edges conMaker := func(lazyIdentityEdges []*connections.LazyIdentityEdge, lazyNode []entity.Id, info *models.PageInfo, totalCount int) (*models.IdentityConnection, error) { edges := make([]*models.IdentityEdge, len(lazyIdentityEdges)) - nodes := make([]identity.Interface, len(lazyIdentityEdges)) + nodes := make([]models.IdentityWrapper, len(lazyIdentityEdges)) for k, lazyIdentityEdge := range lazyIdentityEdges { - i, err := obj.Repo.ResolveIdentity(lazyIdentityEdge.Id) - + excerpt, err := obj.Repo.ResolveIdentityExcerpt(lazyIdentityEdge.Id) if err != nil { return nil, err } - ii := identity.Interface(i.Identity) + i := models.NewLazyIdentity(obj.Repo, excerpt) edges[k] = &models.IdentityEdge{ Cursor: lazyIdentityEdge.Cursor, - Node: i.Identity, + Node: i, } - nodes[k] = ii + nodes[k] = i } return &models.IdentityConnection{ @@ -139,27 +135,25 @@ func (repoResolver) AllIdentities(ctx context.Context, obj *models.Repository, a return connections.LazyIdentityCon(source, edger, conMaker, input) } -func (repoResolver) Identity(ctx context.Context, obj *models.Repository, prefix string) (identity.Interface, error) { - i, err := obj.Repo.ResolveIdentityPrefix(prefix) - +func (repoResolver) Identity(_ context.Context, obj *models.Repository, prefix string) (models.IdentityWrapper, error) { + excerpt, err := obj.Repo.ResolveIdentityExcerptPrefix(prefix) if err != nil { return nil, err } - return i.Identity, nil + return models.NewLazyIdentity(obj.Repo, excerpt), nil } -func (repoResolver) UserIdentity(ctx context.Context, obj *models.Repository) (identity.Interface, error) { - i, err := obj.Repo.GetUserIdentity() - +func (repoResolver) UserIdentity(_ context.Context, obj *models.Repository) (models.IdentityWrapper, error) { + excerpt, err := obj.Repo.GetUserIdentityExcerpt() if err != nil { return nil, err } - return i.Identity, nil + return models.NewLazyIdentity(obj.Repo, excerpt), nil } -func (resolver repoResolver) ValidLabels(ctx context.Context, obj *models.Repository, after *string, before *string, first *int, last *int) (*models.LabelConnection, error) { +func (resolver 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, diff --git a/graphql/resolvers/root.go b/graphql/resolvers/root.go index 3b129f3b..9973ff59 100644 --- a/graphql/resolvers/root.go +++ b/graphql/resolvers/root.go @@ -42,6 +42,10 @@ func (RootResolver) Color() graph.ColorResolver { return &colorResolver{} } +func (r RootResolver) Comment() graph.CommentResolver { + return &commentResolver{} +} + func (RootResolver) Label() graph.LabelResolver { return &labelResolver{} } diff --git a/graphql/resolvers/timeline.go b/graphql/resolvers/timeline.go index b206f898..acf236f8 100644 --- a/graphql/resolvers/timeline.go +++ b/graphql/resolvers/timeline.go @@ -13,7 +13,7 @@ var _ graph.CommentHistoryStepResolver = commentHistoryStepResolver{} type commentHistoryStepResolver struct{} -func (commentHistoryStepResolver) Date(ctx context.Context, obj *bug.CommentHistoryStep) (*time.Time, error) { +func (commentHistoryStepResolver) Date(_ context.Context, obj *bug.CommentHistoryStep) (*time.Time, error) { t := obj.UnixTime.Time() return &t, nil } @@ -22,16 +22,20 @@ var _ graph.AddCommentTimelineItemResolver = addCommentTimelineItemResolver{} type addCommentTimelineItemResolver struct{} -func (addCommentTimelineItemResolver) ID(ctx context.Context, obj *bug.AddCommentTimelineItem) (string, error) { +func (addCommentTimelineItemResolver) ID(_ context.Context, obj *bug.AddCommentTimelineItem) (string, error) { return obj.Id().String(), nil } -func (addCommentTimelineItemResolver) CreatedAt(ctx context.Context, obj *bug.AddCommentTimelineItem) (*time.Time, error) { +func (addCommentTimelineItemResolver) Author(_ context.Context, obj *bug.AddCommentTimelineItem) (models.IdentityWrapper, error) { + return models.NewLoadedIdentity(obj.Author), nil +} + +func (addCommentTimelineItemResolver) CreatedAt(_ context.Context, obj *bug.AddCommentTimelineItem) (*time.Time, error) { t := obj.CreatedAt.Time() return &t, nil } -func (addCommentTimelineItemResolver) LastEdit(ctx context.Context, obj *bug.AddCommentTimelineItem) (*time.Time, error) { +func (addCommentTimelineItemResolver) LastEdit(_ context.Context, obj *bug.AddCommentTimelineItem) (*time.Time, error) { t := obj.LastEdit.Time() return &t, nil } @@ -40,16 +44,20 @@ var _ graph.CreateTimelineItemResolver = createTimelineItemResolver{} type createTimelineItemResolver struct{} -func (createTimelineItemResolver) ID(ctx context.Context, obj *bug.CreateTimelineItem) (string, error) { +func (createTimelineItemResolver) ID(_ context.Context, obj *bug.CreateTimelineItem) (string, error) { return obj.Id().String(), nil } -func (createTimelineItemResolver) CreatedAt(ctx context.Context, obj *bug.CreateTimelineItem) (*time.Time, error) { +func (r createTimelineItemResolver) Author(_ context.Context, obj *bug.CreateTimelineItem) (models.IdentityWrapper, error) { + return models.NewLoadedIdentity(obj.Author), nil +} + +func (createTimelineItemResolver) CreatedAt(_ context.Context, obj *bug.CreateTimelineItem) (*time.Time, error) { t := obj.CreatedAt.Time() return &t, nil } -func (createTimelineItemResolver) LastEdit(ctx context.Context, obj *bug.CreateTimelineItem) (*time.Time, error) { +func (createTimelineItemResolver) LastEdit(_ context.Context, obj *bug.CreateTimelineItem) (*time.Time, error) { t := obj.LastEdit.Time() return &t, nil } @@ -58,11 +66,15 @@ var _ graph.LabelChangeTimelineItemResolver = labelChangeTimelineItem{} type labelChangeTimelineItem struct{} -func (labelChangeTimelineItem) ID(ctx context.Context, obj *bug.LabelChangeTimelineItem) (string, error) { +func (labelChangeTimelineItem) ID(_ context.Context, obj *bug.LabelChangeTimelineItem) (string, error) { return obj.Id().String(), nil } -func (labelChangeTimelineItem) Date(ctx context.Context, obj *bug.LabelChangeTimelineItem) (*time.Time, error) { +func (i labelChangeTimelineItem) Author(_ context.Context, obj *bug.LabelChangeTimelineItem) (models.IdentityWrapper, error) { + return models.NewLoadedIdentity(obj.Author), nil +} + +func (labelChangeTimelineItem) Date(_ context.Context, obj *bug.LabelChangeTimelineItem) (*time.Time, error) { t := obj.UnixTime.Time() return &t, nil } @@ -71,16 +83,20 @@ var _ graph.SetStatusTimelineItemResolver = setStatusTimelineItem{} type setStatusTimelineItem struct{} -func (setStatusTimelineItem) ID(ctx context.Context, obj *bug.SetStatusTimelineItem) (string, error) { +func (setStatusTimelineItem) ID(_ context.Context, obj *bug.SetStatusTimelineItem) (string, error) { return obj.Id().String(), nil } -func (setStatusTimelineItem) Date(ctx context.Context, obj *bug.SetStatusTimelineItem) (*time.Time, error) { +func (i setStatusTimelineItem) Author(_ context.Context, obj *bug.SetStatusTimelineItem) (models.IdentityWrapper, error) { + return models.NewLoadedIdentity(obj.Author), nil +} + +func (setStatusTimelineItem) Date(_ context.Context, obj *bug.SetStatusTimelineItem) (*time.Time, error) { t := obj.UnixTime.Time() return &t, nil } -func (setStatusTimelineItem) Status(ctx context.Context, obj *bug.SetStatusTimelineItem) (models.Status, error) { +func (setStatusTimelineItem) Status(_ context.Context, obj *bug.SetStatusTimelineItem) (models.Status, error) { return convertStatus(obj.Status) } @@ -88,11 +104,15 @@ var _ graph.SetTitleTimelineItemResolver = setTitleTimelineItem{} type setTitleTimelineItem struct{} -func (setTitleTimelineItem) ID(ctx context.Context, obj *bug.SetTitleTimelineItem) (string, error) { +func (setTitleTimelineItem) ID(_ context.Context, obj *bug.SetTitleTimelineItem) (string, error) { return obj.Id().String(), nil } -func (setTitleTimelineItem) Date(ctx context.Context, obj *bug.SetTitleTimelineItem) (*time.Time, error) { +func (i setTitleTimelineItem) Author(_ context.Context, obj *bug.SetTitleTimelineItem) (models.IdentityWrapper, error) { + return models.NewLoadedIdentity(obj.Author), nil +} + +func (setTitleTimelineItem) Date(_ context.Context, obj *bug.SetTitleTimelineItem) (*time.Time, error) { t := obj.UnixTime.Time() return &t, nil } |