Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/main/kotlin/graphql/kickstart/tools/SchemaClassScanner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ internal class SchemaClassScanner(
}

private fun handleDirectiveInput(inputType: Type<*>) {
val inputTypeName = (inputType.unwrap() as TypeName).name
val inputTypeName = inputType.unwrap().name
val typeDefinition = ScalarInfo.GRAPHQL_SPECIFICATION_SCALARS_DEFINITIONS[inputTypeName]
?: definitionsByName[inputTypeName]
?: error("No ${TypeDefinition::class.java.simpleName} for type name $inputTypeName")
Expand Down Expand Up @@ -242,7 +242,7 @@ internal class SchemaClassScanner(
else -> emptyList()
}
}
.mapNotNull { (it.unwrap() as TypeName).name }
.mapNotNull { it.unwrap().name }
.toSet()
}

Expand Down Expand Up @@ -366,7 +366,7 @@ internal class SchemaClassScanner(
private fun handleInterfaceFieldTypes(): Boolean {
val newTypes = dictionary.keys.filterIsInstance<InterfaceTypeDefinition>().flatMap { iface ->
iface.withExtensions(typeExtensions).flatMap { it.fieldDefinitions }.mapNotNull { field ->
val type = definitionsByName[(field.type.unwrap() as TypeName).name]
val type = definitionsByName[field.type.unwrap().name]
if ((type is UnionTypeDefinition || type is InterfaceTypeDefinition) && !dictionary.containsKey(type)) {
type to FieldTypeReference("${iface.name}.${field.name}")
} else {
Expand Down Expand Up @@ -596,7 +596,7 @@ internal class SchemaClassScanner(
.flatMap { it.inputValueDefinitions }
.forEach { inputValueDefinition ->
val inputGraphQLType = inputValueDefinition.type.unwrap()
if (inputGraphQLType !is TypeName || ScalarInfo.GRAPHQL_SPECIFICATION_SCALARS_DEFINITIONS.containsKey(inputGraphQLType.name)) {
if (ScalarInfo.GRAPHQL_SPECIFICATION_SCALARS_DEFINITIONS.containsKey(inputGraphQLType.name)) {
return@forEach
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/graphql/kickstart/tools/TypeClassMatcher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import graphql.kickstart.tools.util.JavaType
import graphql.kickstart.tools.util.isSubtypeOf
import graphql.language.*
import graphql.schema.idl.ScalarInfo
import graphql.schema.idl.TypeUtil
import java.lang.reflect.ParameterizedType
import java.util.*

Expand All @@ -14,7 +15,7 @@ import java.util.*
*/
internal class TypeClassMatcher(private val definitionsByName: Map<String, TypeDefinition<*>>) {

private fun error(potentialMatch: PotentialMatch, msg: String) = SchemaClassScannerError("Unable to match type definition (${potentialMatch.graphQLType}) for reference ${potentialMatch.reference} with java type (${potentialMatch.javaType}): $msg")
private fun error(potentialMatch: PotentialMatch, msg: String) = SchemaClassScannerError("Unable to match type definition (${TypeUtil.simplePrint(potentialMatch.graphQLType)}) for reference ${potentialMatch.reference} with java type (${potentialMatch.javaType}): $msg")

fun match(potentialMatch: PotentialMatch): Match {
return match(potentialMatch, potentialMatch.graphQLType, potentialMatch.javaType, true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import com.fasterxml.jackson.databind.deser.std.ReferenceTypeDeserializer
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException
import graphql.kickstart.tools.resolver.MethodFieldResolver
import graphql.kickstart.tools.util.unwrap
import graphql.language.TypeName
import graphql.schema.GraphQLInputObjectField
import graphql.schema.GraphQLInputObjectType
import graphql.schema.GraphQLNamedType
Expand All @@ -33,7 +32,7 @@ internal class UnmappedInputFieldChecker(

fun check(objectType: String, resolver: MethodFieldResolver) {
resolver.field.inputValueDefinitions.forEachIndexed { index, argument ->
val inputObject = (argument.type.unwrap() as? TypeName)?.let { inputObjects[it.name] } ?: return@forEachIndexed
val inputObject = inputObjects[argument.type.unwrap().name] ?: return@forEachIndexed
val usage = "argument '${argument.name}' of field '$objectType.${resolver.field.name}'"

try {
Expand Down Expand Up @@ -138,7 +137,7 @@ internal class UnmappedInputFieldChecker(
}

private fun inputObjectOf(type: GraphQLType): GraphQLInputObjectType? =
(GraphQLTypeUtil.unwrapAllAs<GraphQLType>(type) as? GraphQLNamedType)?.let { inputObjects[it.name] }
inputObjects[GraphQLTypeUtil.unwrapAllAs<GraphQLNamedType>(type).name]

private fun consequence(mapper: ObjectMapper, inputObject: GraphQLInputObjectType, field: GraphQLInputObjectField): String =
when {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import graphql.kickstart.tools.RootResolverInfo
import graphql.kickstart.tools.SchemaParserOptions
import graphql.kickstart.tools.util.*
import graphql.language.FieldDefinition
import graphql.language.TypeName
import graphql.schema.DataFetchingEnvironment
import kotlinx.coroutines.channels.ReceiveChannel
import org.apache.commons.lang3.ClassUtils
Expand Down Expand Up @@ -159,7 +158,7 @@ internal class FieldResolverScanner(val options: SchemaParserOptions) {
isReceiveChannelWrapper && hasPublisherTransformer
}

private fun isBoolean(type: GraphQLLangType) = type.unwrap().let { it is TypeName && it.name == Scalars.GraphQLBoolean.name }
private fun isBoolean(type: GraphQLLangType) = type.unwrap().name == Scalars.GraphQLBoolean.name

private fun verifyMethodArguments(method: Method, requiredCount: Int, search: Search): Boolean {
val appropriateFirstParameter = if (search.requiredFirstParameterType != null) {
Expand Down
7 changes: 2 additions & 5 deletions src/main/kotlin/graphql/kickstart/tools/util/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import graphql.kickstart.tools.SchemaParserOptions
import graphql.kickstart.tools.TypeExtensions
import graphql.language.*
import graphql.schema.DataFetchingEnvironment
import graphql.schema.idl.TypeUtil
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import org.apache.commons.lang3.reflect.TypeUtils
Expand All @@ -29,11 +30,7 @@ internal typealias JavaType = java.lang.reflect.Type
internal typealias JavaMethod = Method
internal typealias GraphQLLangType = Type<*>

internal fun Type<*>.unwrap(): Type<*> = when (this) {
is NonNullType -> this.type.unwrap()
is ListType -> this.type.unwrap()
else -> this
}
internal fun Type<*>.unwrap(): TypeName = TypeUtil.unwrapAll(this)

internal inline fun <reified T : TypeDefinition<*>> TypeExtensions.extensionsOf(name: String): List<T> =
this[name].orEmpty().filterIsInstance<T>()
Expand Down
Loading