From 275e2ab8f0760beed1701ca031cf3b80b8ef307e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20=C3=85kerman?= <92524583+daniel-humla@users.noreply.github.com> Date: Thu, 7 Nov 2024 21:06:03 +0100 Subject: [PATCH] Upgrade to kotlin 2 (#2054) ### :pencil: Description - Upgrade kotlin to 2.0 - Remove unused file [FieldValueInfosExtensions.kt](https://github.com/ExpediaGroup/graphql-kotlin/compare/master...daniel-humla:graphql-kotlin-kotlin-2:upgrade-to-kotlin-2?expand=1#diff-83598ed0250eac913ae661abe96bcc47c344e342f09f8168341c7728d1c5b2ef) - Added minimal additional test [MetadataCapturingDataFetcherFactoryProviderTest.kt](https://github.com/ExpediaGroup/graphql-kotlin/compare/master...daniel-humla:graphql-kotlin-kotlin-2:upgrade-to-kotlin-2?expand=1#diff-8a648bcb4be11526cc310472dbca7a5a26ff15b7a8e5c15668d5f9e19debb18e) to maintain code coverage ### :link: Related Issues https://github.com/ExpediaGroup/graphql-kotlin/issues/2037 --- .../extensions/FieldValueInfosExtensions.kt | 31 ----------------- gradle/libs.versions.toml | 4 +-- ...dataCapturingDataFetcherFactoryProvider.kt | 1 - ...CapturingDataFetcherFactoryProviderTest.kt | 33 +++++++++++++++++++ 4 files changed, 35 insertions(+), 34 deletions(-) delete mode 100644 executions/graphql-kotlin-dataloader-instrumentation/src/main/kotlin/com/expediagroup/graphql/dataloader/instrumentation/extensions/FieldValueInfosExtensions.kt create mode 100644 plugins/server/graphql-kotlin-graalvm-metadata-generator/src/test/kotlin/MetadataCapturingDataFetcherFactoryProviderTest.kt diff --git a/executions/graphql-kotlin-dataloader-instrumentation/src/main/kotlin/com/expediagroup/graphql/dataloader/instrumentation/extensions/FieldValueInfosExtensions.kt b/executions/graphql-kotlin-dataloader-instrumentation/src/main/kotlin/com/expediagroup/graphql/dataloader/instrumentation/extensions/FieldValueInfosExtensions.kt deleted file mode 100644 index a22910c65a..0000000000 --- a/executions/graphql-kotlin-dataloader-instrumentation/src/main/kotlin/com/expediagroup/graphql/dataloader/instrumentation/extensions/FieldValueInfosExtensions.kt +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2022 Expedia, Inc - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.expediagroup.graphql.dataloader.instrumentation.extensions - -import graphql.execution.FieldValueInfo - -internal fun List.getExpectedStrategyCalls(): Int { - var count = 0 - this.forEach { fieldValueInfo -> - when (fieldValueInfo.completeValueType) { - FieldValueInfo.CompleteValueType.OBJECT -> count++ - FieldValueInfo.CompleteValueType.LIST -> count += fieldValueInfo.fieldValueInfos.getExpectedStrategyCalls() - else -> count += 0 - } - } - return count -} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 8a3837d09b..408935a199 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -7,7 +7,7 @@ graphql-java = "22.1" graalvm = "0.10.2" jackson = "2.17.1" # kotlin version has to match the compile-testing compiler version -kotlin = "1.9.24" +kotlin = "2.0.0" kotlinx-benchmark = "0.4.11" kotlinx-coroutines = "1.8.1" # TODO kotlin 1.9 upgrade: fix GraphQLTestUtils and GenerateKotlinxClientIT @@ -29,7 +29,7 @@ spring-boot = "3.2.7" commons-codec = { strictly = "[1.13, 2[", prefer = "1.16.0" } # test dependencies -compile-testing = "0.5.0" +compile-testing = "0.5.1" icu = "75.1" junit = "5.10.2" logback = "1.5.6" diff --git a/plugins/server/graphql-kotlin-graalvm-metadata-generator/src/main/kotlin/com/expediagroup/graphql/plugin/graalvm/MetadataCapturingDataFetcherFactoryProvider.kt b/plugins/server/graphql-kotlin-graalvm-metadata-generator/src/main/kotlin/com/expediagroup/graphql/plugin/graalvm/MetadataCapturingDataFetcherFactoryProvider.kt index fb0e8de346..c53cb94f22 100644 --- a/plugins/server/graphql-kotlin-graalvm-metadata-generator/src/main/kotlin/com/expediagroup/graphql/plugin/graalvm/MetadataCapturingDataFetcherFactoryProvider.kt +++ b/plugins/server/graphql-kotlin-graalvm-metadata-generator/src/main/kotlin/com/expediagroup/graphql/plugin/graalvm/MetadataCapturingDataFetcherFactoryProvider.kt @@ -32,7 +32,6 @@ internal class MetadataCapturingDataFetcherFactoryProvider(val scanResult: ScanR // we need to capture enums private val additionalTypes: MutableSet = HashSet() - @OptIn(ExperimentalStdlibApi::class) override fun functionDataFetcherFactory(target: Any?, kClass: KClass<*>, kFunction: KFunction<*>): DataFetcherFactory { val methodName = kFunction.javaMethod!!.name val classMetadata = reflectMetadataMap.getOrPut(kClass.java.name) { MutableClassMetadata(name = kClass.java.name, methods = ArrayList()) } diff --git a/plugins/server/graphql-kotlin-graalvm-metadata-generator/src/test/kotlin/MetadataCapturingDataFetcherFactoryProviderTest.kt b/plugins/server/graphql-kotlin-graalvm-metadata-generator/src/test/kotlin/MetadataCapturingDataFetcherFactoryProviderTest.kt new file mode 100644 index 0000000000..38b6f64267 --- /dev/null +++ b/plugins/server/graphql-kotlin-graalvm-metadata-generator/src/test/kotlin/MetadataCapturingDataFetcherFactoryProviderTest.kt @@ -0,0 +1,33 @@ +import com.expediagroup.graphql.plugin.graalvm.MetadataCapturingDataFetcherFactoryProvider +import com.expediagroup.graphql.plugin.graalvm.enums.EnumQuery +import io.github.classgraph.ClassGraph +import io.github.classgraph.ScanResult +import org.junit.jupiter.api.Assertions +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test +import kotlin.reflect.KFunction + +class MetadataCapturingDataFetcherFactoryProviderTest { + + private lateinit var scanResult: ScanResult + private lateinit var provider: MetadataCapturingDataFetcherFactoryProvider + + @BeforeEach + fun setup() { + scanResult = ClassGraph().enableAllInfo().acceptPackages("com.expediagroup.graphql.plugin.graalvm").scan() + provider = MetadataCapturingDataFetcherFactoryProvider(scanResult, listOf("com.expediagroup.graphql.plugin.graalvm")) + + val kClass = EnumQuery::class + val kFunction = kClass.members.find { it.name == "enumArgQuery" } as KFunction<*> + provider.functionDataFetcherFactory(null, kClass, kFunction) + } + + @Test + fun `reflectMetadata should not be empty`() { + val metadata = provider.reflectMetadata() + + Assertions.assertNotNull(metadata) + Assertions.assertTrue(metadata.isNotEmpty(), "Reflect metadata should not be empty") + Assertions.assertEquals(listOf("com.expediagroup.graphql.plugin.graalvm"), provider.supportedPackages) + } +}