I want to use GraphQL Query to get list of pages where XYZ Component is enabled based on set of input parameters. I have read multiple pieces of documentation on GraphQL Queries, and I learned that GraphQL is built to work with Content Fragments. Can anyone suggest way to achieve this requirement?
Solved! Go to Solution.
Views
Replies
Total Likes
hi @Neha_Jadhav,
IMHO the recommended solution is to implement the search using either QueryBuilder or JCR-SQL2, and to expose it via a servlet. It's important to keep the scopes and indexes lean to maintain optimal performance. On the other hand, it's advisable to reserve AEM’s CF GraphQL endpoints for structured headless content modelled as Content Fragments, rather than for site page discovery.
SELECT page.*
FROM [cq:Page] AS page
INNER JOIN [nt:base] AS component ON ISDESCENDANTNODE(component, page)
WHERE ISDESCENDANTNODE(page, '/content/site')
AND component.[sling:resourceType] = 'apps/xyz/components/comp'
path=/content/site
type=cq:PageContent
property=sling:resourceType
property.value=apps/xyz/components/comp
p.limit=-1
Hi @Neha_Jadhav,
You can use AEM’s Query Builder or JCR-SQL2 to search for components within pages.
Example Query Builder JSON:
{
"type": "nt:unstructured",
"path": "/content",
"property": "sling:resourceType",
"property.value": "myproject/components/xyz"
}
This will give you all nodes where the component is used. From there you can walk up the tree to get the page.
If you really want GraphQL, you’d need to:
Create a Sling Model that exposes “page + component usage” as a custom type.
Register that Sling Model with the com.adobe.cq.graphql annotations (or via the Model Exporter).
Then query it through GraphQL.
This way you essentially map the page/component info into a GraphQL type, but it requires custom dev work.
Another approach some teams take:
Write a background job or workflow that scans pages and records where XYZ component exists.
Store that in a Content Fragment model or external index.
Then you can query it via GraphQL (since now it’s part of a CF model).
Views
Replies
Total Likes
hi @Neha_Jadhav,
IMHO the recommended solution is to implement the search using either QueryBuilder or JCR-SQL2, and to expose it via a servlet. It's important to keep the scopes and indexes lean to maintain optimal performance. On the other hand, it's advisable to reserve AEM’s CF GraphQL endpoints for structured headless content modelled as Content Fragments, rather than for site page discovery.
SELECT page.*
FROM [cq:Page] AS page
INNER JOIN [nt:base] AS component ON ISDESCENDANTNODE(component, page)
WHERE ISDESCENDANTNODE(page, '/content/site')
AND component.[sling:resourceType] = 'apps/xyz/components/comp'
path=/content/site
type=cq:PageContent
property=sling:resourceType
property.value=apps/xyz/components/comp
p.limit=-1
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies