~xenrox/10man-api

8b2ba79f0125c78292f73e746e8b4f1494cc3fa5 — Thorben Günther 10 months ago 04c80ad
Add captains to getTeams; will be used for map veto
M graph/generated/generated.go => graph/generated/generated.go +100 -2
@@ 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))
		}

M graph/model/models_gen.go => graph/model/models_gen.go +4 -2
@@ 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 {

M graph/schema.graphqls => graph/schema.graphqls +2 -0
@@ 11,6 11,8 @@ type User {
type Teams {
    team1: [User!]!
    team2: [User!]!
    captain1: User!
    captain2: User!
}

type MapVote {

M graph/schema.resolvers.go => graph/schema.resolvers.go +2 -0
@@ 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
}