diff options
author | Amine Hilaly <hilalyamine@gmail.com> | 2019-03-31 22:32:35 +0200 |
---|---|---|
committer | Amine Hilaly <hilalyamine@gmail.com> | 2019-04-04 00:37:57 +0200 |
commit | 2a5fbc4dc988d2eea76fe5e844ccf6425f9386ee (patch) | |
tree | 8e5125a64ff3d54fa304ae758ddbbcc427b368af /graphql | |
parent | 5b0a92dea43f467f31a65a6f02e937d285cb0a71 (diff) | |
download | git-bug-2a5fbc4dc988d2eea76fe5e844ccf6425f9386ee.tar.gz |
Expose actors and participants in snapshot and bug excerpt
Append operations authors to each list on Apply() call
Expose actors and participants in graphql
Add actor/participant query filter and documentation
Diffstat (limited to 'graphql')
-rw-r--r-- | graphql/graph/gen_graph.go | 189 | ||||
-rw-r--r-- | graphql/graphql_test.go | 30 | ||||
-rw-r--r-- | graphql/resolvers/bug.go | 21 | ||||
-rw-r--r-- | graphql/schema/bug.graphql | 2 |
4 files changed, 222 insertions, 20 deletions
diff --git a/graphql/graph/gen_graph.go b/graphql/graph/gen_graph.go index 06ebecc7..9da0c665 100644 --- a/graphql/graph/gen_graph.go +++ b/graphql/graph/gen_graph.go @@ -81,17 +81,19 @@ type ComplexityRoot struct { } Bug struct { - Id func(childComplexity int) int - HumanId func(childComplexity int) int - Status func(childComplexity int) int - Title func(childComplexity int) int - Labels func(childComplexity int) int - Author func(childComplexity int) int - CreatedAt func(childComplexity int) int - LastEdit func(childComplexity int) int - Comments func(childComplexity int, after *string, before *string, first *int, last *int) int - Timeline func(childComplexity int, after *string, before *string, first *int, last *int) int - Operations func(childComplexity int, after *string, before *string, first *int, last *int) int + Id func(childComplexity int) int + HumanId func(childComplexity int) int + Status func(childComplexity int) int + Title func(childComplexity int) int + Labels func(childComplexity int) int + Author func(childComplexity int) int + Actors func(childComplexity int) int + Participants func(childComplexity int) int + CreatedAt func(childComplexity int) int + LastEdit func(childComplexity int) int + Comments func(childComplexity int, after *string, before *string, first *int, last *int) int + Timeline func(childComplexity int, after *string, before *string, first *int, last *int) int + Operations func(childComplexity int, after *string, before *string, first *int, last *int) int } BugConnection struct { @@ -293,6 +295,9 @@ type AddCommentTimelineItemResolver interface { type BugResolver interface { Status(ctx context.Context, obj *bug.Snapshot) (models.Status, error) + Actors(ctx context.Context, obj *bug.Snapshot) ([]*identity.Interface, error) + Participants(ctx context.Context, obj *bug.Snapshot) ([]*identity.Interface, error) + LastEdit(ctx context.Context, obj *bug.Snapshot) (time.Time, error) Comments(ctx context.Context, obj *bug.Snapshot, after *string, before *string, first *int, last *int) (models.CommentConnection, error) Timeline(ctx context.Context, obj *bug.Snapshot, after *string, before *string, first *int, last *int) (models.TimelineItemConnection, error) @@ -1239,6 +1244,20 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Bug.Author(childComplexity), true + case "Bug.actors": + if e.complexity.Bug.Actors == nil { + break + } + + return e.complexity.Bug.Actors(childComplexity), true + + case "Bug.participants": + if e.complexity.Bug.Participants == nil { + break + } + + return e.complexity.Bug.Participants(childComplexity), true + case "Bug.createdAt": if e.complexity.Bug.CreatedAt == nil { break @@ -2779,6 +2798,24 @@ func (ec *executionContext) _Bug(ctx context.Context, sel ast.SelectionSet, obj if out.Values[i] == graphql.Null { invalid = true } + case "actors": + wg.Add(1) + go func(i int, field graphql.CollectedField) { + out.Values[i] = ec._Bug_actors(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + wg.Done() + }(i, field) + case "participants": + wg.Add(1) + go func(i int, field graphql.CollectedField) { + out.Values[i] = ec._Bug_participants(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + wg.Done() + }(i, field) case "createdAt": out.Values[i] = ec._Bug_createdAt(ctx, field, obj) if out.Values[i] == graphql.Null { @@ -3004,6 +3041,134 @@ func (ec *executionContext) _Bug_author(ctx context.Context, field graphql.Colle } // nolint: vetshadow +func (ec *executionContext) _Bug_actors(ctx context.Context, field graphql.CollectedField, obj *bug.Snapshot) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Bug", + Args: nil, + Field: field, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Bug().Actors(rctx, obj) + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]*identity.Interface) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + + arr1 := make(graphql.Array, len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + + for idx1 := range res { + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() + } + arr1[idx1] = func() graphql.Marshaler { + + if res[idx1] == nil { + return graphql.Null + } + + return ec._Identity(ctx, field.Selections, res[idx1]) + }() + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + + } + wg.Wait() + return arr1 +} + +// nolint: vetshadow +func (ec *executionContext) _Bug_participants(ctx context.Context, field graphql.CollectedField, obj *bug.Snapshot) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Bug", + Args: nil, + Field: field, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Bug().Participants(rctx, obj) + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]*identity.Interface) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + + arr1 := make(graphql.Array, len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + + for idx1 := range res { + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() + } + arr1[idx1] = func() graphql.Marshaler { + + if res[idx1] == nil { + return graphql.Null + } + + return ec._Identity(ctx, field.Selections, res[idx1]) + }() + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + + } + wg.Wait() + return arr1 +} + +// nolint: vetshadow func (ec *executionContext) _Bug_createdAt(ctx context.Context, field graphql.CollectedField, obj *bug.Snapshot) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() @@ -9637,6 +9802,8 @@ type Bug { title: String! labels: [Label!]! author: Identity! + actors: [Identity]! + participants: [Identity]! createdAt: Time! lastEdit: Time! diff --git a/graphql/graphql_test.go b/graphql/graphql_test.go index d571ce51..0b522b5e 100644 --- a/graphql/graphql_test.go +++ b/graphql/graphql_test.go @@ -50,6 +50,16 @@ func TestQueries(t *testing.T) { email avatarUrl } + actors { + name + email + avatarUrl + } + participants { + name + email + avatarUrl + } createdAt humanId @@ -112,7 +122,7 @@ func TestQueries(t *testing.T) { } }` - type Person struct { + type Identity struct { Name string `json:"name"` Email string `json:"email"` AvatarUrl string `json:"avatarUrl"` @@ -123,13 +133,15 @@ func TestQueries(t *testing.T) { AllBugs struct { PageInfo models.PageInfo Nodes []struct { - Author Person - CreatedAt string `json:"createdAt"` - HumanId string `json:"humanId"` - Id string - LastEdit string `json:"lastEdit"` - Status string - Title string + Author Identity + Actors []Identity + Participants []Identity + CreatedAt string `json:"createdAt"` + HumanId string `json:"humanId"` + Id string + LastEdit string `json:"lastEdit"` + Status string + Title string Comments struct { PageInfo models.PageInfo @@ -142,7 +154,7 @@ func TestQueries(t *testing.T) { Operations struct { PageInfo models.PageInfo Nodes []struct { - Author Person + Author Identity Date string Title string Files []string diff --git a/graphql/resolvers/bug.go b/graphql/resolvers/bug.go index 7af04934..f48ff0a7 100644 --- a/graphql/resolvers/bug.go +++ b/graphql/resolvers/bug.go @@ -8,6 +8,7 @@ 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.BugResolver = &bugResolver{} @@ -102,3 +103,23 @@ func (bugResolver) Timeline(ctx context.Context, obj *bug.Snapshot, after *strin func (bugResolver) LastEdit(ctx context.Context, obj *bug.Snapshot) (time.Time, error) { return obj.LastEditTime(), nil } + +func (bugResolver) Actors(ctx context.Context, obj *bug.Snapshot) ([]*identity.Interface, error) { + actorsp := make([]*identity.Interface, len(obj.Actors)) + + for i, actor := range obj.Actors { + actorsp[i] = &actor + } + + return actorsp, nil +} + +func (bugResolver) Participants(ctx context.Context, obj *bug.Snapshot) ([]*identity.Interface, error) { + participantsp := make([]*identity.Interface, len(obj.Participants)) + + for i, participant := range obj.Participants { + participantsp[i] = &participant + } + + return participantsp, nil +} diff --git a/graphql/schema/bug.graphql b/graphql/schema/bug.graphql index a1a61e7e..e294a363 100644 --- a/graphql/schema/bug.graphql +++ b/graphql/schema/bug.graphql @@ -36,6 +36,8 @@ type Bug { title: String! labels: [Label!]! author: Identity! + actors: [Identity]! + participants: [Identity]! createdAt: Time! lastEdit: Time! |