From 6f3f075f51383653b141490782f01ba789be746b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20=C3=85kerman?= Date: Mon, 4 Nov 2024 11:13:22 +0100 Subject: [PATCH 1/3] Upgrade to kotlin 2.0 --- gradle/libs.versions.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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" From e6f4cc8a382735026a1a30673f887750178e6301 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20=C3=85kerman?= Date: Mon, 4 Nov 2024 11:38:09 +0100 Subject: [PATCH 2/3] Delete unused extension function (increase coverage) --- .../extensions/FieldValueInfosExtensions.kt | 31 ------------------- 1 file changed, 31 deletions(-) delete mode 100644 executions/graphql-kotlin-dataloader-instrumentation/src/main/kotlin/com/expediagroup/graphql/dataloader/instrumentation/extensions/FieldValueInfosExtensions.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 -} From 86169d80595dfff11228f08096c01aed00958fd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20=C3=85kerman?= Date: Mon, 4 Nov 2024 15:42:31 +0100 Subject: [PATCH 3/3] Add some more tests to increase coverage --- ...dataCapturingDataFetcherFactoryProvider.kt | 1 - ...CapturingDataFetcherFactoryProviderTest.kt | 33 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 plugins/server/graphql-kotlin-graalvm-metadata-generator/src/test/kotlin/MetadataCapturingDataFetcherFactoryProviderTest.kt 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) + } +}