Expand my Community achievements bar.

Get ready! An upgraded Experience League Community experience is coming in January.

Custom GraphQL Schema Not Registered with Sling Data Fetcher in AEM

Avatar

Level 1

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?

1 Reply

Avatar

Community Advisor

Hi @RajeshGa8,

Sling Data Fetcher is part of Apache Sling GraphQL Core, which is not part of AEM out of the box. You need to make sure that Apache Sling GraphQL Core bundle is installed and active on your instance (manually or via package). Without it, registering custom fetcher will not be possible.

Some links that might help: