Open frederikhors opened 4 years ago
@frederikhors If I understand correctly, the simplest solution would be to only use the TeamByIdLoader
when Player.teamID
is defined.
So your player resolver for the field Team
would look like this:
func (r *playerResolver) Team(ctx context.Context, obj *entities.Player) (*entities.Team, error) {
if obj == nil || obj.TeamID == nil {
return nil, nil
}
return dataloader.For(ctx).TeamById.Load(obj.TeamID)
}
I have these entities:
As you can see:
City
is mandatoryTeam
(andTeamID
in Golang struct) is NOT mandatory, so I'm using a pointer type (*
)What I don't understand now is how to use
dataloaden
(a GraphQL dataloader).Here the generated code for
CityById
loader, generated with:go run github.com/vektah/dataloaden CityByIdLoader int *my_project/entities.City
:What about
[]*int
forTeamID
?Here's the generated code for
TeamById
loader, generated with:go run github.com/vektah/dataloaden TeamByIdLoader *int *my_project/entities.Team
:I don't understand how to re-order teams by keys if I cannot do it in DB because of
NULL
values inkeys
.