package football import ( "context" "fmt" "github.com/pkg/errors" "git.lehouerou.net/laurent/sorare/graphql" ) type GamesFormationQuery struct { c *graphql.Client } type GameFormation struct { Id graphql.Id `graphql:"id"` AwayTeam struct { Team struct { Slug string `graphql:"slug"` } `graphql:"... on TeamInterface"` } `graphql:"awayTeam"` AwayFormation struct { Bench []struct { Slug string `graphql:"slug"` } `graphql:"bench"` StartingLineup [][]struct { Slug string `graphql:"slug"` } `graphql:"startingLineup"` } `graphql:"awayFormation"` HomeTeam struct { Team struct { Slug string `graphql:"slug"` } `graphql:"... on TeamInterface"` } `graphql:"homeTeam"` HomeFormation struct { Bench []struct { Slug string `graphql:"slug"` } `graphql:"bench"` StartingLineup [][]struct { Slug string `graphql:"slug"` } `graphql:"startingLineup"` } `graphql:"homeFormation"` } func NewGamesFormationQuery(c *graphql.Client) *GamesFormationQuery { return &GamesFormationQuery{ c: c, } } func (r *GamesFormationQuery) Get(ctx context.Context, gameIds []string) ([]GameFormation, error) { var q struct { Football [][2]interface{} `graphql:"football"` } q.Football = make([][2]interface{}, len(gameIds)) for i, id := range gameIds { var game GameFormation q.Football[i] = [2]interface{}{fmt.Sprintf("game%d:game(id:\"%s\")", i, id), &game} } err := r.c.Query(ctx, &q, nil) if err != nil { return nil, errors.Wrap(err, "querying games") } var res []GameFormation for _, g := range q.Football { res = append(res, *g[1].(*GameFormation)) } return res, nil }