If I have the following query ``` { allReports(...
# prisma-whats-new
n
If I have the following query
Copy code
{
  allReports(filter: {
    dbrw_gte: 5,
    dbrw_lte: 48,
    manufacturer:{
      id_in: [
        "cj31o9k4y6jxo0127rybvmsac",
      ]
    },
    doorType_in: [
      "Single"
    ]
  }) {
    id
    dbrw
    manufacturer {
      name
    }
    doorType
    doorWidth
  }
}
If I’m using Apollo for example, Is it possible to conditionally include the
manufacturer id_in
part? Think of this as a sidebar on Amazon for filtering products. When someone clicks a checkbox I want to add the ID to the array but if no ID is given, include them all. Possible?
n
@notrab the best way to do this, is to use a variable for the whole
manufacturer
filter object that's either
{}
or `{id_in: <some-list>}'
n
Brilliant solution. I totally forgot about the use of OR. Would this work for the doorType value too? As that's not a relation.
n
no, if you need to do it for individual fields, you need to go one level higher and define the whole
filter
as an object variable πŸ™‚
n
Oh ok. Crap. This could get messy. I'd have to put that manufacturer inside two parts then I'm guessing? And then inside three or four if I query other fields?
n
I'm not sure I understand you correctly
with Apollo, you can give in a normal JSON object as the
filter
input
that either includes the
manufacturer
key or not
n
Ok I'll experiment more and get back to you πŸ’ͺ
Thank you 😊
n
I still think this would be a great webinar topic πŸ™ˆ
πŸ‘ 1
enjoy the experiments
n
Yep it would be!
Let’s arrange a time this week and we can go through it.
πŸŽ‰ 1
Just leaving this here for anyone with similar use case
Copy code
query reports($filter: ReportFilter){
  allReports(filter: $filter) {
    id
    dbrw
    manufacturer {
      id
      name
    }
    doorType
    doorWidth
  }
}
Query variables:
Copy code
{
  "filter": {
    "manufacturer": {
      "id_in": [
        "cj31o9k4y6jxo0127rybvmsac"
      ]
    },
    "doorType_in": [
      "Double",
      "Single"
    ]
  }
}