Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support @deprecated directives without a reason attribute #711

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

rveguilla
Copy link
Member

@rveguilla rveguilla commented Jul 9, 2024

This PR changes how the code generator handle schema @deprecated directives that are missing the reason attribute. The existing behavior was to throw an exception, which results in broken builds. The new behavior is to default to an empty comment when generating Java code and to default to a "Deprecated." message when generating Kotlin @deprecated annotations.

@rveguilla rveguilla changed the title Support @deprecated annotation without a reason attribute Support @deprecated directives without a reason attribute Jul 9, 2024
@@ -2780,23 +2780,37 @@ class KotlinCodeGenTest {
}

@Test
fun deprecateAnnotationWithNoMesssage() {
fun deprecateAnnotationWithNoReason() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: since we're changing it anyway, can we change it to be correct (there is a reason in this test case).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will make it correct by removing the reason attribute so that its missing from both deprecated directives. And for consistency, I will also update the corresponding test in CodeGenTest to test for the same scenario.

@@ -46,7 +46,7 @@ fun applyDirectivesKotlin(directives: List<Directive>, config: CodeGenConfig): M
if (argumentMap.containsKey(ParserConstants.REASON)) {
annotations.add(deprecatedAnnotation((argumentMap[ParserConstants.REASON] as StringValue).value))
} else {
throw IllegalArgumentException("Deprecated requires an argument `${ParserConstants.REASON}`")
annotations.add(deprecatedAnnotation("Deprecated."))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a String like "Deprecated in GraphQL schema" might be a bit better.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants