@@ -6,7 +6,6 @@ import graphql.kickstart.tools.*
6
6
import graphql.kickstart.tools.SchemaParserOptions.GenericWrapper
7
7
import graphql.kickstart.tools.util.JavaType
8
8
import graphql.kickstart.tools.util.coroutineScope
9
- import graphql.kickstart.tools.util.isTrivialDataFetcher
10
9
import graphql.kickstart.tools.util.unwrap
11
10
import graphql.language.*
12
11
import graphql.schema.DataFetcher
@@ -37,13 +36,9 @@ internal class MethodFieldResolver(
37
36
38
37
private val log = LoggerFactory .getLogger(javaClass)
39
38
40
- private val additionalLastArgument =
41
- try {
42
- (method.kotlinFunction?.valueParameters?.size
43
- ? : method.parameterCount) == (field.inputValueDefinitions.size + getIndexOffset() + 1 )
44
- } catch (e: InternalError ) {
45
- method.parameterCount == (field.inputValueDefinitions.size + getIndexOffset() + 1 )
46
- }
39
+ private val isSuspendFunction = method.isSuspendFunction()
40
+ private val numberOfDeclaredParameters = method.kotlinFunction?.valueParameters?.size ? : method.parameterCount
41
+ private val hasAdditionalParameter = numberOfDeclaredParameters == (field.inputValueDefinitions.size + getIndexOffset() + 1 )
47
42
48
43
override fun createDataFetcher (): DataFetcher <* > {
49
44
val args = mutableListOf<ArgumentPlaceholder >()
@@ -100,7 +95,7 @@ internal class MethodFieldResolver(
100
95
}
101
96
102
97
// Add DataFetchingEnvironment/Context argument
103
- if (this .additionalLastArgument ) {
98
+ if (this .hasAdditionalParameter ) {
104
99
when (this .method.parameterTypes.last()) {
105
100
null -> throw ResolverError (" Expected at least one argument but got none, this is most likely a bug with graphql-java-tools" )
106
101
options.contextClass -> args.add { environment ->
@@ -123,10 +118,10 @@ internal class MethodFieldResolver(
123
118
}
124
119
}
125
120
126
- return if (args.isEmpty() && isTrivialDataFetcher( this .method) ) {
121
+ return if (numberOfDeclaredParameters == 0 && ! isSuspendFunction ) {
127
122
LightMethodFieldResolverDataFetcher (createSourceResolver(), this .method, options)
128
123
} else {
129
- MethodFieldResolverDataFetcher (createSourceResolver(), this .method, args, options)
124
+ MethodFieldResolverDataFetcher (createSourceResolver(), this .method, args, options, isSuspendFunction )
130
125
}
131
126
}
132
127
@@ -196,10 +191,9 @@ internal class MethodFieldResolverDataFetcher(
196
191
private val method : Method ,
197
192
private val args : List <ArgumentPlaceholder >,
198
193
private val options : SchemaParserOptions ,
194
+ private val isSuspendFunction : Boolean
199
195
) : DataFetcher<Any> {
200
196
201
- private val isSuspendFunction = method.isSuspendFunction()
202
-
203
197
override fun get (environment : DataFetchingEnvironment ): Any? {
204
198
val source = sourceResolver.resolve(environment, null )
205
199
val args = this .args.map { it(environment) }.toTypedArray()
@@ -223,27 +217,18 @@ internal class MethodFieldResolverDataFetcher(
223
217
}
224
218
225
219
/* *
226
- * Similar to [MethodFieldResolverDataFetcher] but for light data fetchers which do not require the environment to be supplied unless suspend functions or
227
- * generic wrappers are used.
220
+ * Similar to [MethodFieldResolverDataFetcher] but for light data fetchers which do not require the environment to be supplied unless generic wrappers are used.
228
221
*/
229
222
internal class LightMethodFieldResolverDataFetcher (
230
223
private val sourceResolver : SourceResolver ,
231
224
private val method : Method ,
232
225
private val options : SchemaParserOptions ,
233
226
) : LightDataFetcher<Any?> {
234
227
235
- private val isSuspendFunction = method.isSuspendFunction()
236
-
237
- override fun get (fieldDefinition : GraphQLFieldDefinition , sourceObject : Any , environmentSupplier : Supplier <DataFetchingEnvironment >): Any? {
228
+ override fun get (fieldDefinition : GraphQLFieldDefinition , sourceObject : Any? , environmentSupplier : Supplier <DataFetchingEnvironment >): Any? {
238
229
val source = sourceResolver.resolve(null , sourceObject)
239
230
240
- return if (isSuspendFunction) {
241
- environmentSupplier.get().coroutineScope().future(options.coroutineContextProvider.provide()) {
242
- invokeSuspend(source, method, emptyArray())?.transformWithGenericWrapper(options.genericWrappers, environmentSupplier)
243
- }
244
- } else {
245
- invoke(method, source, emptyArray())?.transformWithGenericWrapper(options.genericWrappers, environmentSupplier)
246
- }
231
+ return invoke(method, source, emptyArray())?.transformWithGenericWrapper(options.genericWrappers, environmentSupplier)
247
232
}
248
233
249
234
override fun get (environment : DataFetchingEnvironment ): Any? {
0 commit comments