Description
Since version 1.3. we have detected a strange behavior.
We are using the BatchLoaderRegistry
to register DataLoaders. We write some of them and some are generated using the graphql-maven-plugin.
Example of a DataLoader registration:
@Autowired // This is a constructor in a controller
public FooController(BatchLoaderRegistry registry) {
registry.forTypePair(java.lang.Long.class, FooGQL.class)
.registerMappedBatchLoader((keysSet, env) -> {
....
});
}
After upgrading to 1.3.X
we have experienced behavior, that during runtime, there are no DataLoaders available. We were able to inspect this a little bit further and find a workaround. We have detected that on application startup, the BatchLoaderRegistry
is invoked and there is a check, if some DataLoaders are configured. However, at this time, there are none of them, because the Controllers were not initialized.
Example exception:
java.lang.IllegalArgumentException: Cannot resolve DataLoader for parameter 'dataLoader' ... The DataLoaderRegistry contains: []
The workaround is to provide a custom Bean for the BatchLoaderRegistry
and to initialize it with some data loaders.
@Bean
public BatchLoaderRegistry batchLoaderRegistry()
{
var batchLoaderRegistry = new DefaultBatchLoaderRegistry();
batchLoaderRegistry
.forTypePair(String.class, FooGQL.class)
.withName("...")
.registerMappedBatchLoader((guids, batchLoaderEnvironment) ->
Mono.fromCallable(() -> ...)
);
return batchLoaderRegistry;
}
Is this expected behavior or is this a bug?