Skip to content

Commit e903223

Browse files
author
Samuel Vazquez
committed
feat: remove usages of isSubclassOf
1 parent 0bda0a8 commit e903223

File tree

5 files changed

+19
-11
lines changed

5 files changed

+19
-11
lines changed

generator/graphql-kotlin-schema-generator/src/main/kotlin/com/expediagroup/graphql/generator/internal/extensions/kClassExtensions.kt

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022 Expedia, Inc
2+
* Copyright 2025 Expedia, Inc
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -29,7 +29,6 @@ import kotlin.reflect.KVisibility
2929
import kotlin.reflect.full.declaredMemberFunctions
3030
import kotlin.reflect.full.declaredMemberProperties
3131
import kotlin.reflect.full.findParameterByName
32-
import kotlin.reflect.full.isSubclassOf
3332
import kotlin.reflect.full.memberFunctions
3433
import kotlin.reflect.full.memberProperties
3534
import kotlin.reflect.full.primaryConstructor
@@ -67,7 +66,7 @@ private fun KClass<*>.isDeclaredUnion() = this.isInterface() && this.declaredMem
6766
internal fun KClass<*>.isAnnotationUnion(fieldAnnotations: List<Annotation>): Boolean = (this.isInstance(Any::class) || this.isAnnotation()) &&
6867
fieldAnnotations.getUnionAnnotation() != null
6968

70-
internal fun KClass<*>.isAnnotation(): Boolean = this.isSubclassOf(Annotation::class)
69+
internal fun KClass<*>.isAnnotation(): Boolean = Annotation::class.java.isAssignableFrom(this.java)
7170

7271
/**
7372
* Do not add interfaces as additional types if it expects all the types
@@ -78,9 +77,9 @@ internal fun KClass<*>.isAnnotation(): Boolean = this.isSubclassOf(Annotation::c
7877
*/
7978
internal fun KClass<*>.isValidAdditionalType(inputType: Boolean): Boolean = !(inputType && this.isInterface()) && !this.isGraphQLIgnored()
8079

81-
internal fun KClass<*>.isEnum(): Boolean = this.isSubclassOf(Enum::class)
80+
internal fun KClass<*>.isEnum(): Boolean = Enum::class.java.isAssignableFrom(this.java)
8281

83-
internal fun KClass<*>.isListType(isDirective: Boolean = false): Boolean = this.isSubclassOf(List::class) || (isDirective && this.java.isArray)
82+
internal fun KClass<*>.isListType(isDirective: Boolean = false): Boolean = List::class.java.isAssignableFrom(this.java) || (isDirective && this.java.isArray)
8483

8584
@Throws(CouldNotGetNameOfKClassException::class)
8685
internal fun KClass<*>.getSimpleName(isInputClass: Boolean = false): String {

generator/graphql-kotlin-schema-generator/src/main/kotlin/com/expediagroup/graphql/generator/internal/extensions/kParameterExtensions.kt

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022 Expedia, Inc
2+
* Copyright 2025 Expedia, Inc
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,12 +20,11 @@ import com.expediagroup.graphql.generator.exceptions.CouldNotGetNameOfKParameter
2020
import com.expediagroup.graphql.generator.execution.GraphQLContext
2121
import graphql.schema.DataFetchingEnvironment
2222
import kotlin.reflect.KParameter
23-
import kotlin.reflect.full.isSubclassOf
2423

2524
internal fun KParameter.isInterface() = this.type.getKClass().isInterface()
2625

2726
@Deprecated("GraphQLContext parameter injection is deprecated and will be removed in next major release")
28-
internal fun KParameter.isGraphQLContext() = this.type.getKClass().isSubclassOf(GraphQLContext::class)
27+
internal fun KParameter.isGraphQLContext() = GraphQLContext::class.java.isAssignableFrom(this.type.getKClass().java)
2928

3029
internal fun KParameter.isDataFetchingEnvironment() = this.type.classifier == DataFetchingEnvironment::class
3130

generator/graphql-kotlin-schema-generator/src/main/kotlin/com/expediagroup/graphql/generator/internal/extensions/kTypeExtensions.kt

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import com.expediagroup.graphql.generator.exceptions.InvalidWrappedTypeException
2020
import com.expediagroup.graphql.generator.execution.OptionalInput
2121
import kotlin.reflect.KClass
2222
import kotlin.reflect.KType
23-
import kotlin.reflect.full.isSubclassOf
2423
import kotlin.reflect.full.withNullability
2524
import kotlin.reflect.jvm.jvmErasure
2625

generator/graphql-kotlin-schema-generator/src/test/kotlin/com/expediagroup/graphql/generator/internal/extensions/KClassExtensionsTest.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022 Expedia, Inc
2+
* Copyright 2025 Expedia, Inc
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

generator/graphql-kotlin-schema-generator/src/test/kotlin/com/expediagroup/graphql/generator/internal/extensions/KParameterExtensionsKtTest.kt

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019 Expedia, Inc
2+
* Copyright 2015 Expedia, Inc
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@ package com.expediagroup.graphql.generator.internal.extensions
1818

1919
import com.expediagroup.graphql.generator.annotations.GraphQLDescription
2020
import com.expediagroup.graphql.generator.exceptions.CouldNotGetNameOfKParameterException
21+
import com.expediagroup.graphql.generator.execution.GraphQLContext
2122
import graphql.schema.DataFetchingEnvironment
2223
import io.mockk.every
2324
import io.mockk.mockk
@@ -35,6 +36,8 @@ class KParameterExtensionsKtTest {
3536
@GraphQLDescription("class description")
3637
data class MyClass(val foo: String)
3738

39+
data class MyGraphQLContext(val foo: String) : GraphQLContext
40+
3841
interface MyInterface {
3942
val value: String
4043
}
@@ -63,6 +66,8 @@ class KParameterExtensionsKtTest {
6366
fun paramDescription(@GraphQLDescription("param description") myClass: MyClass) = myClass
6467

6568
fun dataFetchingEnvironment(environment: DataFetchingEnvironment) = environment.field.name
69+
70+
fun graphQLContext(graphQLContext: MyGraphQLContext): String = graphQLContext.foo
6671
}
6772

6873
class MyKotlinClass {
@@ -126,4 +131,10 @@ class KParameterExtensionsKtTest {
126131
val param = Container::interfaceInput.findParameterByName("myInterface")
127132
assertFalse(param?.isDataFetchingEnvironment().isTrue())
128133
}
134+
135+
@Test
136+
fun `is graphQLContext`() {
137+
val param = Container::graphQLContext.findParameterByName("graphQLContext")
138+
assertTrue(param?.isGraphQLContext().isTrue())
139+
}
129140
}

0 commit comments

Comments
 (0)