Skip to content

Commit 44064cf

Browse files
authored
fix: trim union descriptions (#21)
1 parent f595ca1 commit 44064cf

File tree

4 files changed

+7
-4
lines changed

4 files changed

+7
-4
lines changed

src/definitions/union.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { UnionTypeDefinitionNode } from "graphql";
1515
import { shouldIncludeTypeDefinition } from "../helpers/should-include-type-definition";
1616
import { buildDirectiveAnnotations } from "../helpers/build-directive-annotations";
1717
import { CodegenConfig } from "../plugin";
18+
import { trimDescription } from "../helpers/build-annotations";
1819

1920
export function buildUnionTypeDefinition(
2021
node: UnionTypeDefinitionNode,
@@ -30,7 +31,7 @@ export function buildUnionTypeDefinition(
3031
return `${directiveAnnotations}@GraphQLUnion(
3132
name = "${node.name.value}",
3233
possibleTypes = [${possibleTypes}],
33-
description = "${node.description?.value ?? ""}"
34+
description = "${node.description?.value ? trimDescription(node.description.value) : ""}"
3435
)
3536
annotation class ${node.name.value}`;
3637
}

src/helpers/build-annotations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export function isDeprecatedDescription(
9595
);
9696
}
9797

98-
function trimDescription(description: string) {
98+
export function trimDescription(description: string) {
9999
return (
100100
description
101101
.split("\n")

test/unit/should_generate_union_types_properly/expected.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ data class MyType2(
1414
@GraphQLUnion(
1515
name = "MyUnion",
1616
possibleTypes = [MyType1::class, MyType2::class],
17-
description = "A description for MyUnion"
17+
description = "A trimmed description for MyUnion"
1818
)
1919
annotation class MyUnion
2020

test/unit/should_generate_union_types_properly/schema.graphql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ type MyType2 {
77
field: String
88
}
99

10-
"A description for MyUnion"
10+
"""
11+
A "trimmed" description for MyUnion
12+
"""
1113
union MyUnion = MyType1 | MyType2
1214

1315
type MyUnionType {

0 commit comments

Comments
 (0)