Headless Server Developer Manual / Version 2201
Table Of Contents
The Headless Server uses a configured instance of the Spring ConversionService
at several places.
The ConvertingDataFetcher
uses the conversion service to convert any resolved field value, e.g. a
RichTextAdapter
object, into an object type which can be consumed by the GraphQL runtime, e.g. a
string representation of a rich text.
The Spring Expression Language uses the ConversionService
to convert any argument into the
necessary type required to be invoked on a function, e.g.
@localizedVariantsAdapterFactory.to().getLocalizationForLocale(#root, #language, #country, #variant)
.
In this example, the function getLocalizationForLocale(...)
is called on an instance of a
LocalizedVariantsAdapter
. The ConversionService
will try to convert all parameters of the
function into appropriate types defined by the function itself.
To add additional converters to the conversion service, one simply has to implement the
org.springframework.core.convert.converter.Converter
and create it as a regular SpringBean.
Additional Spring Converters are especially useful when using GraphQL input type. See Section “Automatic conversion of GraphQL input types to Java Objects” for details.