@@ -320,6 +320,38 @@ The xref:request-execution.adoc#execution.graphqlsource[GraphQlSource section] e
320
320
321
321
322
322
323
+
324
+ [[execution.thread-model]]
325
+ == Thread Model
326
+
327
+ Most GraphQL requests benefit from concurrent execution in fetching nested fields. This is
328
+ why most applications today rely on GraphQL Java's `AsyncExecutionStrategy`, which allows
329
+ data fetchers to return `CompletionStage` and to execute concurrently rather than serially.
330
+
331
+ Java 21 and virtual threads add an important ability to use more threads efficiently, but
332
+ it is still necessary to execute concurrently rather than serially in order for request
333
+ execution to complete more quickly.
334
+
335
+ Spring for GraphQL supports:
336
+
337
+ - <<execution.reactive-datafetcher, Reactive data fetchers>>, and those are
338
+ adapted to `CompletionStage` as expected by `AsyncExecutionStrategy`.
339
+ - `CompletionStage` as return value.
340
+ - Controller methods that are Kotlin coroutine methods.
341
+ - xref:controllers.adoc#controllers.schema-mapping[@SchemaMapping] and
342
+ xref:controllers.adoc#controllers.schema-mapping[@BatchMapping] methods can return
343
+ `Callable` that is submitted to an `Executor` such as the Spring Framework
344
+ `VirtualThreadTaskExecutor`. To enable this, you must configure an `Executor` on
345
+ `AnnotatedControllerConfigurer`.
346
+
347
+ Spring for GraphQL runs on either Spring MVC or WebFlux as the transport. Spring MVC
348
+ uses async request execution, unless the resulting `CompletableFuture` is done
349
+ immediately after the GraphQL Java engine returns, which would be the case if the
350
+ request is simple enough and did not require asynchronous data fetching.
351
+
352
+
353
+
354
+
323
355
[[execution.reactive-datafetcher]]
324
356
== Reactive `DataFetcher`
325
357
@@ -339,9 +371,10 @@ xref:request-execution.adoc#execution.context.webflux[WebFlux Context].
339
371
== Context Propagation
340
372
341
373
Spring for GraphQL provides support to transparently propagate context from the
342
- xref:transports.adoc#server.transports.http[HTTP], through GraphQL Java, and to `DataFetcher` and other components it
343
- invokes. This includes both `ThreadLocal` context from the Spring MVC request handling
344
- thread and Reactor `Context` from the WebFlux processing pipeline.
374
+ xref:transports.adoc#server.transports.http[HTTP] transport, through GraphQL Java, and to
375
+ `DataFetcher` and other components it invokes. This includes both `ThreadLocal` context
376
+ from the Spring MVC request handling thread and Reactor `Context` from the WebFlux
377
+ processing pipeline.
345
378
346
379
347
380
[[execution.context.webmvc]]
0 commit comments