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

Client code: Generate deprecations #608

Merged

Conversation

theHacker
Copy link
Contributor

Client code generation now generates annotation and JavaDoc for deprecations, if enabled by addDeprecatedAnnotation.

Example:

extend type Query {
    
    foos(ids: [ID!] @deprecated(reason: "Use filters instead"), filters: FooFilters): [Foo!]!
}
Before After
image image

Hi there, 👋

This is my first contribution. I find createQueryClass() a very long and therefore unclear method. I did not dare to refactor here 😊 If you are fine with that, I would very much like to improve the code.

Copy link
Contributor

@srinivasankavitha srinivasankavitha left a comment

Choose a reason for hiding this comment

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

We'll need to also update the generateJava task config to be able to use this setting.

assertThat(codeGenResult.javaQueryTypes[0].typeSpec.typeSpecs[0].methodSpecs).hasSize(4)
assertThat(codeGenResult.javaQueryTypes[0].typeSpec.typeSpecs[0].methodSpecs[1].name).isEqualTo("nameFilter")
assertThat(codeGenResult.javaQueryTypes[0].typeSpec.typeSpecs[0].methodSpecs[1].toString()).isEqualTo(
"""
Copy link
Contributor

Choose a reason for hiding this comment

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

I would recommend checking that the generated class has the annotation rather than checking the entire code block to string match against. Same for the other tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I want to assert that annotation and the javadoc look like expected.
Since both make up the upper part of the code, I rewrote with startsWith(). That way one you still easily see the empty that is expected to separate description and @deprecated inside the javadoc.

Is this acceptable? Or would you rather me to use methodSpec's annotations and javadoc for all cases?

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess we can leave it as is in this scenario, makes sense to me.

…cations, if enabled by addDeprecatedAnnotation

- sanitizeJavaDoc() is now also supported directly on a plain String
@theHacker theHacker force-pushed the feature/deprecation-on-client-code branch from a106840 to 75adbdd Compare November 29, 2023 13:12
@theHacker
Copy link
Contributor Author

Sorry about the late reply 😊

We'll need to also update the generateJava task config to be able to use this setting.

I don't understand that. I did not create that setting, but rather implemented its execution a bit further.
Do you mean GenerateJavaTask.kt, lines 145 and 211?

Or am I overlooking something? Glad for a hint into the right direction 😄

@srinivasankavitha
Copy link
Contributor

Sorry about the late reply 😊

We'll need to also update the generateJava task config to be able to use this setting.

I don't understand that. I did not create that setting, but rather implemented its execution a bit further. Do you mean GenerateJavaTask.kt, lines 145 and 211?

Or am I overlooking something? Glad for a hint into the right direction 😄

Ah right, my bad. Sorry for the confusion. I see that we do indeed have it here: https://github.com/Netflix/dgs-codegen/blob/master/graphql-dgs-codegen-gradle/src/main/kotlin/com/netflix/graphql/dgs/codegen/gradle/GenerateJavaTask.kt#L145

@srinivasankavitha srinivasankavitha merged commit 1d235a1 into Netflix:master Nov 29, 2023
2 checks passed
@theHacker theHacker deleted the feature/deprecation-on-client-code branch November 30, 2023 08:23
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.

2 participants