From 0ac49b1f6f8247e6ec0f8661f77833a009e7602a Mon Sep 17 00:00:00 2001 From: Jan Martiska Date: Thu, 29 Sep 2022 13:03:25 +0200 Subject: [PATCH] Run fireOnDataFetchError on batch errors --- .../datafetcher/QuarkusDefaultDataFetcher.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/extensions/smallrye-graphql/runtime/src/main/java/io/quarkus/smallrye/graphql/runtime/spi/datafetcher/QuarkusDefaultDataFetcher.java b/extensions/smallrye-graphql/runtime/src/main/java/io/quarkus/smallrye/graphql/runtime/spi/datafetcher/QuarkusDefaultDataFetcher.java index d6d6dad50050d..311891879e5a4 100644 --- a/extensions/smallrye-graphql/runtime/src/main/java/io/quarkus/smallrye/graphql/runtime/spi/datafetcher/QuarkusDefaultDataFetcher.java +++ b/extensions/smallrye-graphql/runtime/src/main/java/io/quarkus/smallrye/graphql/runtime/spi/datafetcher/QuarkusDefaultDataFetcher.java @@ -3,6 +3,7 @@ import java.util.List; import java.util.concurrent.Callable; import java.util.concurrent.CompletionStage; +import java.util.function.Consumer; import org.eclipse.microprofile.graphql.GraphQLException; @@ -110,10 +111,20 @@ private CompletionStage> invokeBatchBlocking(DataFetchingEnvironment dfe return (List) operationInvoker.invokePrivileged(arguments); }); + // this gets called on a batch error, so that error callbacks can run with the proper context too + Consumer onErrorConsumer = threadContext.contextualConsumer((Throwable exception) -> { + io.smallrye.graphql.api.Context context = dfe.getGraphQlContext().get("context"); + eventEmitter.fireOnDataFetchError(context, exception); + }); + // Here call blocking with context BlockingHelper.runBlocking(vc, contextualCallable, result); - return result.future().toCompletionStage(); - + return result.future().toCompletionStage() + .whenComplete((resultList, error) -> { + if (error != null) { + onErrorConsumer.accept(error); + } + }); } private boolean runBlocking(DataFetchingEnvironment dfe) {