Skip to content

Commit 1a3ae73

Browse files
committed
Add Thread Model section to documentation
Closes gh-907
1 parent 7140e6c commit 1a3ae73

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed

spring-graphql-docs/modules/ROOT/pages/request-execution.adoc

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,38 @@ The xref:request-execution.adoc#execution.graphqlsource[GraphQlSource section] e
320320

321321

322322

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+
323355
[[execution.reactive-datafetcher]]
324356
== Reactive `DataFetcher`
325357

@@ -339,9 +371,10 @@ xref:request-execution.adoc#execution.context.webflux[WebFlux Context].
339371
== Context Propagation
340372

341373
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.
345378

346379

347380
[[execution.context.webmvc]]

0 commit comments

Comments
 (0)