Skip to content

Improve options to customize of ConversionService used for GraphQL argument binding #271

Closed
@MothF

Description

@MothF

Spring Boot version: 2.7.0-M1
Spring GraphQL version: 1.0.0-M5

Hello. I faced a problem with arguments resolution when passing them to GraphQL controller methods

I have a declared method accepting some input DTO which may have field of one of the types: OffsetDateTime, ZonedDateTime, LocalDateTime. In terms of GraphQl variables it’s a date-formatted string.
There is also related graphql.schema.Coercing responsible for deserialization into java.time.Instant. So in general I want to convert java.time.Instant into correct date representation.

There are several cases where I need customization:

  1. Controller plain argument mapping (ex. OffsetDateTime/ZonedDateTime it depends)
  2. Controller DTO argument mapping (ex. TestInput)

In the first case I need a way to customize ConversionService but without overriding AnnotatedControllerConfigurer bean because it may have unpredictable consequences in future (as I'm developing custom library it would be impossible to maintain). For example it would be okay to call conversion service setter in some configuration PostConstruct method, but as for now it won’t have any effect because of hardcoded GraphQlArgumentInitializer at afterPropertySet method

In the second case there are several problems:

  1. If I want to use no-args-constructor and setters deserialization GraphQlArgumentInitializer will use DataBinder. In such case if something is wrong with mapping into DTO DataBinder doesn’t throw any exception. In my opinion if DataBinder contains some errors they should be re-thrown as it’s done in all-args-constructor case.
  2. There should be a way for DataBinder customization. As DataBinder is hardcoded I’m not able to do this. Check this line

So I think that ConversionService should be passed to DataBinder (something like this dataBinder.setConversionService(this.typeConverter.getConversionService());) and there should be an ability to customize ConversionService

If there is a workaround or my case is inapplicable I'd like to know about it. Also please check project with issues reproduction https://github.com/MothF/spring-graphql

Thank you in advance.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions