Skip to content

Commit

Permalink
fix: trim union descriptions (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
danadajian authored Apr 1, 2024
1 parent f595ca1 commit 44064cf
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/definitions/union.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { UnionTypeDefinitionNode } from "graphql";
import { shouldIncludeTypeDefinition } from "../helpers/should-include-type-definition";
import { buildDirectiveAnnotations } from "../helpers/build-directive-annotations";
import { CodegenConfig } from "../plugin";
import { trimDescription } from "../helpers/build-annotations";

export function buildUnionTypeDefinition(
node: UnionTypeDefinitionNode,
Expand All @@ -30,7 +31,7 @@ export function buildUnionTypeDefinition(
return `${directiveAnnotations}@GraphQLUnion(
name = "${node.name.value}",
possibleTypes = [${possibleTypes}],
description = "${node.description?.value ?? ""}"
description = "${node.description?.value ? trimDescription(node.description.value) : ""}"
)
annotation class ${node.name.value}`;
}
2 changes: 1 addition & 1 deletion src/helpers/build-annotations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export function isDeprecatedDescription(
);
}

function trimDescription(description: string) {
export function trimDescription(description: string) {
return (
description
.split("\n")
Expand Down
2 changes: 1 addition & 1 deletion test/unit/should_generate_union_types_properly/expected.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ data class MyType2(
@GraphQLUnion(
name = "MyUnion",
possibleTypes = [MyType1::class, MyType2::class],
description = "A description for MyUnion"
description = "A trimmed description for MyUnion"
)
annotation class MyUnion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ type MyType2 {
field: String
}

"A description for MyUnion"
"""
A "trimmed" description for MyUnion
"""
union MyUnion = MyType1 | MyType2

type MyUnionType {
Expand Down

0 comments on commit 44064cf

Please sign in to comment.