@@ -3,11 +3,7 @@ package graphql.kickstart.tools.resolver
3
3
import com.fasterxml.jackson.core.type.TypeReference
4
4
import graphql.TrivialDataFetcher
5
5
import graphql.kickstart.tools.*
6
- import graphql.kickstart.tools.DataClassTypeResolverInfo
7
- import graphql.kickstart.tools.ResolverError
8
- import graphql.kickstart.tools.SchemaClassScanner
9
6
import graphql.kickstart.tools.SchemaParserOptions.GenericWrapper
10
- import graphql.kickstart.tools.TypeClassMatcher
11
7
import graphql.kickstart.tools.util.JavaType
12
8
import graphql.kickstart.tools.util.coroutineScope
13
9
import graphql.kickstart.tools.util.isTrivialDataFetcher
@@ -64,23 +60,21 @@ internal class MethodFieldResolver(
64
60
// Add an argument for each argument defined in the GraphQL schema
65
61
this .field.inputValueDefinitions.forEachIndexed { index, definition ->
66
62
67
- val genericParameterType = this .getJavaMethodParameterType(index)
63
+ val parameterType = this .getMethodParameterType(index)
64
+ ?.apply { genericType.getRawClass(this ) }
68
65
? : throw ResolverError (" Missing method type at position ${this .getJavaMethodParameterIndex(index)} , this is most likely a bug with graphql-java-tools" )
69
66
70
67
val isNonNull = definition.type is NonNullType
71
- val isOptional = this .genericType.getRawClass(genericParameterType) == Optional ::class .java
72
-
73
- val typeReference = object : TypeReference <Any >() {
74
- override fun getType () = genericParameterType
75
- }
68
+ val isOptional = this .genericType.getRawClass(parameterType) == Optional ::class .java
76
69
77
70
args.add { environment ->
78
- val value = environment.arguments[definition.name] ? : if (isNonNull) {
71
+ val argumentPresent = environment.arguments.containsKey(definition.name)
72
+ if (! argumentPresent && isNonNull) {
79
73
throw ResolverError (" Missing required argument with name '${definition.name} ', this is most likely a bug with graphql-java-tools" )
80
- } else {
81
- null
82
74
}
83
75
76
+ val value = environment.arguments[definition.name]
77
+
84
78
if (value == null && isOptional) {
85
79
if (options.inputArgumentOptionalDetectOmission && ! environment.containsArgument(definition.name)) {
86
80
return @add null
@@ -89,12 +83,14 @@ internal class MethodFieldResolver(
89
83
}
90
84
91
85
if (value != null
92
- && genericParameterType .unwrap().isAssignableFrom(value.javaClass)
93
- && isScalarType(environment, definition.type, genericParameterType )) {
86
+ && parameterType .unwrap().isAssignableFrom(value.javaClass)
87
+ && isScalarType(environment, definition.type, parameterType )) {
94
88
return @add value
95
89
}
96
90
97
- return @add mapper.convertValue(value, typeReference)
91
+ return @add mapper.convertValue(value, object : TypeReference <Any >() {
92
+ override fun getType () = parameterType
93
+ })
98
94
}
99
95
}
100
96
@@ -140,7 +136,7 @@ internal class MethodFieldResolver(
140
136
val returnValueMatch = TypeClassMatcher .PotentialMatch .returnValue(field.type, unwrappedGenericType, genericType, SchemaClassScanner .ReturnValueReference (method))
141
137
142
138
return field.inputValueDefinitions.mapIndexed { i, inputDefinition ->
143
- TypeClassMatcher .PotentialMatch .parameterType(inputDefinition.type, getJavaMethodParameterType (i)!! , genericType, SchemaClassScanner .MethodParameterReference (method, i))
139
+ TypeClassMatcher .PotentialMatch .parameterType(inputDefinition.type, getMethodParameterType (i)!! , genericType, SchemaClassScanner .MethodParameterReference (method, i))
144
140
} + listOf (returnValueMatch)
145
141
}
146
142
@@ -154,12 +150,12 @@ internal class MethodFieldResolver(
154
150
155
151
private fun getJavaMethodParameterIndex (index : Int ) = index + getIndexOffset()
156
152
157
- private fun getJavaMethodParameterType (index : Int ): JavaType ? {
153
+ private fun getMethodParameterType (index : Int ): JavaType ? {
158
154
val methodIndex = getJavaMethodParameterIndex(index)
159
155
val parameters = method.parameterTypes
160
156
161
157
return if (parameters.size > methodIndex) {
162
- method.genericParameterTypes[getJavaMethodParameterIndex(index) ]
158
+ method.genericParameterTypes[methodIndex ]
163
159
} else {
164
160
null
165
161
}
@@ -255,4 +251,3 @@ private inline fun invoke(method: Method, instance: Any, args: Array<Any?>): Any
255
251
}
256
252
257
253
internal typealias ArgumentPlaceholder = (DataFetchingEnvironment ) -> Any?
258
-
0 commit comments