Hey guys, does anyone have a good solution for que...
# prisma-whats-new
p
Hey guys, does anyone have a good solution for query filtering with options params?
I have a query that looks like this:
Copy code
query($pagination:Int!, $divisionId:ID, $teamId:ID, $startDate:DateTime!, $endDate:DateTime!
  ){
    games: allGames (
      orderBy: date_ASC,
      first: $pagination,
      filter: {
        date_gte: $startDate,
        date_lte: $endDate,
        division: {id: $divisionId},
        OR: [
        {homeTeam: {id: $teamId} },
        {awayTeam: {id: $teamId} },
        ]
      }
   ){
    id
   .... more fields
}
And am trying to figure out how to add a wildcard/* or something of that sort
Essentially, if
divisionId
or
teamId
is
null
, I would like the query to return all potential values for that field. I get somewhat similar functionality on
mutations
(since null is a valid parameter for omitted fields, I can write 1 mutation that will work in multiple scenarios), but am not sure how to achieve that queries
Do I need to create fragments? And call a different query when a user wants to filter
divisionId
or
teamId
?
Or do i switch
division
and
id
to
division_in
and
id_in
and pass them (somewhat large) arrays with all the possible values for for
divisionIds
and
teamIds
as initial props?
n
I think, this might be helpful, @pcooney10, feel free to chime in there or create a new thread: https://www.graph.cool/forum/t/optional-query-filters/355?u=nilan
p
Thank you @nilan! That was helpful. I ended up using the
someField_in
approach as I’d already had the arrays mapped out in the presentational dropdown in the app, but the Filter Object seems like a much better approach!
n
got it! 🙂