@@ -3,11 +3,7 @@ package graphql.kickstart.tools.resolver
33import com.fasterxml.jackson.core.type.TypeReference
44import graphql.TrivialDataFetcher
55import graphql.kickstart.tools.*
6- import graphql.kickstart.tools.DataClassTypeResolverInfo
7- import graphql.kickstart.tools.ResolverError
8- import graphql.kickstart.tools.SchemaClassScanner
96import graphql.kickstart.tools.SchemaParserOptions.GenericWrapper
10- import graphql.kickstart.tools.TypeClassMatcher
117import graphql.kickstart.tools.util.JavaType
128import graphql.kickstart.tools.util.coroutineScope
139import graphql.kickstart.tools.util.isTrivialDataFetcher
@@ -64,23 +60,21 @@ internal class MethodFieldResolver(
6460 // Add an argument for each argument defined in the GraphQL schema
6561 this .field.inputValueDefinitions.forEachIndexed { index, definition ->
6662
67- val genericParameterType = this .getJavaMethodParameterType(index)
63+ val parameterType = this .getMethodParameterType(index)
64+ ?.apply { genericType.getRawClass(this ) }
6865 ? : throw ResolverError (" Missing method type at position ${this .getJavaMethodParameterIndex(index)} , this is most likely a bug with graphql-java-tools" )
6966
7067 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
7669
7770 args.add { environment ->
78- val value = environment.arguments[definition.name] ? : if (isNonNull) {
71+ val argumentPresent = environment.arguments.containsKey(definition.name)
72+ if (! argumentPresent && isNonNull) {
7973 throw ResolverError (" Missing required argument with name '${definition.name} ', this is most likely a bug with graphql-java-tools" )
80- } else {
81- null
8274 }
8375
76+ val value = environment.arguments[definition.name]
77+
8478 if (value == null && isOptional) {
8579 if (options.inputArgumentOptionalDetectOmission && ! environment.containsArgument(definition.name)) {
8680 return @add null
@@ -89,12 +83,14 @@ internal class MethodFieldResolver(
8983 }
9084
9185 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 )) {
9488 return @add value
9589 }
9690
97- return @add mapper.convertValue(value, typeReference)
91+ return @add mapper.convertValue(value, object : TypeReference <Any >() {
92+ override fun getType () = parameterType
93+ })
9894 }
9995 }
10096
@@ -140,7 +136,7 @@ internal class MethodFieldResolver(
140136 val returnValueMatch = TypeClassMatcher .PotentialMatch .returnValue(field.type, unwrappedGenericType, genericType, SchemaClassScanner .ReturnValueReference (method))
141137
142138 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))
144140 } + listOf (returnValueMatch)
145141 }
146142
@@ -154,12 +150,12 @@ internal class MethodFieldResolver(
154150
155151 private fun getJavaMethodParameterIndex (index : Int ) = index + getIndexOffset()
156152
157- private fun getJavaMethodParameterType (index : Int ): JavaType ? {
153+ private fun getMethodParameterType (index : Int ): JavaType ? {
158154 val methodIndex = getJavaMethodParameterIndex(index)
159155 val parameters = method.parameterTypes
160156
161157 return if (parameters.size > methodIndex) {
162- method.genericParameterTypes[getJavaMethodParameterIndex(index) ]
158+ method.genericParameterTypes[methodIndex ]
163159 } else {
164160 null
165161 }
@@ -255,4 +251,3 @@ private inline fun invoke(method: Method, instance: Any, args: Array<Any?>): Any
255251}
256252
257253internal typealias ArgumentPlaceholder = (DataFetchingEnvironment ) -> Any?
258-
0 commit comments