Skip to content

Commit 965d0bb

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

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

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

Lines changed: 16 additions & 1 deletion
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
@@ -105,7 +106,17 @@ internal class MethodFieldResolver(field: FieldDefinition, search: FieldResolver
105106
return if (batched) {
106107
BatchedMethodFieldResolverDataFetcher(getSourceResolver(), this.method, args, options)
107108
} else {
108-
MethodFieldResolverDataFetcher(getSourceResolver(), this.method, args, options)
109+
if (args.size == 0
110+
&& this.method.parameterCount == 0
111+
&& this.method.name.startsWith("get")
112+
&& this.search.type is java.lang.Class<*>
113+
&& (this.search.type as java.lang.Class<*>).getMethod(this.method.getName()) != null
114+
) {
115+
TrivialMethodFieldResolverDataFetcher(getSourceResolver(), this.method, args, options)
116+
} else {
117+
MethodFieldResolverDataFetcher(getSourceResolver(), this.method, args, options)
118+
}
119+
109120
}
110121
}
111122

@@ -191,6 +202,10 @@ open class MethodFieldResolverDataFetcher(private val sourceResolver: SourceReso
191202
}
192203
}
193204

205+
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> {
206+
207+
}
208+
194209
private suspend inline fun MethodAccess.invokeSuspend(target: Any, methodIndex: Int, args: Array<Any?>): Any? {
195210
return suspendCoroutineUninterceptedOrReturn { continuation ->
196211
invoke(target, methodIndex, *args + continuation)

0 commit comments

Comments
 (0)