Skip to content

Conversation

@aldib
Copy link
Contributor

@aldib aldib commented Nov 15, 2021


Description

When using GraphQL federation, external parties can extend types and inputs from the initial schema. Consequently, the server might receive queries and mutations that contains more fields than the ones originally generated.

This changes introduces two new options:

Option Data Type Default value Description
supportUnknownFields Boolean false Specifies whether api classes should support unknown fields during serialization or deserialization. If true, classes will include a property of type java.util.Map<String,Object> that will store unknown fields.
unknownFieldsPropertyName String userDefinedFields Specifies the name of the property to be included in api classes to support unknown fields during serialization or deserialization

When supportUnknownFields=true a new catch-all field annotated with the com.fasterxml.jackson.annotation.JsonAnySetter and com.fasterxml.jackson.annotation.JsonAnyGetter is added to generated code to serialize and deserialize unknown fields using a map.

Please let me know if you agree with the changes and/or if I missed anything.

Thank you in advance


Changes were made to:

  • Codegen library - Java
  • Codegen library - Kotlin
  • Codegen library - Scala
  • Maven plugin
  • Gradle plugin
  • SBT plugin

Copy link
Owner

@kobylynskyi kobylynskyi left a comment

Choose a reason for hiding this comment

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

Overall the idea and implementation look ok to me. Please address the requested changes and also check-code-style issues.
Thank you!

aldib and others added 9 commits December 7, 2021 10:23
…inputs from the initial schema. Consequently, the server might receive queries and mutations that contains more fields than the ones originally generated.

This changes introduces two new options:
| Option                                                | Data Type                                                             | Default value                                          | Description |
| :---------------------------------------------------: | :-------------------------------------------------------------------: | :----------------------------------------------------: | ----------- |
| `supportUnknownFields`                                | Boolean                                                               | false                                                  | Specifies whether api classes should support unknown fields during serialization or deserialization. If `true`, classes will include a property of type [`java.util.Map<String,Object>`](https://docs.oracle.com/javase/8/docs/api/index.html?java/util/Map.html) that will store unknown fields.|
| `unknownFieldsPropertyName`                           | String                                                                | userDefinedFields                                      | Specifies the name of the property to be included in api classes to support unknown fields during serialization or deserialization|

When `supportUnknownFields=true` a new catch-all field annotated with the [com.fasterxml.jackson.annotation.JsonAnySetter](https://fasterxml.github.io/jackson-annotations/javadoc/2.12/com/fasterxml/jackson/annotation/JsonAnySetter.html) and [com.fasterxml.jackson.annotation.JsonAnyGetter](https://fasterxml.github.io/jackson-annotations/javadoc/2.12/com/fasterxml/jackson/annotation/JsonAnyGetter.html) is added to generated code to serialize and deserialize unknown fields using a map.

Changes were made to:

* Codegen library - Java
* Codegen library - Kotlin
* Codegen library - Scala
* Maven plugin
* Gradle plugin
* SBT plugin

Please let me know if you agree with the changes and/or if I missed anything.

Thank you in advance
2. Removed unecessary import statements
3. Externalized the creation of ParameterDefinition to utility interface com.kobylynskyi.graphql.codegen.mapper.UnknownFieldsSupport to avoid duplicated code
2. Fixing code-style issues
…inputs from the initial schema. Consequently, the server might receive queries and mutations that contains more fields than the ones originally generated.

This changes introduces two new options:
| Option                                                | Data Type                                                             | Default value                                          | Description |
| :---------------------------------------------------: | :-------------------------------------------------------------------: | :----------------------------------------------------: | ----------- |
| `supportUnknownFields`                                | Boolean                                                               | false                                                  | Specifies whether api classes should support unknown fields during serialization or deserialization. If `true`, classes will include a property of type [`java.util.Map<String,Object>`](https://docs.oracle.com/javase/8/docs/api/index.html?java/util/Map.html) that will store unknown fields.|
| `unknownFieldsPropertyName`                           | String                                                                | userDefinedFields                                      | Specifies the name of the property to be included in api classes to support unknown fields during serialization or deserialization|

When `supportUnknownFields=true` a new catch-all field annotated with the [com.fasterxml.jackson.annotation.JsonAnySetter](https://fasterxml.github.io/jackson-annotations/javadoc/2.12/com/fasterxml/jackson/annotation/JsonAnySetter.html) and [com.fasterxml.jackson.annotation.JsonAnyGetter](https://fasterxml.github.io/jackson-annotations/javadoc/2.12/com/fasterxml/jackson/annotation/JsonAnyGetter.html) is added to generated code to serialize and deserialize unknown fields using a map.

Changes were made to:

* Codegen library - Java
* Codegen library - Kotlin
* Codegen library - Scala
* Maven plugin
* Gradle plugin
* SBT plugin

Please let me know if you agree with the changes and/or if I missed anything.

Thank you in advance
2. Removed unecessary import statements
3. Externalized the creation of ParameterDefinition to utility interface com.kobylynskyi.graphql.codegen.mapper.UnknownFieldsSupport to avoid duplicated code
2. Fixing code-style issues
@aldib aldib requested a review from kobylynskyi December 7, 2021 13:31
@kobylynskyi
Copy link
Owner

@aldib I've addressed some of the changes in your branch, please review my changes and let me know if you have any questions.
Also, I see that some of your unit tests are failing. Please address those and we will be good to merge this PR.
Thanks!
And sorry for not responding for so long - I got pulled to other stuff.

@aldib
Copy link
Contributor Author

aldib commented Jan 20, 2022

@kobylynskyi Thank you for the changes. I fixed the unit tests that were failing after the rebase, and I'm happy to merge if you are. Thanks.

@aldib
Copy link
Contributor Author

aldib commented Jan 20, 2022

@kobylynskyi I am not sure what to do about the failed sonar job. Could you please advise on how to solve the problem? Thanks

@kobylynskyi kobylynskyi merged commit d6f7d73 into kobylynskyi:develop Jan 20, 2022
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