How to Expose a Custom Resolver Field in Content Fragments for AEM GraphQL queries Without Editing the Fragment Model
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?