Skip to content

Support constructor binding for input arguments #138

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

Closed
koenpunt opened this issue Sep 19, 2021 · 4 comments
Closed

Support constructor binding for input arguments #138

koenpunt opened this issue Sep 19, 2021 · 4 comments
Labels
status: superseded Issue is superseded by another

Comments

@koenpunt
Copy link
Contributor

koenpunt commented Sep 19, 2021

Using spring-graphql with Kotlin works, but when a field has a data class representing an input type, the class can't be instantiated, and fails on BeanUtils.instantiateClass(ctor);.

This repo/commit demonstrates the issue by adding a Kotlin configuration to the project, and adding a test using a kotlin data class as mutation argument:

koenpunt@f85fd6e

A workaround is to not use data classes, but I do believe data classes should be supported as well.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Sep 19, 2021
@koenpunt
Copy link
Contributor Author

For clarification; this used to work before 4dfb662 with the changes of this PR.

Maybe a jackson ObjectMapper would be more suitable for constructing these objects?

@bclozel bclozel self-assigned this Sep 20, 2021
@bclozel bclozel changed the title Bug: Kotlin data classes as input types cannot be instantiated Support constructor instantiation for input arguments Sep 20, 2021
@bclozel bclozel added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Sep 20, 2021
@bclozel bclozel added this to the 1.0 Backlog milestone Sep 20, 2021
@bclozel
Copy link
Member

bclozel commented Sep 20, 2021

This is indeed a limitation from the latest changes in input arguments support; as explained in 4dfb662, an object mapper based approach is not efficient and may override custom scalars.

Using a Binder works pretty well in other arrangements (Spring MVC, WebFlux, Messaging); we might refactor this in web frameworks for reusability (see spring-projects/spring-framework#25943) but I doubt this would work for the GraphQL use case. We need to adapt the existing infrastructure in web frameworks to this project to support constructor binding.

@bclozel bclozel changed the title Support constructor instantiation for input arguments Support constructor binding for input arguments Sep 20, 2021
@koenpunt
Copy link
Contributor Author

koenpunt commented Sep 20, 2021

Hm that's a pity.

We need to adapt the existing infrastructure in web frameworks to this project to support constructor binding.

You mean something like this? https://github.com/spring-projects/spring-framework/blob/958eb0f964ddef1ff1440fd10c5cb850f6ee96db/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ModelAttributeMethodArgumentResolver.java#L228-L260

@bclozel bclozel added status: superseded Issue is superseded by another and removed type: enhancement A general enhancement labels Sep 20, 2021
@bclozel bclozel removed this from the 1.0 Backlog milestone Sep 20, 2021
@bclozel bclozel removed their assignment Sep 20, 2021
@bclozel
Copy link
Member

bclozel commented Sep 20, 2021

Closing in favor of #139

@bclozel bclozel closed this as completed Sep 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: superseded Issue is superseded by another
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants