Annotation Interface BatchMapping
@BatchMapping public Mono<Map<Book, Author>> author(List<Book> books) { // ... }
The annotated method is registered as a batch loading function via
BatchLoaderRegistry
, and along
with it, a DataFetcher
for the field is registered
transparently that looks up the field value through the registered
DataLoader
.
Effectively, a shortcut for:
@Controller public class BookController { public BookController(BatchLoaderRegistry registry) { registry.forTypePair(Long.class, Author.class).registerMappedBatchLoader((ids, environment) -> ...); } @SchemaMapping public CompletableFuture<Author> author(Book book, DataLoader<Long, Author> dataLoader) { return dataLoader.load(book.getAuthorId()); } }
In addition to returning Mono<Map<K,T>>
, an @BatchMapping
method can also return Flux<T>
. However, in that case the returned
sequence of values must match the number and order of the input keys. See
BatchLoader
and MappedBatchLoader
for more details.
- Since:
- 1.0.0
- Author:
- Rossen Stoyanchev
-
Optional Element Summary
Modifier and TypeOptional ElementDescriptionCustomize the name of the GraphQL field to bind to.int
Set the maximum number of keys to include a single batch, before splitting into multiple batches of keys to load.Customizes the name of the source/parent type for the GraphQL field.Effectively an alias forfield()
.
-
Element Details
-
field
Customize the name of the GraphQL field to bind to.By default, if not specified, this is initialized from the method name.
- Default:
- ""
-
value
Effectively an alias forfield()
.- Default:
- ""
-
typeName
String typeNameCustomizes the name of the source/parent type for the GraphQL field.By default, if not specified, it is based on the simple class name of the List of source/parent values injected into the handler method.
The value for this attribute can also be inherited from a class-level
@SchemaMapping
. When used on both levels, the one here overrides the one at the class level.- Default:
- ""
-
maxBatchSize
int maxBatchSizeSet 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
- Default:
- -1
-