leangen / graphql-spqr

Build a GraphQL service in seconds
Apache License 2.0
1.09k stars 179 forks source link

Scalars containing an Instant cannot be serialized over subscription #488

Open Survival1sm opened 4 months ago

Survival1sm commented 4 months ago

When an object containing an Instant is sent over the subscription as a non-scalar (List), the Instant is converted to a string by graphql prior to jackson, and is able to be serialized by ApolloMessages within the jsonMessage method.

When the object is sent over the subscription as a scalar (Map_String_ObjectWithInstant), the Instant retains its data type up to jackson, and since the object mapper in ApolloMessages does not have the JavaTimeModule registered, it can no longer be serialized and produces the following exception:

com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Java 8 date/time typejava.time.Instantnot supported by default: add Module "com.fasterxml.jackson.datatype:jackson-datatype-jsr310" to enable handling

Originating from AplloMessages:71

image

I resolved the issue by creating my own PerConnectionApolloHandler bean, and providing duplicate implementations of PerConnectionApolloHandler, ApolloProtocolHandler, and finally ApolloMessages with the updated object mapper.

Do we have a better way to solve this?