Expand my Community achievements bar.

SOLVED

Nested Content Fragments with GraphQl

Avatar

Level 1

Hello together!

 

Our setup is that we have Content Fragments from Model A that have a content reference to one Content Fragment of Model B. We want to create a GraphQl Query that returns a list of all Content Fragments from Model A that references a Content Fragment from Model B by specific path. Using SQL this works perfectly as we can just query after the jcr property in which the reference is saved as a string. In GraphQl the refernced field is already resolved as Content Fragment Model, which means it searches for all Content Fragments of Model A and only filters afterwards. As we have a lot of data the query always runs into a timeout. Is there any way I can achieve for the Graphql query to see the reference field as the raw type and not be resolved?

 

Here my Query:

 

query listOfModelsByFragmentPath($damPath: ID, $fragmentPath: ID) {
modelAList(
limit: 14
offset: 0
filter: {
_path: {_expressions: [{value: $damPath, _operator: STARTS_WITH}]},
modelBfragment: {_path: {_expressions: [{value: $fragmentPath, _operator: EQUALS}]}}}
) {
items {
url
tags
_path
headline
}
}
}

 

 

This is the same SQL Query I would like to achieve:

 

SELECT main.* FROM [dam:Asset] AS main WHERE ISDESCENDANTNODE(main, 'damPath') AND main.[jcr:content/contentFragment] = true AND main.[jcr:content/data/cq:model] = 'modelA' AND ((ISDESCENDANTNODE(main, 'damPath')) AND (([jcr:primaryType] IS NOT NULL))) AND [jcr:content/data/master/modelBfragment] = 'fragmentPath' OPTION (INDEX TAG[fragments], LIMIT 14)

 

Any help or guidance is much appreciated!

Thank you!

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

@dgshf98678 Your GraphQL query matches with the sample query given in Adobe examples below. Could you try for _match like the example below? 

https://experienceleague.adobe.com/en/docs/experience-manager-cloud-service/content/headless/graphql... 

Sample Query for Nested Content Fragments - All companies that have at least one employee that has a name of “Smith”

This query illustrates filtering for any person of name “Smith”, returning information from across two nested fragments - company and employee.

Sample Query

query {
  companyList(filter: {
    employees: {
      _match: {
        name: {
          _expressions: [
            {
              value: "Smith"
            }
          ]
        }
      }
    }
  }) {
    items {
      name
      ceo {
        name
        firstName
      }
      employees {
        name
        firstName
      }
    }
  }
}

View solution in original post

1 Reply

Avatar

Correct answer by
Community Advisor

@dgshf98678 Your GraphQL query matches with the sample query given in Adobe examples below. Could you try for _match like the example below? 

https://experienceleague.adobe.com/en/docs/experience-manager-cloud-service/content/headless/graphql... 

Sample Query for Nested Content Fragments - All companies that have at least one employee that has a name of “Smith”

This query illustrates filtering for any person of name “Smith”, returning information from across two nested fragments - company and employee.

Sample Query

query {
  companyList(filter: {
    employees: {
      _match: {
        name: {
          _expressions: [
            {
              value: "Smith"
            }
          ]
        }
      }
    }
  }) {
    items {
      name
      ceo {
        name
        firstName
      }
      employees {
        name
        firstName
      }
    }
  }
}