Repository: graphql-java-kickstart/graphql-java-tools (kotlin)

Issue:
Checked Exception in field resolver results in UndeclaredThrowableExceptions
## Description
Hi,

I'm not quite sure if it's a bug, but I found a strange behavior after updating to version **6.1.0**.
Since this version checked exceptions thrown in field resolver functions are getting wrapped by an `UndeclaredThrowableException`. 
The corresponding change came with this commit: https://github.com/graphql-java-kickstart/graphql-java-tools/pull/391/commits/950e291f39102c7f773cdb8e2e74a7ee827c5f58

Is there any particular reason for this implementation?

According to Oracle's [documentation](https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/UndeclaredThrowableException.html) such an exception should only be thrown if a method throws a checked exception in its body that is not declared in the method's signature.

### Expected behavior
Checked exceptions are not getting wrapped by an `UndeclaredThrowableException`, but only thrown as RuntimeExceptions and Errors. 

### Actual behavior
Checked exceptions are are getting wrapped by an `UndeclaredThrowableException`. 

### Steps to reproduce the bug
1. Define a query in the GQL scheme
```graphql
type Query {
    testQuery: String
}
```
2. Implement a corresponding resolver function and throw a checked Exception
```java 
    public String testQuery() throws Exception {
        throw new Exception();
    }
```

Pull request description:
<!-- Uncomment one of the following lines as necessary. -->
Fixes #477 and #713
<!-- Resolves #<ISSUE_NUMBER> -->

## Checklist
<!-- Change [ ] to [x] to indicate you acknowledge the check. -->
- [x] Pull requests follows the [contribution guide](https://github.com/graphql-java-kickstart/graphql-java-tools/wiki/Contribution-guide)
- [x] New or modified functionality is covered by tests

## Description
Removed usage of UndeclaredThrowableException, re-throwing original exception instead

Patch:
diff --git a/src/main/kotlin/graphql/kickstart/tools/resolver/MethodFieldResolver.kt b/src/main/kotlin/graphql/kickstart/tools/resolver/MethodFieldResolver.kt
index efd60cf7..c76023d5 100644
--- a/src/main/kotlin/graphql/kickstart/tools/resolver/MethodFieldResolver.kt
+++ b/src/main/kotlin/graphql/kickstart/tools/resolver/MethodFieldResolver.kt
@@ -15,6 +15,7 @@ import graphql.schema.DataFetchingEnvironment
 import graphql.schema.GraphQLTypeUtil.isScalar
 import kotlinx.coroutines.future.future
 import org.slf4j.LoggerFactory
+import java.lang.reflect.InvocationTargetException
 import java.lang.reflect.Method
 import java.util.*
 import kotlin.coroutines.intrinsics.suspendCoroutineUninterceptedOrReturn
@@ -251,20 +252,11 @@ private suspend inline fun invokeSuspend(target: Any, resolverMethod: Method, ar
     }
 }
 
-@Suppress("NOTHING_TO_INLINE")
-private inline fun invoke(method: Method, instance: Any, args: Array<Any?>): Any? {
+private fun invoke(method: Method, instance: Any, args: Array<Any?>): Any? {
     try {
         return method.invoke(instance, *args)
-    } catch (invocationException: java.lang.reflect.InvocationTargetException) {
-        val e = invocationException.cause
-        if (e is RuntimeException) {
-            throw e
-        }
-        if (e is Error) {
-            throw e
-        }
-
-        throw java.lang.reflect.UndeclaredThrowableException(e)
+    } catch (e: InvocationTargetException) {
+        throw  e.cause ?: RuntimeException("Unknown error occurred while invoking resolver method")
     }
 }
 


Test patch:
diff --git a/src/test/kotlin/graphql/kickstart/tools/MethodFieldResolverTest.kt b/src/test/kotlin/graphql/kickstart/tools/MethodFieldResolverTest.kt
index 1c647da0..642fe6c5 100644
--- a/src/test/kotlin/graphql/kickstart/tools/MethodFieldResolverTest.kt
+++ b/src/test/kotlin/graphql/kickstart/tools/MethodFieldResolverTest.kt
@@ -1,5 +1,6 @@
 package graphql.kickstart.tools
 
+import graphql.ExceptionWhileDataFetching
 import graphql.ExecutionInput
 import graphql.GraphQL
 import graphql.GraphQLContext
@@ -210,6 +211,34 @@ class MethodFieldResolverTest {
         assertEquals(result.getData(), mapOf("test" to 6))
     }
 
+    @Test
+    fun `should unwrap and rethrow resolver exceptions`() {
+        val schema = SchemaParser.newParser()
+            .schemaString(
+                """
+                type Query {
+                    test: String
+                }
+                """)
+            .resolvers(object : GraphQLQueryResolver {
+                fun test(): String = throw Exception("Whoops")
+            })
+            .build()
+            .makeExecutableSchema()
+
+        val gql = GraphQL.newGraphQL(schema).build()
+        val result = gql.execute(ExecutionInput.newExecutionInput().query(
+            """
+            query {
+                test
+            }
+            """))
+
+        assertEquals(result.errors.size, 1)
+        val exceptionWhileDataFetching = result.errors[0] as ExceptionWhileDataFetching
+        assertEquals(exceptionWhileDataFetching.exception.message, "Whoops")
+    }
+
     /**
      * Custom Scalar Class type that doesn't work with Jackson serialization/deserialization
      */