Netflix / dgs-framework

GraphQL for Java with Spring Boot made easy.
https://netflix.github.io/dgs
Apache License 2.0
3.03k stars 286 forks source link

Avoid wrapping checked Exceptions in DataFetcherInvoker #1788

Closed kilink closed 5 months ago

kilink commented 5 months ago

DataFetcherInvoker implements the DataFetcher interface, and its "get" method declares that it throws Exception, which means propagating checked exceptions is not a problem. Howver, we were leveraging the Spring helper method, ReflectionUtils.handleReflectionException, which is designed to be called from methods that do not throw any checked exceptions, so we were ending up wrapping them unnecessarily in UndeclaredThrowableException. This caused an unnecessary layer of indirection that would need to be dealt with for example in a DataFetcherExceptionHandler.

To avoid the problem, stop using the Spring utility to invoke methods reflectively in DataFetcherInvoker, and leverage our own helper method that never throws UndeclaredThrowableException.

Fixes #1098