Skip to content

Commit 8c4f1b2

Browse files
smyrickShane Myrick
andauthored
Include java getters for ignore checks (#842)
Co-authored-by: Shane Myrick <[email protected]>
1 parent bcd047b commit 8c4f1b2

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ internal fun KProperty<*>.isPropertyGraphQLID(parentClass: KClass<*>): Boolean =
3333
internal fun KProperty<*>.isPropertyGraphQLIgnored(parentClass: KClass<*>): Boolean = when {
3434
this.isGraphQLIgnored() -> true
3535
getConstructorParameter(parentClass)?.isGraphQLIgnored().isTrue() -> true
36+
this.getter.isGraphQLIgnored() -> true
3637
else -> false
3738
}
3839

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ internal class KPropertyExtensionsKtTest {
4545
@GraphQLName("nameOnConstructor")
4646
val constructorAnnotation: String,
4747

48+
@get:GraphQLIgnore
49+
val getterAnnotation: String,
50+
4851
val noAnnotations: String
4952
)
5053

@@ -59,6 +62,7 @@ internal class KPropertyExtensionsKtTest {
5962
fun isPropertyGraphQLIgnored() {
6063
assertTrue(MyDataClass::propertyAnnotation.isPropertyGraphQLIgnored(MyDataClass::class))
6164
assertTrue(MyDataClass::constructorAnnotation.isPropertyGraphQLIgnored(MyDataClass::class))
65+
assertTrue(MyDataClass::getterAnnotation.isPropertyGraphQLIgnored(MyDataClass::class))
6266
assertFalse(MyDataClass::noAnnotations.isPropertyGraphQLIgnored(MyDataClass::class))
6367
}
6468

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

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package com.expediagroup.graphql.generator.types
1818

1919
import com.expediagroup.graphql.annotations.GraphQLDescription
2020
import com.expediagroup.graphql.annotations.GraphQLDirective
21+
import com.expediagroup.graphql.annotations.GraphQLIgnore
2122
import com.expediagroup.graphql.generator.SchemaGenerator
2223
import com.expediagroup.graphql.generator.extensions.isTrue
2324
import com.expediagroup.graphql.getTestSchemaConfigWithMockedDirectives
@@ -28,12 +29,19 @@ import kotlin.reflect.KClass
2829
import kotlin.test.assertEquals
2930
import kotlin.test.assertTrue
3031

31-
internal class GenerateDirectiveTest {
32+
class GenerateDirectiveTest {
3233

3334
@GraphQLDirective
34-
internal annotation class DirectiveWithString(val string: String)
35+
annotation class DirectiveWithString(val string: String)
3536

36-
internal enum class Type {
37+
@GraphQLDirective
38+
annotation class DirectiveWithIgnoredArgs(
39+
val string: String,
40+
@get:GraphQLIgnore
41+
val ignoreMe: String
42+
)
43+
44+
enum class Type {
3745
@DirectiveWithString("my string")
3846
@DirectiveWithClass(SimpleDirective::class)
3947
ONE,
@@ -43,12 +51,12 @@ internal class GenerateDirectiveTest {
4351
}
4452

4553
@GraphQLDirective
46-
internal annotation class DirectiveWithEnum(val type: Type)
54+
annotation class DirectiveWithEnum(val type: Type)
4755

4856
@GraphQLDirective
49-
internal annotation class DirectiveWithClass(val kclass: KClass<*>)
57+
annotation class DirectiveWithClass(val kclass: KClass<*>)
5058

51-
internal class MyClass {
59+
class MyClass {
5260

5361
fun noAnnotation(string: String) = string
5462

@@ -69,9 +77,12 @@ internal class GenerateDirectiveTest {
6977

7078
@DirectiveWithClass(kclass = Type::class)
7179
fun directiveWithClass(string: String) = string
80+
81+
@DirectiveWithIgnoredArgs(string = "foo", ignoreMe = "bar")
82+
fun directiveWithIgnoredArgs(string: String) = string
7283
}
7384

74-
internal data class MyClassWithConstructorArgs(
85+
data class MyClassWithConstructorArgs(
7586
@SimpleDirective val noPrefix: String,
7687
@property:SimpleDirective val propertyPrefix: String,
7788
val noDirective: String
@@ -178,6 +189,14 @@ internal class GenerateDirectiveTest {
178189
assertEquals(expected = 0, actual = noPrefixResult.size)
179190
}
180191

192+
@Test
193+
fun `exlude directive arguments @GraphQLIgnore`() {
194+
val directives = generateDirectives(basicGenerator, MyClass::directiveWithIgnoredArgs)
195+
assertEquals(expected = 1, actual = directives.size)
196+
assertEquals(expected = 1, actual = directives.first().arguments.size)
197+
assertEquals(expected = "string", actual = directives.first().arguments.first().name)
198+
}
199+
181200
companion object {
182201
@AfterAll
183202
fun cleanUp(generateDirectiveTest: GenerateDirectiveTest) {

0 commit comments

Comments
 (0)