I am currently passing some tutorials about creating a Graphql server with gqlgen and gorm (mysql server).
Here is my code
type Player struct {
ID string `json:"id"`
Name string `json:"name"`
TeamID int `json:"team_id"`
}
type Team struct {
ID string `json:"id"`
Nat3 string `json:"nat3"`
Players []*Player `json:"players"`
}
...
func (r *queryResolver) Teams(ctx context.Context) ([]*model.Team, error) {
var teams []*model.Team
r.DB.Preload("Players").Find(&teams)
return teams, nil
}
So by requesting "teams with players" it's working fine. However I am wondering if there is a way to skip preloading of Players
, when players
is not request by graphql client, like this:
query{
teams {
id
nat3
}
}
Above I do not request players
but the preloading is executed, which produces unnecessary load on mysql server.