Skip to content

Commit

Permalink
chore: add compilation test for expected kotlin in unit tests (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
danadajian authored Apr 9, 2024
1 parent efe99f9 commit a7364b3
Show file tree
Hide file tree
Showing 43 changed files with 142 additions and 118 deletions.
5 changes: 3 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ dependencies {
}

sourceSets {
main {
test {
kotlin {
srcDirs("test/integration")
srcDirs("test/unit", "test/integration")
exclude("**/actual.kt")
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"build": "tsup src/plugin.ts --clean --dts --external graphql",
"format": "prettier --write .",
"format-check": "prettier --check .",
"integration": "bun run build && graphql-codegen && ./gradlew compileKotlin",
"integration": "bun run build && graphql-codegen && ./gradlew compileTestKotlin",
"lint": "eslint .",
"prepack": "bun run build",
"prepare": "husky",
Expand Down
14 changes: 7 additions & 7 deletions test/unit/should_annotate_types_properly/expected.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.kotlin.generated
import com.expediagroup.graphql.generator.annotations.*

@GraphQLDescription("A description for MyType")
data class MyType(
data class TypeThatShouldBeProperlyAnnotated(
val username: String? = null,
@GraphQLDescription("A description for email")
val email: String? = null,
Expand All @@ -17,20 +17,20 @@ data class MyType(
val deprecated3: String? = null,
@Deprecated("It only takes the first one")
val deprecated4: String? = null,
@MyUnion
@UnionThatShouldBeProperlyAnnotated
@GraphQLDescription("DEPRECATED: It uses the GraphQLDescription annotation for union types")
val deprecated5: Any? = null,
@MyUnion
@UnionThatShouldBeProperlyAnnotated
@GraphQLDescription("It uses the GraphQLDescription annotation for union types")
val deprecated6: Any? = null,
@MyUnion
@UnionThatShouldBeProperlyAnnotated
@GraphQLDescription("When there is a description")
val deprecated7: Any? = null
)

@GraphQLUnion(
name = "MyUnion",
possibleTypes = [MyType::class],
name = "UnionThatShouldBeProperlyAnnotated",
possibleTypes = [TypeThatShouldBeProperlyAnnotated::class],
description = ""
)
annotation class MyUnion
annotation class UnionThatShouldBeProperlyAnnotated
10 changes: 5 additions & 5 deletions test/unit/should_annotate_types_properly/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
A "description" for MyType
It can be multiline
"""
type MyType {
type TypeThatShouldBeProperlyAnnotated {
username: String
"A description for email"
email: String
Expand All @@ -19,14 +19,14 @@ type MyType {
deprecated4: String
@deprecated(reason: "when you have multiple deprecated annotations")
"DEPRECATED: It uses the GraphQLDescription annotation for union types"
deprecated5: MyUnion
deprecated6: MyUnion
deprecated5: UnionThatShouldBeProperlyAnnotated
deprecated6: UnionThatShouldBeProperlyAnnotated
@deprecated(
reason: "It uses the GraphQLDescription annotation for union types"
)
"When there is a description"
deprecated7: MyUnion
deprecated7: UnionThatShouldBeProperlyAnnotated
@deprecated(reason: "It omits the @Deprecated annotation for now")
}

union MyUnion = MyType
union UnionThatShouldBeProperlyAnnotated = TypeThatShouldBeProperlyAnnotated
4 changes: 2 additions & 2 deletions test/unit/should_generate_enums_properly/expected.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package com.kotlin.generated
import com.expediagroup.graphql.generator.annotations.*

@GraphQLDescription("A description for MyEnum")
enum class MyEnum {
enum class EnumThatShouldBeProperlyAnnotated {
This,
@GraphQLDescription("A description for THAT")
That;

companion object {
fun findByName(name: String, ignoreCase: Boolean = false): MyEnum? = values().find { it.name.equals(name, ignoreCase = ignoreCase) }
fun findByName(name: String, ignoreCase: Boolean = false): EnumThatShouldBeProperlyAnnotated? = values().find { it.name.equals(name, ignoreCase = ignoreCase) }
}
}
2 changes: 1 addition & 1 deletion test/unit/should_generate_enums_properly/schema.graphql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"A description for MyEnum"
enum MyEnum {
enum EnumThatShouldBeProperlyAnnotated {
THIS
"A description for THAT"
THAT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ interface Query {
suspend fun nullableField(): FieldType? = null
suspend fun nonNullableField(): FieldType
suspend fun nullableResolver(arg: String): String? = null
suspend fun nonNullableResolver(arg: MyInputType): String
suspend fun nonNullableResolver(arg: InputTypeGenerateFieldResolverInterfaces): String
}

@GraphQLIgnore
interface QueryCompletableFuture {
fun nullableField(): java.util.concurrent.CompletableFuture<FieldType?>
fun nonNullableField(): java.util.concurrent.CompletableFuture<FieldType>
fun nullableResolver(arg: String): java.util.concurrent.CompletableFuture<String?>
fun nonNullableResolver(arg: MyInputType): java.util.concurrent.CompletableFuture<String>
fun nonNullableResolver(arg: InputTypeGenerateFieldResolverInterfaces): java.util.concurrent.CompletableFuture<String>
}

data class MyInputType(
data class InputTypeGenerateFieldResolverInterfaces(
val field: String? = null
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ type Query {
nullableField: FieldType
nonNullableField: FieldType!
nullableResolver(arg: String!): String
nonNullableResolver(arg: MyInputType!): String!
nonNullableResolver(arg: InputTypeGenerateFieldResolverInterfaces!): String!
}

input MyInputType {
input InputTypeGenerateFieldResolverInterfaces {
field: String
}

Expand Down
2 changes: 1 addition & 1 deletion test/unit/should_generate_input_types_properly/expected.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.kotlin.generated
import com.expediagroup.graphql.generator.annotations.*

@GraphQLDescription("A description for MyInputType")
data class MyInputType(
data class InputTypeThatShouldBeGeneratedProperly(
val username: String? = null,
@GraphQLDescription("A description for email")
val email: String? = null,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"A description for MyInputType"
input MyInputType {
input InputTypeThatShouldBeGeneratedProperly {
username: String
"A description for email"
email: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package com.kotlin.generated

import com.expediagroup.graphql.generator.annotations.*

@GraphQLDescription("A description for MyInterface")
interface MyInterface {
@GraphQLDescription("A description for InterfaceWithInheritance")
interface InterfaceWithInheritance {
val field: String?
val field2: String
}
Expand All @@ -12,17 +12,17 @@ interface MyInterface {
data class MyInterfaceImplementation(
override val field: String? = null,
override val field2: String
) : MyInterface
) : InterfaceWithInheritance

interface MyInterface1 {
interface InheritedInterface1 {
val field: String?
}

interface MyInterface2 {
interface InheritedInterface2 {
val field2: String
}

data class MyMergedInterfaceImplementation(
override val field: String? = null,
override val field2: String
) : MyInterface1, MyInterface2
) : InheritedInterface1, InheritedInterface2
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
"A description for MyInterface"
interface MyInterface {
"A description for InterfaceWithInheritance"
interface InterfaceWithInheritance {
field: String
field2: String!
}

"A description for MyInterfaceImplementation"
type MyInterfaceImplementation implements MyInterface {
type MyInterfaceImplementation implements InterfaceWithInheritance {
field: String
field2: String!
}

interface MyInterface1 {
interface InheritedInterface1 {
field: String
}

interface MyInterface2 {
interface InheritedInterface2 {
field2: String!
}

type MyMergedInterfaceImplementation implements MyInterface1 & MyInterface2 {
type MyMergedInterfaceImplementation implements InheritedInterface1 & InheritedInterface2 {
field: String
field2: String!
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@ package com.kotlin.generated
import com.expediagroup.graphql.generator.annotations.*

@GraphQLDescription("A description for MyType1")
data class MyType1(
data class TypeForNonNullableUnionList1(
val field: String? = null
)

data class MyType2(
data class TypeForNonNullableUnionList2(
val field: String? = null
)

@GraphQLUnion(
name = "MyUnion",
possibleTypes = [MyType1::class, MyType2::class],
description = "A description for MyUnion"
name = "UnionForNonNullableList",
possibleTypes = [TypeForNonNullableUnionList1::class, TypeForNonNullableUnionList2::class],
description = "A description for UnionForNonNullableList"
)
annotation class MyUnion
annotation class UnionForNonNullableList

data class MyNonNullableUnionListType(
@MyUnion
@UnionForNonNullableList
val field: List<Any> = emptyList(),
@MyUnion
@UnionForNonNullableList
val field2: List<Any?> = emptyList()
)
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
"A description for MyType1"
type MyType1 {
type TypeForNonNullableUnionList1 {
field: String
}

type MyType2 {
type TypeForNonNullableUnionList2 {
field: String
}

"A description for MyUnion"
union MyUnion = MyType1 | MyType2
"A description for UnionForNonNullableList"
union UnionForNonNullableList =
| TypeForNonNullableUnionList1
| TypeForNonNullableUnionList2

type MyNonNullableUnionListType {
field: [MyUnion!]!
field2: [MyUnion]!
field: [UnionForNonNullableList!]!
field2: [UnionForNonNullableList]!
}
18 changes: 9 additions & 9 deletions test/unit/should_generate_union_list_types_properly/expected.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@ package com.kotlin.generated

import com.expediagroup.graphql.generator.annotations.*

@GraphQLDescription("A description for MyType1")
data class MyType1(
@GraphQLDescription("A description for TypeForGeneratingUnionListTypes1")
data class TypeForGeneratingUnionListTypes1(
val field: String? = null
)

data class MyType2(
data class TypeForGeneratingUnionListTypes2(
val field: String? = null
)

@GraphQLUnion(
name = "MyUnion",
possibleTypes = [MyType1::class, MyType2::class],
description = "A description for MyUnion"
name = "UnionForGeneratingUnionListTypes",
possibleTypes = [TypeForGeneratingUnionListTypes1::class, TypeForGeneratingUnionListTypes2::class],
description = "A description for UnionForGeneratingUnionListTypes"
)
annotation class MyUnion
annotation class UnionForGeneratingUnionListTypes

data class MyUnionListType(
@MyUnion
@UnionForGeneratingUnionListTypes
@GraphQLDescription("A description for field")
val field: List<Any>? = null,
@MyUnion
@UnionForGeneratingUnionListTypes
val field2: List<Any?>? = null
)
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
"A description for MyType1"
type MyType1 {
"A description for TypeForGeneratingUnionListTypes1"
type TypeForGeneratingUnionListTypes1 {
field: String
}

type MyType2 {
type TypeForGeneratingUnionListTypes2 {
field: String
}

"A description for MyUnion"
union MyUnion = MyType1 | MyType2
"A description for UnionForGeneratingUnionListTypes"
union UnionForGeneratingUnionListTypes =
| TypeForGeneratingUnionListTypes1
| TypeForGeneratingUnionListTypes2

type MyUnionListType {
"A description for field"
field: [MyUnion!]
field2: [MyUnion]
field: [UnionForGeneratingUnionListTypes!]
field2: [UnionForGeneratingUnionListTypes]
}
14 changes: 7 additions & 7 deletions test/unit/should_generate_union_types_properly/expected.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ package com.kotlin.generated
import com.expediagroup.graphql.generator.annotations.*

@GraphQLDescription("A description for MyType1")
data class MyType1(
data class TypeForGeneratingUnionTypesProperly1(
val field: String? = null
)

data class MyType2(
data class TypeForGeneratingUnionTypesProperly2(
val field: String? = null
)

@GraphQLUnion(
name = "MyUnion",
possibleTypes = [MyType1::class, MyType2::class],
description = "A trimmed description for MyUnion"
name = "UnionForGeneratingUnionsProperly",
possibleTypes = [TypeForGeneratingUnionTypesProperly1::class, TypeForGeneratingUnionTypesProperly2::class],
description = "A trimmed description for UnionForGeneratingUnionsProperly"
)
annotation class MyUnion
annotation class UnionForGeneratingUnionsProperly

data class MyUnionType(
@MyUnion
@UnionForGeneratingUnionsProperly
@GraphQLDescription("A description for field")
val field: Any? = null,
val field2: String? = null
Expand Down
Loading

0 comments on commit a7364b3

Please sign in to comment.