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
Add Boolean fields to Data classes for supporting sparse update #664
Add Boolean fields to Data classes for supporting sparse update #664
Conversation
graphql-dgs-codegen-core/src/main/kotlin/com/netflix/graphql/dgs/codegen/CodeGen.kt
Outdated
Show resolved
Hide resolved
graphql-dgs-codegen-core/src/main/kotlin/com/netflix/graphql/dgs/codegen/CodeGenCli.kt
Outdated
Show resolved
Hide resolved
...en-core/src/main/kotlin/com/netflix/graphql/dgs/codegen/generators/java/DataTypeGenerator.kt
Outdated
Show resolved
Hide resolved
...en-core/src/main/kotlin/com/netflix/graphql/dgs/codegen/generators/java/DataTypeGenerator.kt
Outdated
Show resolved
Hide resolved
graphql-dgs-codegen-core/src/test/kotlin/com/netflix/graphql/dgs/codegen/CodeGenTest.kt
Outdated
Show resolved
Hide resolved
Hi @srinivasankavitha Can you take a look at the PR |
|
Thanks @srinivasankavitha. I am also working on updating Kotlin codegen. |
yeah that flag is specific to kotlin2. Yes, it would be great of you can add to both since we try to maintain feature parity as much as possible. |
Sounds great, thank you 👍 |
Also, you can run |
This reverts commit cd71b3a.
Linting and some unit tests fixed, please check @srinivasankavitha |
I see the CI build just failed at stage "Build Examples". Can you share any pointers if this needs to be fixed on the PR and how I can run the CI test locally for validating CI builds? |
Both examples are here: https://github.com/Netflix/dgs-examples-java-2.7 |
Thanks @srinivasankavitha I ran through the examples and dropped in a quick fix adding conditional boolean field generation for input type values as well. The build failure message is as below:
I am wondering if this fix will fix the test as well--I a m unsure what test is failing atm ^ as sent above. Can you please retry the build and guide if I need to do anything else to fix like updating expected values etc.? |
ReservedKeywordSanitizer.sanitize(it.name), | ||
ReservedKeywordSanitizer.sanitize(it.name) | ||
) | ||
if (!(!it.isNullable && it.initialValue == null)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's probably cleaner to write this as:
if (it.isNullable && it.initialValue == null) {
// ...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kilink Fields are generated for all these cases:
- Nullable | No default values --> Generate fields
- Nullable | With default values --> Generate fields
- Non-Nullable | No default values --> Field not needed
- Non-Nullable | With default values --> Generate fields
Fields are generated for both nullable field with default value as well as non-nullable with default value might get assigned default values by initializer without direct request from the client. This is our understanding from existing graphql services leveraging sparse update solution. Having Boolean field for other cases will help identify values set by the client.
With this, I can update the double negative to simplify the logic:
if (it.isNullable && it.initialValue != null))
Is this acceptable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no reason to generate fields for any of the cases except the first one: a nullable field with no defaults. For any case with a default value, it's impossible for DGS to tell if the value was explicitly supplied or not, graphql-java will hand us the variables with the default value already there. So the flag here would always be "true". The flag is pretty useless in that case and misleading.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack, updated to generate fields for nullable fields with no default values.
@@ -360,6 +381,35 @@ abstract class BaseDataTypeGenerator( | |||
|
|||
private fun addField(fieldDefinition: Field, javaType: TypeSpec.Builder) { | |||
addFieldWithGetterAndSetter(fieldDefinition.type, fieldDefinition, javaType) | |||
// Generate for all fields except non-nullable without default values |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: I think the comment would be clearer if it was stated as what we want to generate the fields for, e.g.:
Generate for all nullable fields without any defaults
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated 👍
@@ -360,6 +381,35 @@ abstract class BaseDataTypeGenerator( | |||
|
|||
private fun addField(fieldDefinition: Field, javaType: TypeSpec.Builder) { | |||
addFieldWithGetterAndSetter(fieldDefinition.type, fieldDefinition, javaType) | |||
// Generate for all fields except non-nullable without default values | |||
if (!(!fieldDefinition.isNullable && fieldDefinition.initialValue == null)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment here as before, I would avoid that "double negative" and write this as:
if (fieldDefinition.isNullable && fieldDefinition.initialValue == null) {
// ...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated same as above
...en-core/src/main/kotlin/com/netflix/graphql/dgs/codegen/generators/java/DataTypeGenerator.kt
Outdated
Show resolved
Hide resolved
...en-core/src/main/kotlin/com/netflix/graphql/dgs/codegen/generators/java/DataTypeGenerator.kt
Outdated
Show resolved
Hide resolved
This seems to have fixed the build now, right? I see the CI build is green. |
@srinivasankavitha Yes I was just able to validate this locally as well, this fixed the build. Please help validate and merge the PR. |
@kilink Thanks for reviewing, I have updated as per your feedback. Please check if the changes are good |
Hi @kilink @srinivasankavitha Checking in if you need anything from me before the PR can be merged |
Hi @krutikavk - we are out this week. We will take a look next week. |
@srinivasankavitha following up on this. Will you be able to review this PR? And let us know if you need any further changes to the PR |
@srinivasankavitha Thanks for approving. |
Just merged the PR. Will do a release later this week or early next week. |
Thank you |
Hi @srinivasankavitha Checking in when you are able to create a new release tag for this feature |
Hi @srinivasankavitha @kilink I see this change has been recently reverted in commit 08eb4ad. Will this be updated/released soon? Do update if there are any outstanding issues with the feature. |
Hi @krutikavk - yes, I did a release yesterday and it broke a bunch of our projects and had to rollback. I'm yet to investigate and get a good idea of the failure scenarios (there are multiple). Will post an update, so we can fix forward. At teh very least, we might need to feature flag it and disable by default since the addition of the new field is breaking tests for users that are checking strings using toString(). |
.addJavadoc(it.javadoc) | ||
.returns(builderClassName) | ||
.addStatement("this.${it.name} = ${it.name}") | ||
|
||
val fieldName = it.name | ||
val field = fields.find { it.name.contains(fieldName) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be
val field = fields.find { iter-> ReservedKeywordSanitizer.sanitize(iter.name) == fieldName }
Otherwise it matches other fields that are similarly named and is incorrect.
e.g. something
and isSomethingThere
..will generate isSomething
that conflicts with isSomethingThere
field.
Also this is problematic if the field isSomething
is also there as part of the schema.
Ok so couple things that need fixing:
|
Description
Issue: #609
Add Boolean fields to all data classes. Here is a gist of changes:
is<Field>Defined
getIs<Field>Defined
is<Field>Defined
Example of data classes created:
Thanks!
Validation
Sample schema and codegen with bitset: https://github.com/krutikavk/dgs-codegen-run