@Target(value=METHOD) @Retention(value=RUNTIME) @Documented public @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.
public abstract String typeName
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.