Skip to content

Commit 3bdfec9

Browse files
dariuszkucrickfast
authored andcommitted
Remove directive info from descriptions (#81)
Resolves #79
1 parent a3f4dc8 commit 3bdfec9

File tree

2 files changed

+2
-66
lines changed

2 files changed

+2
-66
lines changed

src/main/kotlin/com/expedia/graphql/schema/extensions/annotationExtensions.kt

Lines changed: 2 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -16,60 +16,9 @@ import kotlin.reflect.KParameter
1616
import kotlin.reflect.full.findAnnotation
1717
import com.expedia.graphql.annotations.GraphQLDirective as DirectiveAnnotation
1818

19-
internal fun KAnnotatedElement.graphQLDescription(): String? {
20-
val directiveNames = listOfDirectives().map { it.normalizeDirectiveName() }
21-
val description = this.findAnnotation<GraphQLDescription>()?.value
22-
return formatGraphQLDescription(description, directiveNames)
23-
}
24-
25-
internal fun Field.graphQLDescription(): String? {
26-
val directiveNames = listOfDirectives().map { it.normalizeDirectiveName() }
27-
val description = this.getAnnotation(GraphQLDescription::class.java)?.value
28-
return formatGraphQLDescription(description, directiveNames)
29-
}
30-
31-
private fun formatGraphQLDescription(description: String?, directiveNames: List<String>): String? = when {
32-
description != null && directiveNames.isNotEmpty() ->
33-
"""$description
34-
|
35-
|Directives: ${directiveNames.joinToString(", ")}
36-
""".trimMargin()
37-
description == null && directiveNames.isNotEmpty() ->
38-
"Directives: ${directiveNames.joinToString(", ")}"
39-
else -> description
40-
}
41-
42-
private fun KAnnotatedElement.listOfDirectives(): List<String> {
43-
val deprecationReason: String? = this.getDeprecationReason()?.let { "deprecated" }
44-
45-
return this.annotations.asSequence()
46-
.mapNotNull { it.getDirectiveInfo() }
47-
.map {
48-
when {
49-
it.effectiveName.isNullOrEmpty().not() -> "@${it.effectiveName}"
50-
else -> null
51-
}
52-
}
53-
.plus(deprecationReason)
54-
.filterNotNull()
55-
.toList()
56-
}
57-
58-
private fun Field.listOfDirectives(): List<String> {
59-
val deprecationReason: String? = this.getDeprecationReason()?.let { "deprecated" }
19+
internal fun KAnnotatedElement.graphQLDescription(): String? = this.findAnnotation<GraphQLDescription>()?.value
6020

61-
return this.declaredAnnotations.asSequence()
62-
.mapNotNull { it.getDirectiveInfo() }
63-
.map {
64-
when {
65-
it.effectiveName.isNullOrEmpty().not() -> "@${it.effectiveName}"
66-
else -> null
67-
}
68-
}
69-
.plus(deprecationReason)
70-
.filterNotNull()
71-
.toList()
72-
}
21+
internal fun Field.graphQLDescription(): String? = this.getAnnotation(GraphQLDescription::class.java)?.value
7322

7423
internal fun KAnnotatedElement.getDeprecationReason(): String? = this.findAnnotation<Deprecated>()?.getReason()
7524

src/test/kotlin/com/expedia/graphql/schema/generator/DirectiveTests.kt

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import com.expedia.graphql.schema.testSchemaConfig
66
import com.expedia.graphql.toSchema
77
import graphql.Scalars
88
import graphql.introspection.Introspection
9-
import graphql.schema.GraphQLInputObjectType
109
import graphql.schema.GraphQLNonNull
1110
import graphql.schema.GraphQLObjectType
1211
import org.junit.jupiter.api.Test
@@ -24,21 +23,9 @@ class DirectiveTests {
2423
val deprecatedField = result?.getFieldDefinition("deprecatedField")
2524

2625
assertEquals(deprecatedField?.isDeprecated, true)
27-
assertEquals("Directives: deprecated", deprecatedField?.description)
2826
assertEquals("this field is deprecated", deprecatedField?.deprecationReason)
2927
}
3028

31-
@Test
32-
fun `SchemaGenerator includes deprecated notice for deprecated fields`() {
33-
val schema = toSchema(listOf(TopLevelObjectDef(QueryWithDeprecatedFields())), config = testSchemaConfig)
34-
val topLevelQuery = schema.getObjectType("TopLevelQuery")
35-
val query = topLevelQuery.getFieldDefinition("deprecatedArgumentQuery")
36-
val argument = query.getArgument("input")
37-
val deprecatedInputField = ((argument.type as? GraphQLNonNull)?.wrappedType as? GraphQLInputObjectType)?.getFieldDefinition("deprecatedField")
38-
39-
assertEquals("Directives: deprecated", deprecatedInputField?.description)
40-
}
41-
4229
@Test
4330
fun `SchemaGenerator marks deprecated queries and documents replacement`() {
4431
val schema = toSchema(listOf(TopLevelObjectDef(QueryWithDeprecatedFields())), config = testSchemaConfig)

0 commit comments

Comments
 (0)