Skip to content

Commit d58e0b9

Browse files
authored
fix: trim deprecated reasons (#33)
1 parent 3df8ef3 commit d58e0b9

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

src/helpers/build-directive-annotations.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ limitations under the License.
1212
*/
1313

1414
import { CodegenConfig, GraphQLKotlinCodegenConfig } from "../plugin";
15-
import { DefinitionNode, isDeprecatedDescription } from "./build-annotations";
15+
import {
16+
DefinitionNode,
17+
isDeprecatedDescription,
18+
trimDescription,
19+
} from "./build-annotations";
1620
import { getFederationDirectiveReplacement } from "./get-federation-directive-replacement";
1721
import { TypeMetadata } from "./build-type-metadata";
1822
import { ConstDirectiveNode } from "graphql/language";
@@ -46,7 +50,8 @@ export function buildDirectiveAnnotations(
4650
const descriptionAnnotator = resolvedType?.unionAnnotation
4751
? "@GraphQLDescription"
4852
: "@Deprecated";
49-
return `${descriptionAnnotator}("${deprecatedReason}")\n`;
53+
const trimmedDeprecatedReason = trimDescription(deprecatedReason);
54+
return `${descriptionAnnotator}("${trimmedDeprecatedReason}")\n`;
5055
}
5156
const federationReplacement =
5257
getFederationDirectiveReplacement(directive);

test/unit/should_annotate_types_properly/expected.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import com.expediagroup.graphql.generator.annotations.*
44

55
@GraphQLDescription("A description for MyType")
66
data class TypeThatShouldBeProperlyAnnotated(
7-
val username: String? = null,
8-
@GraphQLDescription("A description for email")
9-
val email: String? = null,
10-
@GraphQLDescription("A `weird` description for name")
11-
val name: String? = null,
7+
val field: String? = null,
8+
@GraphQLDescription("A description for fieldWithDescription")
9+
val fieldWithDescription: String? = null,
10+
@GraphQLDescription("A `weird` description for weirdDescription")
11+
val weirdDescription: String? = null,
1212
@Deprecated("Use something else instead")
1313
val deprecated1: String? = null,
1414
@Deprecated("")
@@ -25,7 +25,9 @@ data class TypeThatShouldBeProperlyAnnotated(
2525
val deprecated6: Any? = null,
2626
@UnionThatShouldBeProperlyAnnotated
2727
@GraphQLDescription("When there is a description")
28-
val deprecated7: Any? = null
28+
val deprecated7: Any? = null,
29+
@Deprecated("Multiline reason")
30+
val deprecated8: String? = null
2931
)
3032

3133
@GraphQLUnion(

test/unit/should_annotate_types_properly/schema.graphql

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ A "description" for MyType
44
It can be multiline
55
"""
66
type TypeThatShouldBeProperlyAnnotated {
7-
username: String
8-
"A description for email"
9-
email: String
7+
field: String
8+
"A description for fieldWithDescription"
9+
fieldWithDescription: String
1010
"""
11-
A \`weird\` description for name
11+
A \`weird\` description for weirdDescription
1212
"""
13-
name: String
13+
weirdDescription: String
1414
"DEPRECATED: Use something else instead"
1515
deprecated1: String
1616
deprecated2: String @deprecated
@@ -27,6 +27,10 @@ type TypeThatShouldBeProperlyAnnotated {
2727
"When there is a description"
2828
deprecated7: UnionThatShouldBeProperlyAnnotated
2929
@deprecated(reason: "It omits the @Deprecated annotation for now")
30+
deprecated8: String
31+
@deprecated(
32+
reason: "\n Multiline reason\n with spaces\n "
33+
)
3034
}
3135

3236
union UnionThatShouldBeProperlyAnnotated = TypeThatShouldBeProperlyAnnotated

0 commit comments

Comments
 (0)