GraphQL “includeVariations” returns empty with filters in AEMaaCS
In AEMaaCS, the includeVariations:true
parameter in a GraphQL query returns empty results when an additional filter (for example, _path
)is applied. This happens when fetching content fragment variations with specific filters. To fix this issue, enable hybrid filtering and modify the query filter.
Description description
Environment
- Product: Adobe Experience Manager (AEM) as a Cloud Service – Sites
- Instance: Development
Issue/Symptoms
- Using
includeVariations:true
returns correct results. - Adding filters (for example,
_path
) results in empty query output. - Occurs when fetching content fragment variations with filters
Resolution resolution
To resolve the issue, follow these steps:
-
Enable hybrid filtering by adding the
cfGlobalVersion=1
property to/content/dam
. It improves query performance and fixes path-based filtering issues. Refer the Use AEM GraphQL hybrid filtering documentation for more details. -
Test it in a lower environment before applying to production.
-
Modify query filters. Use the
STARTS_WITH
operator for_path
instead ofEQUALS
in expressions:code language-none [ { value: "/content/dam/content-fragments/sites/example-path/", _operator: STARTS_WITH } ]
Note: This workaround does not work if hybrid filtering is enabled.
-
If multiple variations are required, explicitly query each variation using aliases, as shown below:
code language-none query($path: String!) { standard: pageByPath(_path: $path, variation: "standard") { item { _path title _variation } } premier: pageByPath(_path: $path, variation: "premier") { item { _path title _variation } } }
-
To optimize query design, if only one specific variation is needed, specify it directly in the query using the variation parameter instead of relying on
includeVariations: true
. -
Check for invalid content fragments where the associated content models are missing.
-
Clean up invalid fragments or make them valid by associating them with appropriate models.
-
After enabling hybrid filtering or making changes, verify logs on both author and publish instances to confirm that settings are applied correctly.
-
Use list queries sparingly when only one fragment is needed; prefer targeted queries (for example.,
pageByPath
).
Related reading
- Updating your Content Fragments for optimized GraphQL Filtering in AEM as a Cloud Service user guide.
- Optimize GraphQL queries in AEM documentation.