From 8b2ba79f0125c78292f73e746e8b4f1494cc3fa5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorben=20G=C3=BCnther?= Date: Sat, 13 Nov 2021 22:43:55 +0100 Subject: [PATCH] Add captains to getTeams; will be used for map veto --- graph/generated/generated.go | 102 ++++++++++++++++++++++++++++++++++- graph/model/models_gen.go | 6 ++- graph/schema.graphqls | 2 + graph/schema.resolvers.go | 2 + 4 files changed, 108 insertions(+), 4 deletions(-) diff --git a/graph/generated/generated.go b/graph/generated/generated.go index 3ad131b..ac747b7 100644 --- a/graph/generated/generated.go +++ b/graph/generated/generated.go @@ -67,8 +67,10 @@ type ComplexityRoot struct { } Teams struct { - Team1 func(childComplexity int) int - Team2 func(childComplexity int) int + Captain1 func(childComplexity int) int + Captain2 func(childComplexity int) int + Team1 func(childComplexity int) int + Team2 func(childComplexity int) int } User struct { @@ -262,6 +264,20 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Query.UserByTs(childComplexity, args["teamspeakID"].(string)), true + case "Teams.captain1": + if e.complexity.Teams.Captain1 == nil { + break + } + + return e.complexity.Teams.Captain1(childComplexity), true + + case "Teams.captain2": + if e.complexity.Teams.Captain2 == nil { + break + } + + return e.complexity.Teams.Captain2(childComplexity), true + case "Teams.team1": if e.complexity.Teams.Team1 == nil { break @@ -402,6 +418,8 @@ var sources = []*ast.Source{ type Teams { team1: [User!]! team2: [User!]! + captain1: User! + captain2: User! } type MapVote { @@ -1353,6 +1371,76 @@ func (ec *executionContext) _Teams_team2(ctx context.Context, field graphql.Coll return ec.marshalNUser2ᚕᚖgitᚗxenroxᚗnetᚋאxenroxᚋ10manᚑapiᚋgraphᚋmodelᚐUserᚄ(ctx, field.Selections, res) } +func (ec *executionContext) _Teams_captain1(ctx context.Context, field graphql.CollectedField, obj *model.Teams) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "Teams", + Field: field, + Args: nil, + IsMethod: false, + IsResolver: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Captain1, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*model.User) + fc.Result = res + return ec.marshalNUser2ᚖgitᚗxenroxᚗnetᚋאxenroxᚋ10manᚑapiᚋgraphᚋmodelᚐUser(ctx, field.Selections, res) +} + +func (ec *executionContext) _Teams_captain2(ctx context.Context, field graphql.CollectedField, obj *model.Teams) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "Teams", + Field: field, + Args: nil, + IsMethod: false, + IsResolver: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Captain2, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*model.User) + fc.Result = res + return ec.marshalNUser2ᚖgitᚗxenroxᚗnetᚋאxenroxᚋ10manᚑapiᚋgraphᚋmodelᚐUser(ctx, field.Selections, res) +} + func (ec *executionContext) _User_id(ctx context.Context, field graphql.CollectedField, obj *model.User) (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { @@ -3003,6 +3091,16 @@ func (ec *executionContext) _Teams(ctx context.Context, sel ast.SelectionSet, ob if out.Values[i] == graphql.Null { invalids++ } + case "captain1": + out.Values[i] = ec._Teams_captain1(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalids++ + } + case "captain2": + out.Values[i] = ec._Teams_captain2(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalids++ + } default: panic("unknown field " + strconv.Quote(field.Name)) } diff --git a/graph/model/models_gen.go b/graph/model/models_gen.go index 1ef2333..6d65b92 100644 --- a/graph/model/models_gen.go +++ b/graph/model/models_gen.go @@ -15,8 +15,10 @@ type NewUser struct { } type Teams struct { - Team1 []*User `json:"team1"` - Team2 []*User `json:"team2"` + Team1 []*User `json:"team1"` + Team2 []*User `json:"team2"` + Captain1 *User `json:"captain1"` + Captain2 *User `json:"captain2"` } type User struct { diff --git a/graph/schema.graphqls b/graph/schema.graphqls index 779dda1..9cba1ce 100644 --- a/graph/schema.graphqls +++ b/graph/schema.graphqls @@ -11,6 +11,8 @@ type User { type Teams { team1: [User!]! team2: [User!]! + captain1: User! + captain2: User! } type MapVote { diff --git a/graph/schema.resolvers.go b/graph/schema.resolvers.go index 55b2658..d0f9030 100644 --- a/graph/schema.resolvers.go +++ b/graph/schema.resolvers.go @@ -565,6 +565,8 @@ func (r *queryResolver) GetTeams(ctx context.Context, id *int) (*model.Teams, er } teams.Team1, teams.Team2 = team1, team2 + // players with highest elo are captains + teams.Captain1, teams.Captain2 = team1[1], team2[1] return &teams, nil } -- 2.44.0