Skip to content

Commit 742e62b

Browse files
authored
Merge pull request #330 from cliedeman/trivial-dataloader
Add the TrivialDataFetcher interface to MethodFieldResolver so that i…
2 parents fcd00bf + 965d0bb commit 742e62b

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.ListType
@@ -116,7 +117,17 @@ internal class MethodFieldResolver(field: FieldDefinition, search: FieldResolver
116117
return if (batched) {
117118
BatchedMethodFieldResolverDataFetcher(getSourceResolver(), this.method, args, options)
118119
} else {
119-
MethodFieldResolverDataFetcher(getSourceResolver(), this.method, args, options)
120+
if (args.size == 0
121+
&& this.method.parameterCount == 0
122+
&& this.method.name.startsWith("get")
123+
&& this.search.type is java.lang.Class<*>
124+
&& (this.search.type as java.lang.Class<*>).getMethod(this.method.getName()) != null
125+
) {
126+
TrivialMethodFieldResolverDataFetcher(getSourceResolver(), this.method, args, options)
127+
} else {
128+
MethodFieldResolverDataFetcher(getSourceResolver(), this.method, args, options)
129+
}
130+
120131
}
121132
}
122133

@@ -221,6 +232,10 @@ open class MethodFieldResolverDataFetcher(private val sourceResolver: SourceReso
221232
}
222233
}
223234

235+
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> {
236+
237+
}
238+
224239
private suspend inline fun MethodAccess.invokeSuspend(target: Any, methodIndex: Int, args: Array<Any?>): Any? {
225240
return suspendCoroutineUninterceptedOrReturn { continuation ->
226241
invoke(target, methodIndex, *args + continuation)

0 commit comments

Comments
 (0)