From ef8c20bc6b38eb64d40edc020fb283886e8095ff Mon Sep 17 00:00:00 2001 From: Dan Adajian Date: Wed, 12 Jun 2024 09:12:20 -0500 Subject: [PATCH 1/2] unit test --- test/unit/should_annotate_types_properly/expected.kt | 8 ++++++++ test/unit/should_annotate_types_properly/schema.graphql | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/test/unit/should_annotate_types_properly/expected.kt b/test/unit/should_annotate_types_properly/expected.kt index 2f578ac..9e86a69 100644 --- a/test/unit/should_annotate_types_properly/expected.kt +++ b/test/unit/should_annotate_types_properly/expected.kt @@ -30,3 +30,11 @@ data class TypeThatShouldBeProperlyAnnotated( ) : UnionThatShouldBeProperlyAnnotated interface UnionThatShouldBeProperlyAnnotated + +@GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.INPUT_OBJECT]) +data class InputTypeThatShouldBeProperlyAnnotated( + @Deprecated("this field is deprecated") + val optionalField: String? = null, + @GraphQLDescription("this field is deprecated") + val requiredField: String +) diff --git a/test/unit/should_annotate_types_properly/schema.graphql b/test/unit/should_annotate_types_properly/schema.graphql index ffdde85..31eaf7c 100644 --- a/test/unit/should_annotate_types_properly/schema.graphql +++ b/test/unit/should_annotate_types_properly/schema.graphql @@ -34,3 +34,10 @@ type TypeThatShouldBeProperlyAnnotated { } union UnionThatShouldBeProperlyAnnotated = TypeThatShouldBeProperlyAnnotated + +input InputTypeThatShouldBeProperlyAnnotated { + "DEPRECATED: this field is deprecated" + optionalField: String + "DEPRECATED: this field is deprecated" + requiredField: String! +} From 924cb58e67e88cfaa17ab32048c070bf65598cd5 Mon Sep 17 00:00:00 2001 From: Dan Adajian Date: Wed, 12 Jun 2024 09:25:39 -0500 Subject: [PATCH 2/2] make test pass --- src/annotations/build-description-annotation.ts | 8 +++++++- test/unit/should_annotate_types_properly/expected.kt | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/annotations/build-description-annotation.ts b/src/annotations/build-description-annotation.ts index e7b93a0..de2aee3 100644 --- a/src/annotations/build-description-annotation.ts +++ b/src/annotations/build-description-annotation.ts @@ -27,7 +27,13 @@ export function buildDescriptionAnnotation( const isDeprecatedDescription = trimmedDescription.startsWith( deprecatedDescriptionPrefix, ); - if (isDeprecatedDescription && typeMetadata?.unionAnnotation) { + const isRequiredInputField = + definitionNode.kind === Kind.INPUT_VALUE_DEFINITION && + definitionNode.type.kind === Kind.NON_NULL_TYPE; + if ( + isDeprecatedDescription && + (typeMetadata?.unionAnnotation || isRequiredInputField) + ) { return `@GraphQLDescription("${trimmedDescription}")\n`; } else if (isDeprecatedDescription) { const descriptionValue = description.replace( diff --git a/test/unit/should_annotate_types_properly/expected.kt b/test/unit/should_annotate_types_properly/expected.kt index 9e86a69..410fa38 100644 --- a/test/unit/should_annotate_types_properly/expected.kt +++ b/test/unit/should_annotate_types_properly/expected.kt @@ -35,6 +35,6 @@ interface UnionThatShouldBeProperlyAnnotated data class InputTypeThatShouldBeProperlyAnnotated( @Deprecated("this field is deprecated") val optionalField: String? = null, - @GraphQLDescription("this field is deprecated") + @GraphQLDescription("DEPRECATED: this field is deprecated") val requiredField: String )