I am acing an issue where a custom GraphQL schema is not being registered with the corresponding Sling Data Fetcher in AEM. The schema fields are not appearing in the GraphiQL editor (http://localhost:4502/aem/graphiql.html), and it seems the core issue is that the schema is not linked to the Sling Data Fetcher.
Schema File: The schema file is located at /conf/<project>/settings/graphql/example-schema.gql and contains the following definition:
type Query {
exampleData: String @fetcher(name: "exampleDataFetcher")
}
Sling Data Fetcher Implementation:
The ExampleDataFetcher class is implemented as follows:
import org.apache.sling.graphql.api.SlingDataFetcher;
import org.apache.sling.graphql.api.SlingDataFetcherEnvironment;
import org.osgi.service.component.annotations.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(
service = SlingDataFetcher.class,
property = {
"name=exampleDataFetcher"
}
)
public class ExampleDataFetcher implements SlingDataFetcher<String> {
private static final Logger LOGGER = LoggerFactory.getLogger(ExampleDataFetcher.class);
@Override
public String get(SlingDataFetcherEnvironment environment) throws Exception {
LOGGER.info("Fetching data in ExampleDataFetcher...");
return "Hello from ExampleDataFetcher!";
}
}
What additional steps are required to ensure the custom schema is registered and linked to the Sling Data Fetcher?
Are there specific configurations needed for the schema to appear in the GraphiQL editor?