How to Expose a Custom Resolver Field in Content Fragments for AEM GraphQL queries Without Editing the Fragment Model | Community
Skip to main content
New Member
September 19, 2025
Solved

How to Expose a Custom Resolver Field in Content Fragments for AEM GraphQL queries Without Editing the Fragment Model

  • September 19, 2025
  • 3 replies
  • 2494 views

I have created a custom SlingDataFetcher resolver and I want to use the cq:Name (node name) in my GraphQL query:

 

import org.apache.sling.graphql.api.SlingDataFetcher; import org.apache.sling.graphql.api.SlingDataFetcherEnvironment; import org.osgi.service.component.annotations.Component; @Component(service = SlingDataFetcher.class, property = {"name=nodeName"}) public class GraphQLResolver implements SlingDataFetcher<String> { @9944223 public String get(SlingDataFetcherEnvironment env) { return env.getCurrentResource() != null ? env.getCurrentResource().getName() : null; } }

 

I would like to use this nodeName field and be able to query it from the GraphQL Editor or in a persisted query (located at /conf/project/settings/graphql/persistentQueries).
However, I am unable to access nodeName in my GraphQL queries..

 

  • Is it possible to expose this custom resolver field (nodeName) for GraphQL queries without editing the existing content fragment model?
  • How should the schema be defined or extended in AEM to support this, especially when not using schema files?
  • Is there a configuration or mapping that allows this field to be available without modifying the fragment model?

 

Best answer by HrishikeshKagne

Hi @arthiselva ,

 

No, you cannot expose a new GraphQL field without touching the schema. In AEM GraphQL, the schema is auto-generated from Content Fragment Models. If the field is not in the model, GraphQL won’t know about it, even if you have a custom SlingDataFetcher.

Your custom SlingDataFetcher works only if the schema already has a field mapped to it. That mapping comes from either:

Adding a field in the Content Fragment Model and assigning your data fetcher, or

Using a custom schema extension (SDL file) where you declare the field and wire it to your fetcher.

You must define the field in the schema (via CF model or SDL extension).

There is no config in AEM 6.5 AMS that will auto-expose nodeName without schema changes.

3 replies

New Member
September 19, 2025

I am using Adobe Managed services and we are yet to be on the cloud services.

giuseppebaglio
Level 10
September 19, 2025

hi @arthiselva

Your SlingDataFetcher implementation and registration are the right starting point, but you also need to declare or extend the GraphQL schema to include a new field (nodeName) in the relevant GraphQL type exposed by Content Fragments.

Please take a look here and here

 

 
HrishikeshKagne
Community Advisor
HrishikeshKagneCommunity AdvisorAccepted solution
Community Advisor
September 19, 2025

Hi @arthiselva ,

 

No, you cannot expose a new GraphQL field without touching the schema. In AEM GraphQL, the schema is auto-generated from Content Fragment Models. If the field is not in the model, GraphQL won’t know about it, even if you have a custom SlingDataFetcher.

Your custom SlingDataFetcher works only if the schema already has a field mapped to it. That mapping comes from either:

Adding a field in the Content Fragment Model and assigning your data fetcher, or

Using a custom schema extension (SDL file) where you declare the field and wire it to your fetcher.

You must define the field in the schema (via CF model or SDL extension).

There is no config in AEM 6.5 AMS that will auto-expose nodeName without schema changes.

Hrishikesh Kagane