From f4c6fca42f4cb7a06377529e2d7c7b6b81a1c373 Mon Sep 17 00:00:00 2001 From: rstoyanchev Date: Tue, 7 May 2024 17:45:57 +0100 Subject: [PATCH] Update docs for blocking controller method support See gh-958 --- .../modules/ROOT/pages/controllers.adoc | 34 +++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/spring-graphql-docs/modules/ROOT/pages/controllers.adoc b/spring-graphql-docs/modules/ROOT/pages/controllers.adoc index 740e0c79..e00cdce7 100644 --- a/spring-graphql-docs/modules/ROOT/pages/controllers.adoc +++ b/spring-graphql-docs/modules/ROOT/pages/controllers.adoc @@ -125,7 +125,7 @@ method arguments and return values.. [[controllers.schema-mapping.signature]] -=== Method Signature +=== Method Arguments Schema mapping handler methods can have any of the following method arguments: @@ -208,6 +208,10 @@ See xref:controllers.adoc#controllers.schema-mapping.data-loader[`DataLoader`]. |=== + +[[controllers.schema-mapping.return.values]] +=== Return Values + Schema mapping handler methods can return: - A resolved value of any type. @@ -217,6 +221,16 @@ Schema mapping handler methods can return: - `java.util.concurrent.Callable` to have the value(s) produced asynchronously. For this to work, `AnnotatedControllerConfigurer` must be configured with an `Executor`. +On Java 21+, when `AnnotatedControllerConfigurer` is configured with an `Executor`, controller +methods with a blocking method signature are invoked asynchronously. By default, a controller +method is considered blocking if it does not return an async type such as `Flux`, `Mono`, +`CompletableFuture`, and is also not a Kotlin suspending function. You can configure a +blocking controller method `Predicate` on `AnnotatedControllerConfigurer` to help +determine which methods are considered blocking. + +TIP: The Spring Boot starter for Spring for GraphQL automatically configures +`AnnotatedControllerConfigurer` with an `Executor` for virtual threads when the property +`spring.threads.virtual.enabled` is set. [[controllers.schema-mapping.interfaces]] @@ -705,7 +719,7 @@ annotation attributes. The type name can also be inherited from a class level [[controllers.batch-mapping.signature]] -=== Method Signature +=== Method Arguments Batch mapping methods support the following arguments: @@ -731,9 +745,12 @@ Batch mapping methods support the following arguments: | The environment that is available in GraphQL Java to a `org.dataloader.BatchLoaderWithContext`. - |=== + +[[controllers.batch-mapping.return.values]] +=== Return Values + Batch mapping methods can return: [cols="1,2"] @@ -759,6 +776,17 @@ Batch mapping methods can return: |=== +On Java 21+, when `AnnotatedControllerConfigurer` is configured with an `Executor`, controller +methods with a blocking method signature are invoked asynchronously. By default, a controller +method is considered blocking if it does not return an async type such as `Flux`, `Mono`, +`CompletableFuture`, and is also not a Kotlin suspending function. You can configure a +blocking controller method `Predicate` on `AnnotatedControllerConfigurer` to help +determine which methods are considered blocking. + +TIP: The Spring Boot starter for Spring for GraphQL automatically configures +`AnnotatedControllerConfigurer` with an `Executor` for virtual threads when the property +`spring.threads.virtual.enabled` is set. + [[controllers.batch-mapping.interfaces]]