From 499886d1f30a02ce78eade32b5adfeb5e3536a18 Mon Sep 17 00:00:00 2001 From: Dan Adajian Date: Wed, 12 Jun 2024 09:31:01 -0500 Subject: [PATCH] fix: input field deprecation (#85) * unit test * make test pass --- src/annotations/build-description-annotation.ts | 8 +++++++- test/unit/should_annotate_types_properly/expected.kt | 8 ++++++++ test/unit/should_annotate_types_properly/schema.graphql | 7 +++++++ 3 files changed, 22 insertions(+), 1 deletion(-) 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 2f578ac..410fa38 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("DEPRECATED: 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! +}