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

Fix handling of @InputArgument for Java objects with optionals. #1926

Closed
wants to merge 2 commits into from

Conversation

srinivasankavitha
Copy link
Contributor

Pull Request type

  • Bugfix
  • Feature
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Other (please describe):

Changes in this PR

This PR fixes handling of @InputArgument for optionals. The current implementation of the DefaultInputObjectMapper does not handling converting from map to optionals, resulting in the following error when used:

**Failed to convert from type [java.util.LinkedHashMap<?, ?>] to type [@com.netflix.graphql.dgs.InputArgument 

Conversion of String to Optional, for e.g works fine since Spring's ObjectToOptionalConverter handles this fine: https://github.com/spring-projects/spring-framework/blob/main/spring-core/src/main/java/org/springframework/core/convert/support/ObjectToOptionalConverter.java

Adding similar logic to the DefaultInputObjectMapper to handle optionals based on this code: https://github.com/spring-projects/spring-framework/blob/main/spring-core/src/main/java/org/springframework/core/convert/support/ObjectToOptionalConverter.java#L76

Describe the new behavior from this PR, and why it's needed
Issue #1925

Copy link
Contributor

@Emily Emily left a comment

Choose a reason for hiding this comment

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

Could you add a test that checks the behavior when one of the optional fields isn't present?

@@ -67,6 +69,18 @@ class DefaultInputObjectMapper(customInputObjectMapper: InputObjectMapper? = nul
if (KotlinDetector.isKotlinType(targetType.type)) {
return mapper.mapToKotlinObject(sourceMap, targetType.type.kotlin)
}

if (targetType.resolvableType.hasGenerics()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this check specifically for Optional instead of any type with generics?

@filippocozzini
Copy link

Any update?

@srinivasankavitha
Copy link
Contributor Author

Any update?

Sorry for the delay. I need to address some of the comments before I can push the fix through.

@srinivasankavitha
Copy link
Contributor Author

Declining this PR in favor of a better fix here: #1951

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.

None yet

4 participants