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?
Solved! Go to Solution.
Views
Replies
Total Likes
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-ap...
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
}
}
}
Please see the link below, the highlighted line says, that in AEM, for a GQL filter AND is implicit while OR needs to be mentioned explicitly. Can you try your query with this format:
https://experienceleague.adobe.com/docs/experience-manager-cloud-service/content/headless/graphql-ap...
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.
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-ap...
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
}
}
}
@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.
Views
Replies
Total Likes
Views
Likes
Replies