Skip to main content
Level 4
Nov 7, 2022 6:54 AM UTC
Solved

How to execute a conjunction of OR and AND in AEM GraphQL?

I want to have a filter like this:

const value = { AND: [ { OR: [ { productVisibility_contains_none: ['authenticated', 'eap'] }, { AND: [ { productVisibility_contains_all: ['authenticated'] }, { productVisibility_contains_none: ['eap'] }, ], }, ], }, { title_exists: true }, { OR: [ { title_contains: $arg1 }, { author_contains: $arg1 }, { articleSource_contains: $arg1 }, { articleByline_contains: $arg1 }, { articleSubtitle_contains: $arg1 }, { primaryCategoryTag_contains_some: [$arg1, $arg1_cap, $arg1_low] }, { categoryTags_contains_some: [$arg1, $arg1_cap, $arg1_low] }, ], }, { primaryCategoryTag_contains: $categoryTitles }, ], };

as you can see there's conjunction of OR and AND operations, however in AEM GQL you only get either OR or AND for all the high level filters. I wanted to know if it would be possible to perform the above in AEM or not?

aanchal-sikka
aanchal-sikkaAccepted solution
Community Advisor
Feb 24, 2024 7:18 AM UTC

You would need to restructure your query. The samples for OR and And are as follows:

 

For an OR condition refer to: https://experienceleague.adobe.com/docs/experience-manager-cloud-service/content/headless/graphql-api/sample-queries.html?lang=en#sample-all-cities-d-ch-population

 

country: { _logOp: OR _expressions: [ { value: "Germany" }, { value: "Switzerland" } ] }

 

 

For and condition omit the "_logOp". Two adjacent conditions are tried via AND.

Example:
Multiple values in population is AND. And So is 'population' + 'country'

query { cityList(filter: { population: { _expressions: [ { value: 400000 _operator: GREATER_EQUAL }, { value: 1000000 _operator: LOWER } ] }, country: { _logOp: OR _expressions: [ { value: "Germany" }, { value: "Switzerland" } ] } }) { items { name population country } } }

 

Aanchal Sikka

5 replies

krati_garg
Adobe Employee
Adobe Employee
Nov 7, 2022 7:35 AM UTC
Level 4
Nov 7, 2022 7:47 AM UTC

Hello @krati_garg 

 

Thanks for the quick response, however if you see my question and compare the same with the documentation you would observe that this solution won't work for me as I need to perform a high level OR as well as AND filtering among multiple fields.

Translate
aanchal-sikka
Community Advisor
aanchal-sikkaCommunity AdvisorAccepted solution
Community Advisor
Feb 24, 2024 7:18 AM UTC

You would need to restructure your query. The samples for OR and And are as follows:

 

For an OR condition refer to: https://experienceleague.adobe.com/docs/experience-manager-cloud-service/content/headless/graphql-api/sample-queries.html?lang=en#sample-all-cities-d-ch-population

 

country: { _logOp: OR _expressions: [ { value: "Germany" }, { value: "Switzerland" } ] }

 

 

For and condition omit the "_logOp". Two adjacent conditions are tried via AND.

Example:
Multiple values in population is AND. And So is 'population' + 'country'

query { cityList(filter: { population: { _expressions: [ { value: 400000 _operator: GREATER_EQUAL }, { value: 1000000 _operator: LOWER } ] }, country: { _logOp: OR _expressions: [ { value: "Germany" }, { value: "Switzerland" } ] } }) { items { name population country } } }

 

Translate
Aanchal Sikka
Level 2
Apr 17, 2025 1:21 AM UTC

How is that the right answer?

Translate
kautuk_sahni
Level 9
Feb 28, 2024 1:08 PM UTC

@spidey1405  Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.

Translate
Kautuk Sahni