From 95cc3af32b4ab5b65c2079031515107e6a93e7cc Mon Sep 17 00:00:00 2001 From: Ragnar Rova Date: Tue, 3 Dec 2019 12:57:36 +0100 Subject: [PATCH] Treat non-nullable scalars as scalars When using a non-nullable scalar as input type a regression was introduced by the upgrade of jackson. A jackson exception occurs internally in the MethodFieldResolver because the correct deserialiser/serialiser cannot be found. Somehow this was hidden when using earlier versions of jackson where this just worked anyhow, but due to changes in jackson this bug is uncovered. The correct way is of course to fix this in isScalarType to cover non-nullable scalars, and not rely on functionality in jackson which no longer seems to be supported. --- .../coxautodev/graphql/tools/MethodFieldResolver.kt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/com/coxautodev/graphql/tools/MethodFieldResolver.kt b/src/main/kotlin/com/coxautodev/graphql/tools/MethodFieldResolver.kt index 89465f33..d3959628 100644 --- a/src/main/kotlin/com/coxautodev/graphql/tools/MethodFieldResolver.kt +++ b/src/main/kotlin/com/coxautodev/graphql/tools/MethodFieldResolver.kt @@ -11,7 +11,7 @@ import graphql.language.Type import graphql.language.TypeName import graphql.schema.DataFetcher import graphql.schema.DataFetchingEnvironment -import graphql.schema.GraphQLTypeUtil.isScalar +import graphql.schema.GraphQLTypeUtil.* import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.future.future import java.lang.reflect.Method @@ -121,12 +121,14 @@ internal class MethodFieldResolver(field: FieldDefinition, search: FieldResolver } private fun isScalarType(environment: DataFetchingEnvironment, type: Type<*>, genericParameterType: JavaType): Boolean = - when (type) { - is ListType -> + when { + type is ListType -> List::class.java.isAssignableFrom(this.genericType.getRawClass(genericParameterType)) && isScalarType(environment, type.type, this.genericType.unwrapGenericType(genericParameterType)) - is TypeName -> + type is TypeName -> environment.graphQLSchema?.getType(type.name)?.let { isScalar(it) } ?: false + type is NonNullType && type.type is TypeName -> + environment.graphQLSchema?.getType((type.type as TypeName).name)?.let { isScalar(unwrapNonNull(it)) } ?: false else -> false }