Allow nested filters on links and blocks fileds

Hi,

We would like to filter nested links and block fields in the following way

{
  pageFestivalLineup {
    id
    title
    lineup(filter: {festivalLinupItem: {headliner: {eq: true}}}) {
      id
      performers {
        name
      }
      headliner
    }
  }
}

Here I want to filter lineup which is a modular block (but could also be a links field) and only return the filtered records. When you have a lot of associated links or modular blocks this helps return only the relevant data.

Regards,

Is this what you’re looking for? Deep Filtering — DatoCMS

No since that filters the “parent” record based on the childrens content. I want to filter the children specifically.

This is kind of a poor workaround, but might something like this work…?

If you are specifically worried about the query response size in this instance, would it be possible to remodel lineup as a model instead of a block?

Then, you can make the lineup field inside pageFestivalLineups a multiple links field.

Then in the GraphQL query, you could fetch just the lineup IDs inside pageFestivalLineup and then separately fetch the lineup model data with filtering, and recombine them clientside by their IDs. Like this:

query MyQuery {
  allLineupModels(filter: {headliner: {eq: "true"}}) {
    id
    headliner
    performers {
      name
    }
  }
  allPageFestivalLineups(filter: {lineup: {}}) {
    id
    title
    lineup {
      id
    }
  }
}

Which would return:

{
  "data": {
    "allLineupModels": [
      {
        "id": "lpMbI7iSQEGIaahXpOEe1w",
        "headliner": true,
        "performers": [
          {
            "name": "famous person 1"
          },
          {
            "name": "famous person 2"
          }
        ]
      }
    ],
    "allPageFestivalLineups": [
      {
        "id": "fJJNPoivQVKA8AK1JFWdeg",
        "title": "lineup1",
        "lineup": [
          {
            "id": "AMPXlSF6QGKyz1NHxsCokA"
          },
          {
            "id": "lpMbI7iSQEGIaahXpOEe1w"
          }
        ]
      }
    ]
  }
}

In this case, it is filtering out lineups where headliner=false, like this one:

      {
        "id": "AMPXlSF6QGKyz1NHxsCokA",
        "headliner": false,
        "performers": [
          {
            "name": "not very famous person"
          }
        ]
      },

In your frontend, you’d then only show the lineups whose id is also present in allLineUpModels.

Could something like that work? If not, this may have to be a feature request instead, sorry about that!

1 Like

Hi,

yes thats indeed totally possible but the problem is that it has a very bad editor experience. The advantage right now is that the complete lineup is available on one page with all information. If we create a linked field then we lose that information.

Especially if you take it a step future and have multiple events / lineups then having a linked field is a bit annoying for content editors. How can they be sure they select the right “lineup item” that matches with their event? There is no way to scope a linked list to a specific associated field for example.

Regards

Thank you for the clarification, Jan. That makes sense!

And I’m sorry – I didn’t realize this was in the Feature Request section (thought it was a support request at first). Let’s leave it here with your additional clarifications so the devs can see it soon :slight_smile: