Skip to content

Commit 499886d

Browse files
authored
fix: input field deprecation (#85)
* unit test * make test pass
1 parent d173cef commit 499886d

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

src/annotations/build-description-annotation.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@ export function buildDescriptionAnnotation(
2727
const isDeprecatedDescription = trimmedDescription.startsWith(
2828
deprecatedDescriptionPrefix,
2929
);
30-
if (isDeprecatedDescription && typeMetadata?.unionAnnotation) {
30+
const isRequiredInputField =
31+
definitionNode.kind === Kind.INPUT_VALUE_DEFINITION &&
32+
definitionNode.type.kind === Kind.NON_NULL_TYPE;
33+
if (
34+
isDeprecatedDescription &&
35+
(typeMetadata?.unionAnnotation || isRequiredInputField)
36+
) {
3137
return `@GraphQLDescription("${trimmedDescription}")\n`;
3238
} else if (isDeprecatedDescription) {
3339
const descriptionValue = description.replace(

test/unit/should_annotate_types_properly/expected.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,11 @@ data class TypeThatShouldBeProperlyAnnotated(
3030
) : UnionThatShouldBeProperlyAnnotated
3131

3232
interface UnionThatShouldBeProperlyAnnotated
33+
34+
@GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.INPUT_OBJECT])
35+
data class InputTypeThatShouldBeProperlyAnnotated(
36+
@Deprecated("this field is deprecated")
37+
val optionalField: String? = null,
38+
@GraphQLDescription("DEPRECATED: this field is deprecated")
39+
val requiredField: String
40+
)

test/unit/should_annotate_types_properly/schema.graphql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,10 @@ type TypeThatShouldBeProperlyAnnotated {
3434
}
3535

3636
union UnionThatShouldBeProperlyAnnotated = TypeThatShouldBeProperlyAnnotated
37+
38+
input InputTypeThatShouldBeProperlyAnnotated {
39+
"DEPRECATED: this field is deprecated"
40+
optionalField: String
41+
"DEPRECATED: this field is deprecated"
42+
requiredField: String!
43+
}

0 commit comments

Comments
 (0)