Skip to content

Commit

Permalink
Merge pull request #28285 from jmartisk/main-issue-28184
Browse files Browse the repository at this point in the history
Run fireOnDataFetchError on batch errors
  • Loading branch information
phillip-kruger authored Sep 29, 2022
2 parents 8b7d265 + 0ac49b1 commit 8da3049
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -110,10 +111,20 @@ private CompletionStage<List<T>> invokeBatchBlocking(DataFetchingEnvironment dfe
return (List<T>) operationInvoker.invokePrivileged(arguments);
});

// this gets called on a batch error, so that error callbacks can run with the proper context too
Consumer<Throwable> 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) {
Expand Down

0 comments on commit 8da3049

Please sign in to comment.