Expand my Community achievements bar.

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

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

Avatar

Level 1

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> {
    @Override
    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?

 

3 Replies

Avatar

Level 1

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

Avatar

Level 10

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

 

 

Avatar

Community Advisor

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