How is everyone querying GraphQL for multiple items? | Community
Skip to main content
Preston-3
Level 4
February 11, 2026
Solved

How is everyone querying GraphQL for multiple items?

  • February 11, 2026
  • 2 replies
  • 63 views

We have need to query GraphQL in AEM for specific content fragments with a title (for example) of X or Y. That’s easy enough to do with a query like this. This is the most common example I see. 

 

query getAdventuresByActivity(
$activity1: String!
$activity2: String!
) {
adventureList(filter: {
adventureActivity: {
_logOp: OR
_expressions: [
{ value: $activity1 }
{ value: $activity2 }
]
}
}) {
items {
_path
adventureTitle
adventureActivity
adventurePrice
adventureTripLength
}
}
}

 

Then followed by a variable like this. 

{
"activity1": "Surfing",
"activity2": "Rock Climbing"
}

The issue is that we’d like to be able to query on n number of variables and there doesn’t seem to be a facility for this. You can pass in a dynamic filter expression to the persisted query, but this only works in Graphiql. I’m wondering what other folks out there are doing for a problem like this. Are you simply making multiple single filter calls to GraphQL if you need data like this? 

Best answer by sarav_prakash

Hi ​@Preston-3 , question is not clear. You are not sure of number of filters during build time? Like if client has only 2 variables, must run 2filter query. Vs if they have 3 variables, must run 3filter query ? like that? ideally graphql doesnt restrict number of variables. any number of filters can be added, as long as syxtax is right. 

I have a query with 10 variables 

query myproducts($product1:ID,$product2:ID,$product3:ID,$product4:ID,$product5:ID,$product6:ID,$product7:ID,$product8:ID,$product9:ID,$product10:ID) {
supplierContentModelList(
filter:{
_path:{_logOp:OR _expressions:[
{value:$product1},
{value:$product2},
{value:$product3},
{value:$product4},
{value:$product5},
{value:$product6},
{value:$product7},
{value:$product8},
{value:$product9},
{value:$product10}
]}
}
limit:10
offset:0
) {
items {
_path
}
}
}

Here calling client can pass 1-10 filters. Query returns list of matching CFs as array. 

 

Second, I have usecase for dynamic filter. And I created static queries for all combinations, instead of dynamic filter. True it ended with 64 queries under an endpoint. But it improved performance with tailored persisted query cached at CDN. most times client was hitting upto 7 queries only. 

 

If you can clarify exact usecase, can give example how we implemented.  

2 replies

kautuk_sahni
Community Manager
Community Manager
February 17, 2026

@EstebanBustamante ​@arunpatidar ​@MayurSatav​ @mbartlett ​@Rohan_Garg ​@MukeshYadav_ Wanted to loop you in and see if you have any perspective or lessons learned that could help us here. Your insight would be helpful, thank you!

Kautuk Sahni
sarav_prakash
Community Advisor
sarav_prakashCommunity AdvisorAccepted solution
Community Advisor
February 28, 2026

Hi ​@Preston-3 , question is not clear. You are not sure of number of filters during build time? Like if client has only 2 variables, must run 2filter query. Vs if they have 3 variables, must run 3filter query ? like that? ideally graphql doesnt restrict number of variables. any number of filters can be added, as long as syxtax is right. 

I have a query with 10 variables 

query myproducts($product1:ID,$product2:ID,$product3:ID,$product4:ID,$product5:ID,$product6:ID,$product7:ID,$product8:ID,$product9:ID,$product10:ID) {
supplierContentModelList(
filter:{
_path:{_logOp:OR _expressions:[
{value:$product1},
{value:$product2},
{value:$product3},
{value:$product4},
{value:$product5},
{value:$product6},
{value:$product7},
{value:$product8},
{value:$product9},
{value:$product10}
]}
}
limit:10
offset:0
) {
items {
_path
}
}
}

Here calling client can pass 1-10 filters. Query returns list of matching CFs as array. 

 

Second, I have usecase for dynamic filter. And I created static queries for all combinations, instead of dynamic filter. True it ended with 64 queries under an endpoint. But it improved performance with tailored persisted query cached at CDN. most times client was hitting upto 7 queries only. 

 

If you can clarify exact usecase, can give example how we implemented.