You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: spring-graphql-docs/modules/ROOT/pages/controllers.adoc
+30-7
Original file line number
Diff line number
Diff line change
@@ -214,12 +214,33 @@ See xref:controllers.adoc#controllers.schema-mapping.data-loader[`DataLoader`].
214
214
215
215
Schema mapping handler methods can return:
216
216
217
-
- A resolved value of any type.
218
-
- `Mono` and `Flux` for asynchronous value(s). Supported for controller methods and for
219
-
any `DataFetcher` as described in xref:request-execution.adoc#execution.reactive-datafetcher[Reactive `DataFetcher`].
220
-
- Kotlin coroutine and `Flow` are adapted to `Mono` and `Flux`.
221
-
- `java.util.concurrent.Callable` to have the value(s) produced asynchronously.
222
-
For this to work, `AnnotatedControllerConfigurer` must be configured with an `Executor`.
217
+
[cols="1,2"]
218
+
|===
219
+
| Return Value | Description
220
+
221
+
| A resolved value `T`
222
+
| Any application type directly resolved.
223
+
224
+
| `Mono<T>` and `Flux<T>`
225
+
| For asynchronous value(s).
226
+
227
+
Supported for controller methods and for any `DataFetcher` as described in xref:request-execution.adoc#execution.reactive-datafetcher[Reactive `DataFetcher`].
228
+
229
+
| Kotlin `suspend fun` and `Flow`
230
+
| They are automatically adapted to `Mono` and `Flux`.
231
+
232
+
| `java.util.concurrent.Callable<T>`
233
+
| For producing value(s) asynchronously.
234
+
For this to work, `AnnotatedControllerConfigurer` must be configured with an `Executor`.
235
+
On Java 21+, returning `T` directly is enough. Read the paragraph after this table for more details.
236
+
237
+
| `graphql.execution.DataFetcherResult<P>`
238
+
| With `P` being any of the types listed above (`T`, `Mono<T>`, etc.).
239
+
240
+
This is the "full" GraphQL Java return value, containing not only the "data".
241
+
Useful for completing the result with "extensions" or a xref:controllers.adoc#controllers.schema-mapping.localcontext["Local Context"].
242
+
243
+
|===
223
244
224
245
On Java 21+, when `AnnotatedControllerConfigurer` is configured with an `Executor`, controller
225
246
methods with a blocking method signature are invoked asynchronously. By default, a controller
@@ -664,12 +685,14 @@ for links to relevant issues and a suggested workaround.
664
685
The main `GraphQlContext` is global for the entire query and can be used to store and retrieve cross-cutting context data for observability, security and more.
665
686
There are times when you would like to pass additional information to child fields data fetchers and avoid polluting the main context.
666
687
For such use cases, you should consider a local `GraphQLContext` as it is contained to a subset of the data fetching operations.
667
-
A well-known use case is https://www.graphql-java.com/blog/deep-dive-data-fetcher-results[data pre-fetching].
668
688
669
689
Controller methods can contribute a local context by returning a `DataFetcherResult<T>` that holds the resolved data and the new context:
If you want to see a more detailed example and discussion of using this, have a look at
694
+
https://www.graphql-java.com/blog/deep-dive-data-fetcher-results[the "Building efficient data fetchers by looking ahead" section on the graphql-java documentation].
0 commit comments