diff --git a/spring-graphql-docs/src/docs/asciidoc/index.adoc b/spring-graphql-docs/src/docs/asciidoc/index.adoc index e593feee..e9023ab0 100644 --- a/spring-graphql-docs/src/docs/asciidoc/index.adoc +++ b/spring-graphql-docs/src/docs/asciidoc/index.adoc @@ -290,11 +290,11 @@ default it is marked as `INTERNAL_ERROR`. Given a `Book` and its `Author`, we can create one `DataFetcher` for books and another for the author of a book. This means books and authors aren't automatically loaded -together, which enables queries to select the subset of data they need. However, when -loading multiple books, the author for each book is loaded individually, and this is -an issue known as the N+1 select problem. +together, which enables queries to select the subset of data they need. However, loading +multiple books, results in loading each author individually, and this is a performance +issue known as the N+1 select problem. -To address the issue, GraphQL Java provides a +GraphQL Java provides a https://www.graphql-java.com/documentation/v16/batching/[batching feature] that allows related entities, such as the authors for all books, to be loaded together. This is how the underlying mechanism works in GraphQL Java: @@ -310,7 +310,7 @@ defers until it is ready to batch load all related entities as one. - `DataLoader` additionally maintains a cache of previously loaded entities that can further improve efficiency when the same entity is in multiple places of the response. -Spring GraphQL exposes a `BatchLoaderRegistry` that accepts and stores registrations of +Spring GraphQL provides a `BatchLoaderRegistry` that accepts and stores registrations of batch loading functions. The `ExecutionGraphQlService` accepts the registry as input and uses it to make per request `DataLoader` registrations. A `DataFetcher` then looks up the `DataLoader` for an entity and uses it to load instances, or in an annotated controller, 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 dfb85436..b90de5c2 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 @@ -29,7 +29,7 @@ import org.springframework.core.annotation.AliasFor; * *
* @BatchMapping
- * public Flux<Author> author(List<Book> books) {
+ * public Mono<Map<Book, Author>> author(List<Book> books) {
* // ...
* }
*
@@ -47,17 +47,23 @@ import org.springframework.core.annotation.AliasFor;
* public class BookController {
*
* public BookController(BatchLoaderRegistry registry) {
- * registry.forTypePair(Long.class, Author.class).registerBatchLoader((ids, environment) -> ...);
+ * registry.forTypePair(Long.class, Author.class).registerMappedBatchLoader((ids, environment) -> ...);
* }
*
* @SchemaMapping
- * public Author author(Book book, DataLoader<Long, Author> dataLoader) {
+ * public CompletableFuture<Author> author(Book book, DataLoader<Long, Author> dataLoader) {
* return dataLoader.load(book.getAuthorId());
* }
*
* }
*
*
+ * In addition to returning {@code Mono