11package graphql.kickstart.tools
22
3- import com.esotericsoftware.reflectasm.MethodAccess
43import com.fasterxml.jackson.core.type.TypeReference
54import graphql.TrivialDataFetcher
65import graphql.execution.batched.Batched
@@ -182,9 +181,7 @@ internal class MethodFieldResolver(field: FieldDefinition, search: FieldResolver
182181
183182open class MethodFieldResolverDataFetcher (private val sourceResolver : SourceResolver , method : Method , private val args : List <ArgumentPlaceholder >, private val options : SchemaParserOptions ) : DataFetcher<Any> {
184183
185- // Convert to reflactasm reflection
186- private val methodAccess = MethodAccess .get(method.declaringClass)!!
187- private val methodIndex = methodAccess.getIndex(method.name, * method.parameterTypes)
184+ private val resolverMethod = method
188185 private val isSuspendFunction = try {
189186 method.kotlinFunction?.isSuspend == true
190187 } catch (e: InternalError ) {
@@ -206,10 +203,10 @@ open class MethodFieldResolverDataFetcher(private val sourceResolver: SourceReso
206203
207204 return if (isSuspendFunction) {
208205 environment.coroutineScope().future(options.coroutineContextProvider.provide()) {
209- methodAccess. invokeSuspend(source, methodIndex , args)?.transformWithGenericWrapper(environment)
206+ invokeSuspend(source, resolverMethod , args)?.transformWithGenericWrapper(environment)
210207 }
211208 } else {
212- methodAccess. invoke(source, methodIndex, * args)?.transformWithGenericWrapper(environment)
209+ invoke(resolverMethod, source, args)?.transformWithGenericWrapper(environment)
213210 }
214211 }
215212
@@ -236,9 +233,26 @@ open class TrivialMethodFieldResolverDataFetcher(sourceResolver: SourceResolver,
236233
237234}
238235
239- private suspend inline fun MethodAccess. invokeSuspend (target : Any , methodIndex : Int , args : Array <Any ?>): Any? {
236+ private suspend inline fun invokeSuspend (target : Any , resolverMethod : Method , args : Array <Any ?>): Any? {
240237 return suspendCoroutineUninterceptedOrReturn { continuation ->
241- invoke(target, methodIndex, * args + continuation)
238+ invoke(resolverMethod, target, args + continuation)
239+ }
240+ }
241+
242+ @Suppress(" NOTHING_TO_INLINE" )
243+ private inline fun invoke (method : Method , instance : Any , args : Array <Any ?>): Any? {
244+ try {
245+ return method.invoke(instance, * args)
246+ } catch (invocationException: java.lang.reflect.InvocationTargetException ) {
247+ val e = invocationException.cause
248+ if (e is RuntimeException ) {
249+ throw e
250+ }
251+ if (e is Error ) {
252+ throw e
253+ }
254+
255+ throw java.lang.reflect.UndeclaredThrowableException (e);
242256 }
243257}
244258
0 commit comments