newly working with GraphQl and wondering is it possible to filter a set in a query? I'm still new to database design as well so could be an issue there. So I run the below query, managerGwPicks has a field player with is a player object containig their name etc.
This player object contains a set of all the weeks they have played which is a separate table in my database.
So as can be seen in the above image when I display the set it shows all the gameweek
data whereas ideally I would like it filtered by the gameweek:21
parameter passed to the managerGwPicks
query.
I'm not sure it should be possible as there is no direct link between the managerGwPicks
and playergwstats
tables but I'd like to be sure that my thinking is correct.
My solution for my front end would be to have two queries, one similar to what I have getting the player information and a second query using the player id and gameweek
to query playergwstats
to get the player stats for the individual week. Does this sound like a reasonable approach?
It's preferable to avoid query patterns where you have to do multiple back-and-forths between the client and the server. If you can imagine making the link on the client then you can do it directly on the server. If you can go from a managerId
and gameweek
to a list of players and you can go from players to playergwstats
then you can create a join that goes from your two parameters to all the relevant players.
I've covered patterns like this in a series of posts on GraphQL for SQL Developers - look at the join that's used to go from a booking reference to a series of tickets and flights.