Git Product home page Git Product logo

Comments (7)

apottere avatar apottere commented on July 30, 2024

Are you using 3.9.0? I released this change yesterday which should support that: fff13ab

from graphql-spring-boot.

miguelaferreira avatar miguelaferreira commented on July 30, 2024

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.

from graphql-spring-boot.

miguelaferreira avatar miguelaferreira commented on July 30, 2024

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 Application class.

When I debug the bootstrapping of the application I see that the module JavaTimeModule is added to a object mapper that already contains the Jdk8Module (as expected).

Before my configuration is applied:

before-configuration

After my configuration is applied:

after-configuration

However, when handling the input of a mutation the object mapper is different (with a different memory address) and no longer has the JavaTimeModule.

handling-mutation

from graphql-spring-boot.

miguelaferreira avatar miguelaferreira commented on July 30, 2024

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 com.coxautodev.graphql.tools.MethodFieldResolver. java-graphql-tools also has it's own ObjectMapperConfigurer abstraction.

from graphql-spring-boot.

miguelaferreira avatar miguelaferreira commented on July 30, 2024

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 java-graphql-tools (which I use to parse the schema definition).

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();
    }
(...)

}

from graphql-spring-boot.

apottere avatar apottere commented on July 30, 2024

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.

from graphql-spring-boot.

miguelaferreira avatar miguelaferreira commented on July 30, 2024

It's indeed a difficult one to solve elegantly. If the interfaces for the ObjectMapperConfigurer in both projects would align, then it would be possible to create one configuration bean that would get injected in both sides. It wouldn't be super elegant, but a least would remove the need to configure things twice.

Thanks again for being so active in giving support 👍

from graphql-spring-boot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.