diff options
author | Michael Muré <batolettre@gmail.com> | 2019-08-12 16:12:14 +0200 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2019-08-12 16:12:14 +0200 |
commit | 99b5c58d43137bd9f6503788a55484327b0c531f (patch) | |
tree | 08ecc0f923b5f1fb4e8a7627aeabccb335d92ad1 /graphql/resolvers | |
parent | 67a3752e176790e82a48706236f889cab4f8913d (diff) | |
download | git-bug-99b5c58d43137bd9f6503788a55484327b0c531f.tar.gz |
finish the refactoring for the dedicated identifier type
Diffstat (limited to 'graphql/resolvers')
-rw-r--r-- | graphql/resolvers/bug.go | 8 | ||||
-rw-r--r-- | graphql/resolvers/identity.go | 4 | ||||
-rw-r--r-- | graphql/resolvers/operations.go | 45 | ||||
-rw-r--r-- | graphql/resolvers/repo.go | 9 | ||||
-rw-r--r-- | graphql/resolvers/root.go | 2 | ||||
-rw-r--r-- | graphql/resolvers/timeline.go | 33 |
6 files changed, 92 insertions, 9 deletions
diff --git a/graphql/resolvers/bug.go b/graphql/resolvers/bug.go index 37766b95..8f994c0b 100644 --- a/graphql/resolvers/bug.go +++ b/graphql/resolvers/bug.go @@ -15,6 +15,14 @@ var _ graph.BugResolver = &bugResolver{} type bugResolver struct{} +func (bugResolver) ID(ctx context.Context, obj *bug.Snapshot) (string, error) { + return obj.Id().String(), nil +} + +func (bugResolver) HumanID(ctx context.Context, obj *bug.Snapshot) (string, error) { + return obj.Id().Human(), nil +} + func (bugResolver) Status(ctx context.Context, obj *bug.Snapshot) (models.Status, error) { return convertStatus(obj.Status) } diff --git a/graphql/resolvers/identity.go b/graphql/resolvers/identity.go index 05f7207e..ee40d4d8 100644 --- a/graphql/resolvers/identity.go +++ b/graphql/resolvers/identity.go @@ -12,11 +12,11 @@ var _ graph.IdentityResolver = &identityResolver{} type identityResolver struct{} func (identityResolver) ID(ctx context.Context, obj *identity.Interface) (string, error) { - return (*obj).Id(), nil + return (*obj).Id().String(), nil } func (identityResolver) HumanID(ctx context.Context, obj *identity.Interface) (string, error) { - return (*obj).HumanId(), nil + return (*obj).Id().Human(), nil } func (identityResolver) Name(ctx context.Context, obj *identity.Interface) (*string, error) { diff --git a/graphql/resolvers/operations.go b/graphql/resolvers/operations.go index 19b2b17f..3080c98b 100644 --- a/graphql/resolvers/operations.go +++ b/graphql/resolvers/operations.go @@ -6,39 +6,74 @@ import ( "time" "github.com/MichaelMure/git-bug/bug" + "github.com/MichaelMure/git-bug/graphql/graph" "github.com/MichaelMure/git-bug/graphql/models" ) +var _ graph.CreateOperationResolver = createOperationResolver{} + type createOperationResolver struct{} +func (createOperationResolver) ID(ctx context.Context, obj *bug.CreateOperation) (string, error) { + return obj.Id().String(), nil +} + func (createOperationResolver) Date(ctx context.Context, obj *bug.CreateOperation) (*time.Time, error) { t := obj.Time() return &t, nil } +var _ graph.AddCommentOperationResolver = addCommentOperationResolver{} + type addCommentOperationResolver struct{} +func (addCommentOperationResolver) ID(ctx context.Context, obj *bug.AddCommentOperation) (string, error) { + return obj.Id().String(), nil +} + func (addCommentOperationResolver) Date(ctx context.Context, obj *bug.AddCommentOperation) (*time.Time, error) { t := obj.Time() return &t, nil } +var _ graph.EditCommentOperationResolver = editCommentOperationResolver{} + type editCommentOperationResolver struct{} +func (editCommentOperationResolver) ID(ctx context.Context, obj *bug.EditCommentOperation) (string, error) { + return obj.Id().String(), nil +} + +func (editCommentOperationResolver) Target(ctx context.Context, obj *bug.EditCommentOperation) (string, error) { + panic("implement me") +} + func (editCommentOperationResolver) Date(ctx context.Context, obj *bug.EditCommentOperation) (*time.Time, error) { t := obj.Time() return &t, nil } -type labelChangeOperation struct{} +var _ graph.LabelChangeOperationResolver = labelChangeOperationResolver{} + +type labelChangeOperationResolver struct{} -func (labelChangeOperation) Date(ctx context.Context, obj *bug.LabelChangeOperation) (*time.Time, error) { +func (labelChangeOperationResolver) ID(ctx context.Context, obj *bug.LabelChangeOperation) (string, error) { + return obj.Id().String(), nil +} + +func (labelChangeOperationResolver) Date(ctx context.Context, obj *bug.LabelChangeOperation) (*time.Time, error) { t := obj.Time() return &t, nil } +var _ graph.SetStatusOperationResolver = setStatusOperationResolver{} + type setStatusOperationResolver struct{} +func (setStatusOperationResolver) ID(ctx context.Context, obj *bug.SetStatusOperation) (string, error) { + return obj.Id().String(), nil +} + func (setStatusOperationResolver) Date(ctx context.Context, obj *bug.SetStatusOperation) (*time.Time, error) { t := obj.Time() return &t, nil @@ -48,8 +83,14 @@ func (setStatusOperationResolver) Status(ctx context.Context, obj *bug.SetStatus return convertStatus(obj.Status) } +var _ graph.SetTitleOperationResolver = setTitleOperationResolver{} + type setTitleOperationResolver struct{} +func (setTitleOperationResolver) ID(ctx context.Context, obj *bug.SetTitleOperation) (string, error) { + return obj.Id().String(), nil +} + func (setTitleOperationResolver) Date(ctx context.Context, obj *bug.SetTitleOperation) (*time.Time, error) { t := obj.Time() return &t, nil diff --git a/graphql/resolvers/repo.go b/graphql/resolvers/repo.go index 68a3ce0a..ac9c162f 100644 --- a/graphql/resolvers/repo.go +++ b/graphql/resolvers/repo.go @@ -5,6 +5,7 @@ import ( "github.com/MichaelMure/git-bug/bug" "github.com/MichaelMure/git-bug/cache" + "github.com/MichaelMure/git-bug/entity" "github.com/MichaelMure/git-bug/graphql/connections" "github.com/MichaelMure/git-bug/graphql/graph" "github.com/MichaelMure/git-bug/graphql/models" @@ -38,7 +39,7 @@ func (repoResolver) AllBugs(ctx context.Context, obj *models.Repository, after * source := obj.Repo.QueryBugs(query) // The edger create a custom edge holding just the id - edger := func(id string, offset int) connections.Edge { + edger := func(id entity.Id, offset int) connections.Edge { return connections.LazyBugEdge{ Id: id, Cursor: connections.OffsetToCursor(offset), @@ -46,7 +47,7 @@ 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 []string, info *models.PageInfo, totalCount int) (*models.BugConnection, error) { + 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)) @@ -99,7 +100,7 @@ func (repoResolver) AllIdentities(ctx context.Context, obj *models.Repository, a source := obj.Repo.AllIdentityIds() // The edger create a custom edge holding just the id - edger := func(id string, offset int) connections.Edge { + edger := func(id entity.Id, offset int) connections.Edge { return connections.LazyIdentityEdge{ Id: id, Cursor: connections.OffsetToCursor(offset), @@ -107,7 +108,7 @@ 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 []string, info *models.PageInfo, totalCount int) (*models.IdentityConnection, error) { + 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)) diff --git a/graphql/resolvers/root.go b/graphql/resolvers/root.go index 8873b723..3b129f3b 100644 --- a/graphql/resolvers/root.go +++ b/graphql/resolvers/root.go @@ -87,7 +87,7 @@ func (r RootResolver) EditCommentOperation() graph.EditCommentOperationResolver } func (RootResolver) LabelChangeOperation() graph.LabelChangeOperationResolver { - return &labelChangeOperation{} + return &labelChangeOperationResolver{} } func (RootResolver) SetStatusOperation() graph.SetStatusOperationResolver { diff --git a/graphql/resolvers/timeline.go b/graphql/resolvers/timeline.go index 27f799ba..b206f898 100644 --- a/graphql/resolvers/timeline.go +++ b/graphql/resolvers/timeline.go @@ -5,9 +5,12 @@ import ( "time" "github.com/MichaelMure/git-bug/bug" + "github.com/MichaelMure/git-bug/graphql/graph" "github.com/MichaelMure/git-bug/graphql/models" ) +var _ graph.CommentHistoryStepResolver = commentHistoryStepResolver{} + type commentHistoryStepResolver struct{} func (commentHistoryStepResolver) Date(ctx context.Context, obj *bug.CommentHistoryStep) (*time.Time, error) { @@ -15,8 +18,14 @@ func (commentHistoryStepResolver) Date(ctx context.Context, obj *bug.CommentHist return &t, nil } +var _ graph.AddCommentTimelineItemResolver = addCommentTimelineItemResolver{} + type addCommentTimelineItemResolver struct{} +func (addCommentTimelineItemResolver) ID(ctx context.Context, obj *bug.AddCommentTimelineItem) (string, error) { + return obj.Id().String(), nil +} + func (addCommentTimelineItemResolver) CreatedAt(ctx context.Context, obj *bug.AddCommentTimelineItem) (*time.Time, error) { t := obj.CreatedAt.Time() return &t, nil @@ -27,8 +36,14 @@ func (addCommentTimelineItemResolver) LastEdit(ctx context.Context, obj *bug.Add return &t, nil } +var _ graph.CreateTimelineItemResolver = createTimelineItemResolver{} + type createTimelineItemResolver struct{} +func (createTimelineItemResolver) ID(ctx context.Context, obj *bug.CreateTimelineItem) (string, error) { + return obj.Id().String(), nil +} + func (createTimelineItemResolver) CreatedAt(ctx context.Context, obj *bug.CreateTimelineItem) (*time.Time, error) { t := obj.CreatedAt.Time() return &t, nil @@ -39,15 +54,27 @@ func (createTimelineItemResolver) LastEdit(ctx context.Context, obj *bug.CreateT return &t, nil } +var _ graph.LabelChangeTimelineItemResolver = labelChangeTimelineItem{} + type labelChangeTimelineItem struct{} +func (labelChangeTimelineItem) ID(ctx context.Context, obj *bug.LabelChangeTimelineItem) (string, error) { + return obj.Id().String(), nil +} + func (labelChangeTimelineItem) Date(ctx context.Context, obj *bug.LabelChangeTimelineItem) (*time.Time, error) { t := obj.UnixTime.Time() return &t, nil } +var _ graph.SetStatusTimelineItemResolver = setStatusTimelineItem{} + type setStatusTimelineItem struct{} +func (setStatusTimelineItem) ID(ctx context.Context, obj *bug.SetStatusTimelineItem) (string, error) { + return obj.Id().String(), nil +} + func (setStatusTimelineItem) Date(ctx context.Context, obj *bug.SetStatusTimelineItem) (*time.Time, error) { t := obj.UnixTime.Time() return &t, nil @@ -57,8 +84,14 @@ func (setStatusTimelineItem) Status(ctx context.Context, obj *bug.SetStatusTimel return convertStatus(obj.Status) } +var _ graph.SetTitleTimelineItemResolver = setTitleTimelineItem{} + type setTitleTimelineItem struct{} +func (setTitleTimelineItem) ID(ctx context.Context, obj *bug.SetTitleTimelineItem) (string, error) { + return obj.Id().String(), nil +} + func (setTitleTimelineItem) Date(ctx context.Context, obj *bug.SetTitleTimelineItem) (*time.Time, error) { t := obj.UnixTime.Time() return &t, nil |