Configure Jackson codec specifically for GraphQL HTTP endpoints

Prior to this commit, the `GraphQlHttpHandler` implementations would use
the JSON codecs configured in the web Framework (MVC or WebFlux) for
reading and writing GraphQL payloads as JSON documents.

This can cause issues in cases the application configures the JSON codec
in a way that makes it incompatible with the expected GraphQL documents.
For example, not serializing empty values and arrays.

This commit adds new constructors in `GraphQlHttpHandler`
implementations that can get a custom JSON codec for GraphQL payloads.

Closes gh-860
This commit is contained in:
Brian Clozel
2024-04-02 18:11:35 +02:00
parent 3e898f74fa
commit 9e4d77395a
13 changed files with 333 additions and 43 deletions

View File

@@ -29,6 +29,11 @@ xref:boot-starter.adoc[Boot Starter] does this, see the
details, or check `GraphQlWebMvcAutoConfiguration` or `GraphQlWebFluxAutoConfiguration`
it contains, for the actual config.
By default, the `GraphQlHttpHandler` will serialize and deserialize JSON payloads using the `HttpMessageConverter` (Spring MVC)
and the `DecoderHttpMessageReader/EncoderHttpMessageWriter` (WebFlux) configured in the web framework.
In some cases, the application will configure the JSON codec for the HTTP endpoint in a way that is not compatible with the GraphQL payloads.
Applications can instantiate `GraphQlHttpHandler` with a custom JSON codec that will be used for GraphQL payloads.
The 1.0.x branch of this repository contains a Spring MVC
{github-10x-branch}/samples/webmvc-http[HTTP sample] application.