Skip to content

Commit

Permalink
fix: trim deprecated reasons (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
danadajian authored Apr 15, 2024
1 parent 3df8ef3 commit d58e0b9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
9 changes: 7 additions & 2 deletions src/helpers/build-directive-annotations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ limitations under the License.
*/

import { CodegenConfig, GraphQLKotlinCodegenConfig } from "../plugin";
import { DefinitionNode, isDeprecatedDescription } from "./build-annotations";
import {
DefinitionNode,
isDeprecatedDescription,
trimDescription,
} from "./build-annotations";
import { getFederationDirectiveReplacement } from "./get-federation-directive-replacement";
import { TypeMetadata } from "./build-type-metadata";
import { ConstDirectiveNode } from "graphql/language";
Expand Down Expand Up @@ -46,7 +50,8 @@ export function buildDirectiveAnnotations(
const descriptionAnnotator = resolvedType?.unionAnnotation
? "@GraphQLDescription"
: "@Deprecated";
return `${descriptionAnnotator}("${deprecatedReason}")\n`;
const trimmedDeprecatedReason = trimDescription(deprecatedReason);
return `${descriptionAnnotator}("${trimmedDeprecatedReason}")\n`;
}
const federationReplacement =
getFederationDirectiveReplacement(directive);
Expand Down
14 changes: 8 additions & 6 deletions test/unit/should_annotate_types_properly/expected.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import com.expediagroup.graphql.generator.annotations.*

@GraphQLDescription("A description for MyType")
data class TypeThatShouldBeProperlyAnnotated(
val username: String? = null,
@GraphQLDescription("A description for email")
val email: String? = null,
@GraphQLDescription("A `weird` description for name")
val name: String? = null,
val field: String? = null,
@GraphQLDescription("A description for fieldWithDescription")
val fieldWithDescription: String? = null,
@GraphQLDescription("A `weird` description for weirdDescription")
val weirdDescription: String? = null,
@Deprecated("Use something else instead")
val deprecated1: String? = null,
@Deprecated("")
Expand All @@ -25,7 +25,9 @@ data class TypeThatShouldBeProperlyAnnotated(
val deprecated6: Any? = null,
@UnionThatShouldBeProperlyAnnotated
@GraphQLDescription("When there is a description")
val deprecated7: Any? = null
val deprecated7: Any? = null,
@Deprecated("Multiline reason")
val deprecated8: String? = null
)

@GraphQLUnion(
Expand Down
14 changes: 9 additions & 5 deletions test/unit/should_annotate_types_properly/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ A "description" for MyType
It can be multiline
"""
type TypeThatShouldBeProperlyAnnotated {
username: String
"A description for email"
email: String
field: String
"A description for fieldWithDescription"
fieldWithDescription: String
"""
A \`weird\` description for name
A \`weird\` description for weirdDescription
"""
name: String
weirdDescription: String
"DEPRECATED: Use something else instead"
deprecated1: String
deprecated2: String @deprecated
Expand All @@ -27,6 +27,10 @@ type TypeThatShouldBeProperlyAnnotated {
"When there is a description"
deprecated7: UnionThatShouldBeProperlyAnnotated
@deprecated(reason: "It omits the @Deprecated annotation for now")
deprecated8: String
@deprecated(
reason: "\n Multiline reason\n with spaces\n "
)
}

union UnionThatShouldBeProperlyAnnotated = TypeThatShouldBeProperlyAnnotated

0 comments on commit d58e0b9

Please sign in to comment.