Reputation: 11
I have created a simple graphQL schema as follows,
type Query {
showsByIds(input: ShowsByIdsInput!
) : ShowsByIdsOutput!
}
input ShowsByIdsInput {
ids: [ID]!
}
type ShowsByIdsOutput {
ids: [Show!]!
}
type Show @key(fields: "id"){
id: ID!
actors: Actor!
}
type Actor {
name: String!
}
My DataFetcher looks as follows:
@DgsComponent
public class ShowDataFetcher {
@DgsQuery
public ShowsByIdsOutput showsByIds(
@InputArgument final ShowsByIdsInput input) {
return ShowsByIdsOutput.newBuilder().build();
}
@DgsData(parentType = "Show")
public CompletableFuture<Actor> actors(
final DgsDataFetchingEnvironment env) {
final DataLoader<String, Show> dataLoader = env.getDataLoader(
ActorDataLoader.class);
final Show test = env.getSource();
return dataLoader.load(test.getId())
.thenApply(show -> show.getAtcors());
}
My Data Loader looks as follows:
@DgsDataLoader(maxBatchSize = 1)
public class ActorDataLoader implements
MappedBatchLoader<String, Show> {
@Override
public CompletionStage<Map<String, Listing>> load(final Set<String> keys) {
final int cpunt = keys.size();
return null;
}
}
The problem is I keep getting error in the data fetcher class while trying to get dataloader from DgsDataFetchingEnvironment. The Data loader class is not registered at application startup which is why I get exception java.lang.NullPointerException: {\n dfe.getDat…s, annotation))\n } must not be null
I am not sure why the dataloader class does not get registered even after using DgsDataLoader annotation.
Upvotes: 1
Views: 794
Reputation: 1
I had the same issue, the dataloader beans were not loaded yet when the DgsDataLoaderProvider bean is initialized. In our case we found a jakarta outdated dependency was causing the issue. Anyways this config would help
@Component
@RequiredArgsConstructor
public class DataLoadersInitializer implements SmartInitializingSingleton {
private final DgsDataLoaderProvider provider;
@Override
public void afterSingletonsInstantiated() {
provider.findDataLoaders$graphql_dgs();
}
}
Upvotes: 0