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..
Views
Replies
Total Likes
I am using Adobe Managed services and we are yet to be on the cloud services.
Views
Replies
Total Likes
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.
Views
Replies
Total Likes
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.
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies