Skip to content

Commit a7364b3

Browse files
authored
chore: add compilation test for expected kotlin in unit tests (#31)
1 parent efe99f9 commit a7364b3

File tree

43 files changed

+142
-118
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+142
-118
lines changed

build.gradle.kts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ dependencies {
1212
}
1313

1414
sourceSets {
15-
main {
15+
test {
1616
kotlin {
17-
srcDirs("test/integration")
17+
srcDirs("test/unit", "test/integration")
18+
exclude("**/actual.kt")
1819
}
1920
}
2021
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"build": "tsup src/plugin.ts --clean --dts --external graphql",
4040
"format": "prettier --write .",
4141
"format-check": "prettier --check .",
42-
"integration": "bun run build && graphql-codegen && ./gradlew compileKotlin",
42+
"integration": "bun run build && graphql-codegen && ./gradlew compileTestKotlin",
4343
"lint": "eslint .",
4444
"prepack": "bun run build",
4545
"prepare": "husky",

test/unit/should_annotate_types_properly/expected.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package com.kotlin.generated
33
import com.expediagroup.graphql.generator.annotations.*
44

55
@GraphQLDescription("A description for MyType")
6-
data class MyType(
6+
data class TypeThatShouldBeProperlyAnnotated(
77
val username: String? = null,
88
@GraphQLDescription("A description for email")
99
val email: String? = null,
@@ -17,20 +17,20 @@ data class MyType(
1717
val deprecated3: String? = null,
1818
@Deprecated("It only takes the first one")
1919
val deprecated4: String? = null,
20-
@MyUnion
20+
@UnionThatShouldBeProperlyAnnotated
2121
@GraphQLDescription("DEPRECATED: It uses the GraphQLDescription annotation for union types")
2222
val deprecated5: Any? = null,
23-
@MyUnion
23+
@UnionThatShouldBeProperlyAnnotated
2424
@GraphQLDescription("It uses the GraphQLDescription annotation for union types")
2525
val deprecated6: Any? = null,
26-
@MyUnion
26+
@UnionThatShouldBeProperlyAnnotated
2727
@GraphQLDescription("When there is a description")
2828
val deprecated7: Any? = null
2929
)
3030

3131
@GraphQLUnion(
32-
name = "MyUnion",
33-
possibleTypes = [MyType::class],
32+
name = "UnionThatShouldBeProperlyAnnotated",
33+
possibleTypes = [TypeThatShouldBeProperlyAnnotated::class],
3434
description = ""
3535
)
36-
annotation class MyUnion
36+
annotation class UnionThatShouldBeProperlyAnnotated

test/unit/should_annotate_types_properly/schema.graphql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
A "description" for MyType
44
It can be multiline
55
"""
6-
type MyType {
6+
type TypeThatShouldBeProperlyAnnotated {
77
username: String
88
"A description for email"
99
email: String
@@ -19,14 +19,14 @@ type MyType {
1919
deprecated4: String
2020
@deprecated(reason: "when you have multiple deprecated annotations")
2121
"DEPRECATED: It uses the GraphQLDescription annotation for union types"
22-
deprecated5: MyUnion
23-
deprecated6: MyUnion
22+
deprecated5: UnionThatShouldBeProperlyAnnotated
23+
deprecated6: UnionThatShouldBeProperlyAnnotated
2424
@deprecated(
2525
reason: "It uses the GraphQLDescription annotation for union types"
2626
)
2727
"When there is a description"
28-
deprecated7: MyUnion
28+
deprecated7: UnionThatShouldBeProperlyAnnotated
2929
@deprecated(reason: "It omits the @Deprecated annotation for now")
3030
}
3131

32-
union MyUnion = MyType
32+
union UnionThatShouldBeProperlyAnnotated = TypeThatShouldBeProperlyAnnotated

test/unit/should_generate_enums_properly/expected.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ package com.kotlin.generated
33
import com.expediagroup.graphql.generator.annotations.*
44

55
@GraphQLDescription("A description for MyEnum")
6-
enum class MyEnum {
6+
enum class EnumThatShouldBeProperlyAnnotated {
77
This,
88
@GraphQLDescription("A description for THAT")
99
That;
1010

1111
companion object {
12-
fun findByName(name: String, ignoreCase: Boolean = false): MyEnum? = values().find { it.name.equals(name, ignoreCase = ignoreCase) }
12+
fun findByName(name: String, ignoreCase: Boolean = false): EnumThatShouldBeProperlyAnnotated? = values().find { it.name.equals(name, ignoreCase = ignoreCase) }
1313
}
1414
}

test/unit/should_generate_enums_properly/schema.graphql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"A description for MyEnum"
2-
enum MyEnum {
2+
enum EnumThatShouldBeProperlyAnnotated {
33
THIS
44
"A description for THAT"
55
THAT

test/unit/should_generate_field_resolver_interfaces/expected.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@ interface Query {
77
suspend fun nullableField(): FieldType? = null
88
suspend fun nonNullableField(): FieldType
99
suspend fun nullableResolver(arg: String): String? = null
10-
suspend fun nonNullableResolver(arg: MyInputType): String
10+
suspend fun nonNullableResolver(arg: InputTypeGenerateFieldResolverInterfaces): String
1111
}
1212

1313
@GraphQLIgnore
1414
interface QueryCompletableFuture {
1515
fun nullableField(): java.util.concurrent.CompletableFuture<FieldType?>
1616
fun nonNullableField(): java.util.concurrent.CompletableFuture<FieldType>
1717
fun nullableResolver(arg: String): java.util.concurrent.CompletableFuture<String?>
18-
fun nonNullableResolver(arg: MyInputType): java.util.concurrent.CompletableFuture<String>
18+
fun nonNullableResolver(arg: InputTypeGenerateFieldResolverInterfaces): java.util.concurrent.CompletableFuture<String>
1919
}
2020

21-
data class MyInputType(
21+
data class InputTypeGenerateFieldResolverInterfaces(
2222
val field: String? = null
2323
)
2424

test/unit/should_generate_field_resolver_interfaces/schema.graphql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ type Query {
22
nullableField: FieldType
33
nonNullableField: FieldType!
44
nullableResolver(arg: String!): String
5-
nonNullableResolver(arg: MyInputType!): String!
5+
nonNullableResolver(arg: InputTypeGenerateFieldResolverInterfaces!): String!
66
}
77

8-
input MyInputType {
8+
input InputTypeGenerateFieldResolverInterfaces {
99
field: String
1010
}
1111

test/unit/should_generate_input_types_properly/expected.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package com.kotlin.generated
33
import com.expediagroup.graphql.generator.annotations.*
44

55
@GraphQLDescription("A description for MyInputType")
6-
data class MyInputType(
6+
data class InputTypeThatShouldBeGeneratedProperly(
77
val username: String? = null,
88
@GraphQLDescription("A description for email")
99
val email: String? = null,

test/unit/should_generate_input_types_properly/schema.graphql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"A description for MyInputType"
2-
input MyInputType {
2+
input InputTypeThatShouldBeGeneratedProperly {
33
username: String
44
"A description for email"
55
email: String

0 commit comments

Comments
 (0)