How to filter GraphQL query by child model?

Hiii, will keep this brief for you… trying to filter a query by child fields.

How would we filter by allHomepages that have regionCode “eu”?
(“website” is a linked model)

{
  "data": {
    "allHomepages": [
      {
        "id": "39122981",
        "pageTitle": "Common Homepage (EU, UK)",
        "website": [
          {
            "regionCode": "eu"
          },
          {
            "regionCode": "uk"
          }
        ]
      },
      {
        "id": "39293383",
        "pageTitle": "US home page",
        "website": [
          {
            "regionCode": "us"
          }
        ]
      }
    ]
  }
}

Did you figure this out yet? If not, try this:

query MyQuery {
  allHomepages(filter: {regionCode: {eq: "eu"}}) {
    id
    title
  }
}

The API Explorer tab is really helpful for this. If you click the filter entry, the first child of most content models, it’ll help you build the appropriate query.

hi @ashleigh deep filtering within links/link is not supported at the moment. You can filter why linked items id though.

So in your case, you should perform 2 queries: in the first query you search for websites having a specific regionCode and you get their ids. In the second query you search for homepages that contains the website ids you fechted before.

There is an open feature request for this at the moment: Deep filtering on both CMA and CDA - #6 by williamli You can upvote it too :slight_smile:

1 Like

Thanks @fabrizio , yes deep filtering is what we’re after.
Making do with 2 queries and an id filter for now.
Many thanks.