Skip to content

Commit 5cff305

Browse files
committed
Add the TrivialDataFetcher interface to MethodFieldResolver so that it can be excluded from tracing
1 parent bc6dedb commit 5cff305

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/main/kotlin/com/coxautodev/graphql/tools/MethodFieldResolver.kt

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.coxautodev.graphql.tools
33
import com.coxautodev.graphql.tools.SchemaParserOptions.GenericWrapper
44
import com.esotericsoftware.reflectasm.MethodAccess
55
import com.fasterxml.jackson.core.type.TypeReference
6+
import graphql.TrivialDataFetcher
67
import graphql.execution.batched.Batched
78
import graphql.language.FieldDefinition
89
import graphql.language.NonNullType
@@ -13,9 +14,6 @@ import kotlinx.coroutines.future.future
1314
import java.lang.reflect.Method
1415
import java.util.*
1516
import kotlin.coroutines.intrinsics.suspendCoroutineUninterceptedOrReturn
16-
import kotlin.reflect.full.valueParameters
17-
import kotlin.reflect.jvm.javaType
18-
import kotlin.reflect.jvm.kotlinFunction
1917

2018
/**
2119
* @author Andrew Potter
@@ -105,7 +103,16 @@ internal class MethodFieldResolver(field: FieldDefinition, search: FieldResolver
105103
return if (batched) {
106104
BatchedMethodFieldResolverDataFetcher(getSourceResolver(), this.method, args, options)
107105
} else {
108-
MethodFieldResolverDataFetcher(getSourceResolver(), this.method, args, options)
106+
if (args.size == 0
107+
&& this.method.getParameterCount() == 0
108+
&& this.method.getName().startsWith("get")
109+
&& this.search.type is java.lang.reflect.Class
110+
&& (this.search.type as java.lang.reflect.Class).getMethod(this.method.getName()) != null) {
111+
TrivialMethodFieldResolverDataFetcher(getSourceResolver(), this.method, args, options);
112+
} else {
113+
MethodFieldResolverDataFetcher(getSourceResolver(), this.method, args, options)
114+
}
115+
109116
}
110117
}
111118

@@ -191,6 +198,10 @@ open class MethodFieldResolverDataFetcher(private val sourceResolver: SourceReso
191198
}
192199
}
193200

201+
open class TrivialMethodFieldResolverDataFetcher(private val sourceResolver: SourceResolver, method: Method, private val args: List<ArgumentPlaceholder>, private val options: SchemaParserOptions) : MethodFieldResolverDataFetcher(sourceResolver, method, args, options), TrivialDataFetcher<Any> {
202+
203+
}
204+
194205
private suspend inline fun MethodAccess.invokeSuspend(target: Any, methodIndex: Int, args: Array<Any?>): Any? {
195206
return suspendCoroutineUninterceptedOrReturn { continuation ->
196207
invoke(target, methodIndex, *args + continuation)

0 commit comments

Comments
 (0)