Graphql - How to Filter a Nested List

Graphql - How to Filter a Nested List

I am currently trying to filter a nested list based on a given id, but don't understand the syntax required. Although I have altered the entities and properties, this is what I am attempting

{
  companies{
    company{
      id,
      name,
      offices(where:{officeId: {eq: 2}}){
        officeId,
        address,
      }
    }
  }
}

In the returned data, I would like ALL companies and their offices where the office id is equal to 2. Is this possible and how would I do this?

2 Answers

This way you filter the offices inside all companies Try this

{
  companies(where:{company: {offices: {some: {officeId: {eq: 2}}}}}){
    company {
      id 
      name 
      offices {
        officeId
        address
      }
    }
  }
}
4
companies(
  where:{
    company: {
      offices: {
        some: {IsActive: {eq: true}}
      }
    }
  }
)

If filter is boolean then query doesn't work if Offices has IsActive bool field

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Alexander Ross
Author

Alexander Ross

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.