Skip to content

Commit

Permalink
fix: input field deprecation (#85)
Browse files Browse the repository at this point in the history
* unit test

* make test pass
  • Loading branch information
danadajian authored Jun 12, 2024
1 parent d173cef commit 499886d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/annotations/build-description-annotation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 8 additions & 0 deletions test/unit/should_annotate_types_properly/expected.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
7 changes: 7 additions & 0 deletions test/unit/should_annotate_types_properly/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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!
}

0 comments on commit 499886d

Please sign in to comment.