Description
Hi, sorry if this has been requested before
As the title suggests, I would like to put forward a feature request for having the @BatchMapping
-annotation expose a maxBatchSize which will be set on the default DataLoaderOptions
for that DataLoader. As MappingInfo is collected before registration I would carefully suggest that the batchloader boolean be changed to it's own separate object which would enclose additional properties for a batchloader like this.
Annotation annotation = annotations.iterator().next();
if (annotation instanceof SchemaMapping) {
SchemaMapping mapping = (SchemaMapping) annotation;
typeName = mapping.typeName();
field = (StringUtils.hasText(mapping.field()) ? mapping.field() : method.getName());
}
else {
BatchMapping mapping = (BatchMapping) annotation;
typeName = mapping.typeName();
field = (StringUtils.hasText(mapping.field()) ? mapping.field() : method.getName());
batchMapping = BatchOptions.withMaximumBatchSize(mapping.maxBatchSize);
}
And these changes would be necessary in the MappingInfo
class, and the BatchOptions class has been omitted as that would be an implementation detail for the spring team to consider if at all implemented.
private static class MappingInfo {
private final FieldCoordinates coordinates;
private final BatchOptions batchOptions;
private final HandlerMethod handlerMethod;
public MappingInfo(String typeName, String field, BatchOptions BatchOptions, HandlerMethod handlerMethod) {
this.coordinates = FieldCoordinates.coordinates(typeName, field);
this.handlerMethod = handlerMethod;
this.batchOptions= batchOptions;
}
public FieldCoordinates getCoordinates() {
return this.coordinates;
}
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
public boolean isBatchMapping() {
return this.batchOptions != null;
}
public boolean getBatchOptions() {
return this.batchOptions;
}
public HandlerMethod getHandlerMethod() {
return this.handlerMethod;
}
@Override
public String toString() {
return this.coordinates + " -> " + this.handlerMethod;
}
}
Secondary I would like to suggest the addition of ConfigurationProperties that could act as the "default" DataLoaderOptions
and be injected into the BatchLoaderRegistry
for convenience to be able to set properties like max batch size globally, perhaps under the key spring.graphql.dataloader.options