From f1f0894f603ac891e3e20466d0e23e32592321e8 Mon Sep 17 00:00:00 2001 From: Dan Adajian Date: Wed, 3 Apr 2024 17:12:45 -0500 Subject: [PATCH] fix: duplicated description annotation on union fields (#25) --- src/helpers/build-directive-annotations.ts | 3 +++ test/unit/should_annotate_types_properly/expected.kt | 5 ++++- test/unit/should_annotate_types_properly/schema.graphql | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/helpers/build-directive-annotations.ts b/src/helpers/build-directive-annotations.ts index cda2d8b..1c219d0 100644 --- a/src/helpers/build-directive-annotations.ts +++ b/src/helpers/build-directive-annotations.ts @@ -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"; diff --git a/test/unit/should_annotate_types_properly/expected.kt b/test/unit/should_annotate_types_properly/expected.kt index fb51de1..91d0f18 100644 --- a/test/unit/should_annotate_types_properly/expected.kt +++ b/test/unit/should_annotate_types_properly/expected.kt @@ -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( diff --git a/test/unit/should_annotate_types_properly/schema.graphql b/test/unit/should_annotate_types_properly/schema.graphql index 5b2a22b..45a889a 100644 --- a/test/unit/should_annotate_types_properly/schema.graphql +++ b/test/unit/should_annotate_types_properly/schema.graphql @@ -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