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:

  1. 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.

  2. Test it in a lower environment before applying to production.

  3. Modify query filters. Use the STARTS_WITH operator for _path instead of EQUALS 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.

  4. 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
             }
           }
         }
    
  5. 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.

  6. Check for invalid content fragments where the associated content models are missing.

  7. Clean up invalid fragments or make them valid by associating them with appropriate models.

  8. After enabling hybrid filtering or making changes, verify logs on both author and publish instances to confirm that settings are applied correctly.

  9. Use list queries sparingly when only one fragment is needed; prefer targeted queries (for example., pageByPath).

recommendation-more-help
3d58f420-19b5-47a0-a122-5c9dab55ec7f