@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.
| Modifier and Type | Optional Element and Description |
|---|---|
java.lang.String |
field
Customize the name of the GraphQL field to bind to.
|
java.lang.String |
typeName
Customizes the name of the source/parent type for the GraphQL field.
|
java.lang.String |
value
Effectively an alias for
field(). |
@AliasFor(value="value") public abstract java.lang.String field
By default, if not specified, this is initialized from the method name.
@AliasFor(value="field") public abstract java.lang.String value
field().public abstract java.lang.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.