-
Notifications
You must be signed in to change notification settings - Fork 326
Configure GraphQLServlet object mapper #32
Comments
Are you using 3.9.0? I released this change yesterday which should support that: fff13ab |
Yes, I am. I've just debugged the bootstrapping of the application and I do see that my configuration is being applied to the object mapper. So, answering my own question, configuration works just fine. I'll close the issue now and if relevant I'll post here (for reference) how I solved my problem. |
A bit more debugging shows that the object mapper used to deserialise inputs from mutations is not the same as the one I configured via a bean in the When I debug the bootstrapping of the application I see that the module Before my configuration is applied: After my configuration is applied: However, when handling the input of a mutation the object mapper is different (with a different memory address) and no longer has the |
It seems that the object mapper that deserialises the values passed into the mutation is not the one in the servlet but instead it's the one in |
I've fixed my problem (deserialising LocalDateTime objects passed in as inputs to mutations) by also registering a bean to configure the object mapper used by So the final configuration looks like this: @SpringBootApplication
public class Application {
(...)
@Bean
ObjectMapperConfigurer objectMapperConfigurer() {
return (ObjectMapper mapper) -> mapper.registerModule(new JavaTimeModule());
}
@Bean
SchemaParserOptions schemaParserOptions() {
return SchemaParserOptions.newOptions()
.objectMapperConfigurer((ObjectMapper mapper, ObjectMapperConfigurerContext context) -> mapper.registerModule(new JavaTimeModule()))
.build();
}
(...)
} |
Ah, yeah. The servlet object mapper handles parsing variables and output, but the graphql-java-tools objectmapper handles marshalling the field input values to java types. It's a little wonky, but since the two libraries can be used independently I'm not sure how to make it better. |
It's indeed a difficult one to solve elegantly. If the interfaces for the Thanks again for being so active in giving support 👍 |
It's possible to configure the object mapper used by the
GraphQLServlet
via a custom implementation of the (functional) interfaceObjectMapperConfigurer
(see graphql-java-kickstart/graphql-java-servlet@8f55785).I would expect it to be possible to register a bean of such implementation in the application context and have it injected in the
GraphQLServlet
. However this doesn't seem to be possible yet.Here's what I'm trying to do:
Is this something that needs to be implemented yet? Or am I going about it the wrong way?
The text was updated successfully, but these errors were encountered: