diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/BatchMapping.java b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/BatchMapping.java
index b90de5c2..9a0e4714 100644
--- a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/BatchMapping.java
+++ b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/BatchMapping.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2021 the original author or authors.
+ * Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -95,4 +95,12 @@ public @interface BatchMapping {
*/
String typeName() default "";
+ /**
+ * Set the maximum number of keys to include a single batch, before
+ * splitting into multiple batches of keys to load.
+ *
By default this is -1 in which case there is no limit.
+ * @since 1.1
+ */
+ int maxBatchSize() default -1;
+
}
diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/AnnotatedControllerConfigurer.java b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/AnnotatedControllerConfigurer.java
index e9413a7b..a86146f4 100644
--- a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/AnnotatedControllerConfigurer.java
+++ b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/AnnotatedControllerConfigurer.java
@@ -309,11 +309,11 @@ public class AnnotatedControllerConfigurer
String typeName;
String field;
boolean batchMapping = false;
+ int batchSize = -1;
HandlerMethod handlerMethod = createHandlerMethod(method, handler, handlerType);
Annotation annotation = annotations.iterator().next();
- if (annotation instanceof SchemaMapping) {
- SchemaMapping mapping = (SchemaMapping) annotation;
+ if (annotation instanceof SchemaMapping mapping) {
typeName = mapping.typeName();
field = (StringUtils.hasText(mapping.field()) ? mapping.field() : method.getName());
}
@@ -322,6 +322,7 @@ public class AnnotatedControllerConfigurer
typeName = mapping.typeName();
field = (StringUtils.hasText(mapping.field()) ? mapping.field() : method.getName());
batchMapping = true;
+ batchSize = mapping.maxBatchSize();
}
if (!StringUtils.hasText(typeName)) {
@@ -354,7 +355,7 @@ public class AnnotatedControllerConfigurer
"No parentType specified, and a source/parent method argument was also not found: " +
handlerMethod.getShortLogMessage());
- return new MappingInfo(typeName, field, batchMapping, handlerMethod);
+ return new MappingInfo(typeName, field, batchMapping, batchSize, handlerMethod);
}
private HandlerMethod createHandlerMethod(Method method, Object handler, Class> handlerType) {
@@ -394,11 +395,16 @@ public class AnnotatedControllerConfigurer
Class> clazz = returnType.getParameterType();
Class> nestedClass = (clazz.equals(Callable.class) ? returnType.nested().getNestedParameterType() : clazz);
+ BatchLoaderRegistry.RegistrationSpec