From 31f50752d8714c75882cc742f725d5129c5f48a5 Mon Sep 17 00:00:00 2001 From: rstoyanchev Date: Mon, 15 Apr 2024 12:39:43 +0100 Subject: [PATCH] Update docs for batched EntityMapping methods Closes gh-922 --- .../modules/ROOT/pages/federation.adoc | 39 +++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/spring-graphql-docs/modules/ROOT/pages/federation.adoc b/spring-graphql-docs/modules/ROOT/pages/federation.adoc index b32d23f0..544b5a40 100644 --- a/spring-graphql-docs/modules/ROOT/pages/federation.adoc +++ b/spring-graphql-docs/modules/ROOT/pages/federation.adoc @@ -77,8 +77,38 @@ For example: } ---- -The `@Argument` method parameters is resolved from the "representation" input map for the entity. -You can also inject the full "representation" input `Map`. +The `@Argument` method parameters is resolved from the "representation" input map for +the entity. You can also inject the full "representation" input `Map`. See +xref:federation.adoc#federation.entity-mapping.signature[Method Signature] for all +supported method argument and return value types. + +You can batch load federated entities by returning a `List` of instances from the controller +method and accepting a `List` of argument values. In addition, you can use `@BatchMapping` +methods for subfields. + +For example: + +[source,java,indent=0,subs="verbatim,quotes"] +---- + @Controller + private static class BookController { + + @EntityMapping + public List book(@Argument List idList) { + // ... + } + + @BatchMapping + public Map author(List books) { + // ... + } + } +---- + +Note `idList` naming convention for the argument, which helps Spring for GraphQL to +de-pluralize the method parameter name and derive the correct argument name to use. +Alternatively, set the argument name through the annotation. + [[federation.entity-mapping.signature]] @@ -96,6 +126,10 @@ Entity mapping methods support the following arguments: | `Map` | The full "representation" input map for the entity. +| `List>` +| The list of "representation" input maps when using a single controller method to load + all entities of a given type. + | `@ContextValue` | For access to an attribute from the main `GraphQLContext` in `DataFetchingEnvironment`. @@ -132,4 +166,3 @@ You can use `@GraphQlExceptionHandler` methods to map exceptions from `@EntityMa methods to ``GraphQLError``'s. The errors will be included in the response of the "_entities" query. Exception handler methods can be in the same controller or in an `@ControllerAdvice` class. -