Expand my Community achievements bar.

Submissions are now open for the 2026 Adobe Experience Maker Awards.
SOLVED

AEM GraphQL Query approach to get list of pages where XYZ component is enabled.

Avatar

Level 2

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?

 

1 Accepted Solution

Avatar

Correct answer by
Level 10

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.

JCR‑SQL2 query:

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'

QueryBuilder predicate:

path=/content/site
type=cq:PageContent
property=sling:resourceType
property.value=apps/xyz/components/comp
p.limit=-1

 

View solution in original post

2 Replies

Avatar

Community Advisor

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:

  1. Create a Sling Model that exposes “page + component usage” as a custom type.

  2. Register that Sling Model with the com.adobe.cq.graphql annotations (or via the Model Exporter).

  3. Then query it through GraphQL.

This way you essentially map the page/component info into a GraphQL type, but it requires custom dev work.

c. Indexing component usage into a Content Fragment or external DB

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


Santosh Sai

AEM BlogsLinkedIn


Avatar

Correct answer by
Level 10

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.

JCR‑SQL2 query:

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'

QueryBuilder predicate:

path=/content/site
type=cq:PageContent
property=sling:resourceType
property.value=apps/xyz/components/comp
p.limit=-1