Skip to content

Commit 436a84c

Browse files
smyrickShane Myrick
authored andcommitted
Update to kotlin 1.4 (ExpediaGroup#844)
* Update to kotlin 1.4 * Update tests for coverage * Update to corountines 1.3.9 * Update GraphQLGradlePluginAbstractIT.kt Co-authored-by: Shane Myrick <[email protected]>
1 parent 1606787 commit 436a84c

File tree

11 files changed

+133
-30
lines changed

11 files changed

+133
-30
lines changed

examples/client/gradle-client/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import com.expediagroup.graphql.plugin.gradle.graphql
33

44
plugins {
55
application
6-
id("org.jetbrains.kotlin.jvm") version "1.3.72"
6+
id("org.jetbrains.kotlin.jvm") version "1.4.0"
77
id("com.expediagroup.graphql") version "3.1.0"
88
}
99

examples/client/maven-client/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
<!-- those properties are set by gradle -->
1111
<graphql-kotlin.version>3.1.0</graphql-kotlin.version>
1212
<!-- lib versions -->
13-
<kotlin.version>1.3.72</kotlin.version>
14-
<kotlin-coroutines.version>1.3.6</kotlin-coroutines.version>
13+
<kotlin.version>1.4.0</kotlin.version>
14+
<kotlin-coroutines.version>1.3.9</kotlin-coroutines.version>
1515
<ktor.version>1.3.1</ktor.version>
1616
</properties>
1717

examples/client/server/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
plugins {
2-
id("org.jetbrains.kotlin.jvm") version "1.3.72"
3-
id("org.jetbrains.kotlin.plugin.spring") version "1.3.72"
2+
id("org.jetbrains.kotlin.jvm") version "1.4.0"
3+
id("org.jetbrains.kotlin.plugin.spring") version "1.4.0"
44
id("org.springframework.boot") version "2.2.7.RELEASE"
55
}
66

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ org.gradle.jvmargs=-Xmx2g -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError
1515

1616
# dependencies
1717
kotlinJvmVersion = 1.8
18-
kotlinVersion = 1.3.72
19-
kotlinCoroutinesVersion = 1.3.7
18+
kotlinVersion = 1.4.0
19+
kotlinCoroutinesVersion = 1.3.9
2020

2121
classGraphVersion = 4.8.87
2222
graphQLJavaVersion = 15.0

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import kotlin.reflect.KClass
2121
import kotlin.reflect.KType
2222
import kotlin.reflect.full.createType
2323
import kotlin.reflect.full.isSubclassOf
24-
import kotlin.reflect.jvm.javaType
2524
import kotlin.reflect.jvm.jvmErasure
2625

2726
private val primitiveArrayTypes = mapOf(
@@ -36,7 +35,7 @@ private val primitiveArrayTypes = mapOf(
3635

3736
internal fun KType.getKClass() = this.jvmErasure
3837

39-
internal fun KType.getJavaClass() = this.javaType as Class<*>
38+
internal fun KType.getJavaClass(): Class<*> = this.getKClass().java
4039

4140
internal fun KType.isSubclassOf(kClass: KClass<*>) = this.getKClass().isSubclassOf(kClass)
4241

graphql-kotlin-schema-generator/src/test/kotlin/com/expediagroup/graphql/directives/KotlinDirectiveWiringFactoryTest.kt

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ class KotlinDirectiveWiringFactoryTest {
211211
}
212212

213213
@Test
214-
fun `verify exception is thrown if no coordinates or code registry is specified for the field`() {
214+
fun `verify exception is thrown if no coordinates are specified for the field`() {
215215
val myTestField = GraphQLFieldDefinition.newFieldDefinition()
216216
.name("MyField")
217217
.type { context, visitor -> context.thisNode().accept(context, visitor) }
@@ -220,7 +220,21 @@ class KotlinDirectiveWiringFactoryTest {
220220
.build()
221221

222222
assertFailsWith(InvalidSchemaDirectiveWiringException::class) {
223-
SimpleWiringFactory().onWire(graphQLSchemaElement = myTestField, coordinates = null, codeRegistry = null)
223+
SimpleWiringFactory().onWire(graphQLSchemaElement = myTestField, coordinates = null, codeRegistry = mockk())
224+
}
225+
}
226+
227+
@Test
228+
fun `verify exception is thrown if no code registry is specified for the field`() {
229+
val myTestField = GraphQLFieldDefinition.newFieldDefinition()
230+
.name("MyField")
231+
.type { context, visitor -> context.thisNode().accept(context, visitor) }
232+
.description("My Field Description")
233+
.withDirective(graphQLLowercaseDirective)
234+
.build()
235+
236+
assertFailsWith(InvalidSchemaDirectiveWiringException::class) {
237+
SimpleWiringFactory().onWire(graphQLSchemaElement = myTestField, coordinates = mockk(), codeRegistry = null)
224238
}
225239
}
226240

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

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,18 @@ import org.junit.jupiter.api.condition.EnabledOnJre
2525
import org.junit.jupiter.api.condition.JRE
2626
import kotlin.reflect.KType
2727
import kotlin.reflect.KTypeProjection
28+
import kotlin.reflect.full.createType
2829
import kotlin.reflect.full.findParameterByName
2930
import kotlin.reflect.full.starProjectedType
3031
import kotlin.test.assertEquals
3132
import kotlin.test.assertFailsWith
3233
import kotlin.test.assertFalse
34+
import kotlin.test.assertNotNull
3335
import kotlin.test.assertTrue
3436

35-
internal class KTypeExtensionsKtTest {
37+
class KTypeExtensionsKtTest {
3638

37-
internal class MyClass {
39+
class MyClass {
3840
fun listFun(list: List<String>) = list.joinToString(separator = ",") { it }
3941

4042
fun arrayFun(array: Array<String>) = array.joinToString(separator = ",") { it }
@@ -44,9 +46,9 @@ internal class KTypeExtensionsKtTest {
4446
fun stringFun(string: String) = "hello $string"
4547
}
4648

47-
internal interface SimpleInterface
49+
interface SimpleInterface
4850

49-
internal class SimpleClass(val id: String) : SimpleInterface
51+
class SimpleClass(val id: String) : SimpleInterface
5052

5153
@Test
5254
fun getTypeOfFirstArgument() {
@@ -77,7 +79,22 @@ internal class KTypeExtensionsKtTest {
7779

7880
@Test
7981
fun getKClass() {
80-
assertEquals(MyClass::class, MyClass::class.starProjectedType.getKClass())
82+
assertEquals(MyClass::class, MyClass::class.createType().getKClass())
83+
}
84+
85+
@Test
86+
fun getJavaClass() {
87+
val listType = assertNotNull(MyClass::listFun.findParameterByName("list")?.type)
88+
assertEquals(List::class.java, listType.getJavaClass())
89+
90+
val arrayType = assertNotNull(MyClass::arrayFun.findParameterByName("array")?.type)
91+
assertEquals(Array<String>::class.java, arrayType.getJavaClass())
92+
93+
val primitiveArrayType = assertNotNull(MyClass::primitiveArrayFun.findParameterByName("intArray")?.type)
94+
assertEquals(IntArray::class.java, primitiveArrayType.getJavaClass())
95+
96+
val stringType = assertNotNull(MyClass::stringFun.findParameterByName("string")?.type)
97+
assertEquals(String::class.java, stringType.getJavaClass())
8198
}
8299

83100
@Test

graphql-kotlin-schema-generator/src/test/kotlin/com/expediagroup/graphql/generator/types/GenerateDirectiveTest.kt

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import com.expediagroup.graphql.test.utils.SimpleDirective
2626
import org.junit.jupiter.api.AfterAll
2727
import org.junit.jupiter.api.Test
2828
import kotlin.reflect.KClass
29+
import kotlin.reflect.KFunction
2930
import kotlin.test.assertEquals
3031
import kotlin.test.assertTrue
3132

@@ -92,40 +93,47 @@ class GenerateDirectiveTest {
9293

9394
@Test
9495
fun `no annotation`() {
95-
assertTrue(generateDirectives(basicGenerator, MyClass::noAnnotation).isEmpty().isTrue())
96+
val noAnnotation: KFunction<String> = MyClass::noAnnotation
97+
assertTrue(generateDirectives(basicGenerator, noAnnotation).isEmpty().isTrue())
9698
}
9799

98100
@Test
99101
fun `no directive`() {
100-
assertTrue(generateDirectives(basicGenerator, MyClass::noDirective).isEmpty().isTrue())
102+
val noDirective: KFunction<String> = MyClass::noDirective
103+
assertTrue(generateDirectives(basicGenerator, noDirective).isEmpty().isTrue())
101104
}
102105

103106
@Test
104107
fun `has directive`() {
105-
assertEquals(expected = 1, actual = generateDirectives(basicGenerator, MyClass::simpleDirective).size)
108+
val simpleDirective: KFunction<String> = MyClass::simpleDirective
109+
assertEquals(expected = 1, actual = generateDirectives(basicGenerator, simpleDirective).size)
106110
}
107111

108112
@Test
109113
fun `has directive with string`() {
110-
assertEquals(expected = 1, actual = generateDirectives(basicGenerator, MyClass::directiveWithString).size)
114+
val directiveWithString: KFunction<String> = MyClass::directiveWithString
115+
assertEquals(expected = 1, actual = generateDirectives(basicGenerator, directiveWithString).size)
111116
}
112117

113118
@Test
114119
fun `has directive with enum`() {
115-
assertEquals(expected = 1, actual = generateDirectives(basicGenerator, MyClass::directiveWithEnum).size)
120+
val directiveWithEnum: KFunction<String> = MyClass::directiveWithEnum
121+
assertEquals(expected = 1, actual = generateDirectives(basicGenerator, directiveWithEnum).size)
116122
}
117123

118124
@Test
119125
fun `has directive with class`() {
120-
assertEquals(expected = 1, actual = generateDirectives(basicGenerator, MyClass::directiveWithClass).size)
126+
val directiveWithClass: KFunction<String> = MyClass::directiveWithClass
127+
assertEquals(expected = 1, actual = generateDirectives(basicGenerator, directiveWithClass).size)
121128
}
122129

123130
@Test
124131
fun `directives are only added to the schema once`() {
125132
val initialCount = basicGenerator.directives.size
126-
val firstInvocation = generateDirectives(basicGenerator, MyClass::simpleDirective)
133+
val simpleDirective: KFunction<String> = MyClass::simpleDirective
134+
val firstInvocation = generateDirectives(basicGenerator, simpleDirective)
127135
assertEquals(1, firstInvocation.size)
128-
val secondInvocation = generateDirectives(basicGenerator, MyClass::simpleDirective)
136+
val secondInvocation = generateDirectives(basicGenerator, simpleDirective)
129137
assertEquals(1, secondInvocation.size)
130138
assertEquals(firstInvocation.first(), secondInvocation.first())
131139
assertEquals(initialCount + 1, basicGenerator.directives.size)
@@ -154,8 +162,10 @@ class GenerateDirectiveTest {
154162
@Test
155163
fun `directives are created per each declaration`() {
156164
val initialCount = basicGenerator.directives.size
157-
val directivesOnFirstField = generateDirectives(basicGenerator, MyClass::directiveWithString)
158-
val directivesOnSecondField = generateDirectives(basicGenerator, MyClass::directiveWithAnotherString)
165+
val directiveWithString: KFunction<String> = MyClass::directiveWithString
166+
val directiveWithAnotherString: KFunction<String> = MyClass::directiveWithAnotherString
167+
val directivesOnFirstField = generateDirectives(basicGenerator, directiveWithString)
168+
val directivesOnSecondField = generateDirectives(basicGenerator, directiveWithAnotherString)
159169
assertEquals(expected = 1, actual = directivesOnFirstField.size)
160170
assertEquals(expected = 1, actual = directivesOnSecondField.size)
161171

@@ -191,7 +201,8 @@ class GenerateDirectiveTest {
191201

192202
@Test
193203
fun `exlude directive arguments @GraphQLIgnore`() {
194-
val directives = generateDirectives(basicGenerator, MyClass::directiveWithIgnoredArgs)
204+
val directiveWithIgnoredArgs: KFunction<String> = MyClass::directiveWithIgnoredArgs
205+
val directives = generateDirectives(basicGenerator, directiveWithIgnoredArgs)
195206
assertEquals(expected = 1, actual = directives.size)
196207
assertEquals(expected = 1, actual = directives.first().arguments.size)
197208
assertEquals(expected = "string", actual = directives.first().arguments.first().name)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright 2020 Expedia, Inc
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.expediagroup.graphql.hooks
18+
19+
import kotlinx.coroutines.flow.Flow
20+
import kotlinx.coroutines.flow.emptyFlow
21+
import org.junit.jupiter.api.Test
22+
import java.util.concurrent.CompletableFuture
23+
import kotlin.reflect.full.createType
24+
import kotlin.reflect.jvm.reflect
25+
import kotlin.test.assertEquals
26+
import kotlin.test.assertFalse
27+
import kotlin.test.assertNotNull
28+
import kotlin.test.assertTrue
29+
30+
class FlowSubscriptionSchemaGeneratorHooksTest {
31+
32+
val hooks = FlowSubscriptionSchemaGeneratorHooks()
33+
34+
@Test
35+
fun `willResolveMonad unwraps Flow`() {
36+
val type = assertNotNull(TestQuery::getFlow.reflect()?.returnType)
37+
val result = hooks.willResolveMonad(type)
38+
assertEquals(String::class.createType(), result)
39+
}
40+
41+
@Test
42+
fun `willResolveMonad does nothing on any other type`() {
43+
val stringType = assertNotNull(TestQuery::getString.reflect()?.returnType)
44+
val cfType = assertNotNull(TestQuery::getCompletableFuture.reflect()?.returnType)
45+
46+
assertEquals(stringType, hooks.willResolveMonad(stringType))
47+
assertEquals(cfType, hooks.willResolveMonad(cfType))
48+
}
49+
50+
@Test
51+
fun isValidSubscriptionReturnType() {
52+
assertTrue(hooks.isValidSubscriptionReturnType(TestQuery::class, TestQuery::getFlow))
53+
assertFalse(hooks.isValidSubscriptionReturnType(TestQuery::class, TestQuery::getString))
54+
assertFalse(hooks.isValidSubscriptionReturnType(TestQuery::class, TestQuery::getCompletableFuture))
55+
}
56+
57+
class TestQuery {
58+
fun getFlow(): Flow<String> = emptyFlow()
59+
fun getString(): String = ""
60+
fun getCompletableFuture(): CompletableFuture<String> = CompletableFuture.completedFuture("")
61+
}
62+
}

graphql-kotlin-schema-generator/src/test/kotlin/com/expediagroup/graphql/hooks/SchemaGeneratorHooksTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ class SchemaGeneratorHooksTest {
302302
@Test
303303
fun `willResolveMonad returns basic type`() {
304304
val hooks = NoopSchemaGeneratorHooks
305-
val type = TestQuery::query.returnType
305+
val type = (TestQuery::query as KFunction<*>).returnType
306306

307307
assertEquals(expected = "SomeData", actual = hooks.willResolveMonad(type).getSimpleName())
308308
}

plugins/graphql-kotlin-gradle-plugin/src/test/kotlin/com/expediagroup/graphql/plugin/gradle/GraphQLGradlePluginAbstractIT.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ abstract class GraphQLGradlePluginAbstractIT {
3434

3535
// unsure if there is a better way - correct values are set from Gradle build
3636
// when running directly from IDE you will need to manually update those to correct values
37-
private val gqlKotlinVersion = System.getProperty("graphQLKotlinVersion") ?: "3.0.0-SNAPSHOT"
38-
private val kotlinVersion = System.getProperty("kotlinVersion") ?: "1.3.72"
37+
private val gqlKotlinVersion = System.getProperty("graphQLKotlinVersion") ?: "4.0.0-SNAPSHOT"
38+
private val kotlinVersion = System.getProperty("kotlinVersion") ?: "1.4.0"
3939
private val junitVersion = System.getProperty("junitVersion") ?: "5.6.2"
4040

4141
val testSchema = loadResource("mocks/schema.graphql")

0 commit comments

Comments
 (0)