Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: duplicated description annotation on union fields #25

Merged
merged 2 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/helpers/build-directive-annotations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ export function buildDirectiveAnnotations(
deprecatedReasonNode?.kind === "StringValue"
? deprecatedReasonNode.value
: "";
if (incomingNode.description?.value && resolvedType?.unionAnnotation) {
return "";
}
const descriptionAnnotator = resolvedType?.unionAnnotation
? "@GraphQLDescription"
: "@Deprecated";
Expand Down
5 changes: 4 additions & 1 deletion test/unit/should_annotate_types_properly/expected.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ data class MyType(
val deprecated5: Any? = null,
@MyUnion
@GraphQLDescription("It uses the GraphQLDescription annotation for union types")
val deprecated6: Any? = null
val deprecated6: Any? = null,
@MyUnion
@GraphQLDescription("When there is a description")
val deprecated7: Any? = null
)

@GraphQLUnion(
Expand Down
3 changes: 3 additions & 0 deletions test/unit/should_annotate_types_properly/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ type MyType {
@deprecated(
reason: "It uses the GraphQLDescription annotation for union types"
)
"When there is a description"
deprecated7: MyUnion
@deprecated(reason: "It omits the @Deprecated annotation for now")
}

union MyUnion = MyType