Headless Server Developer Manual / Version 2404
Table Of Contents
A query root is the primary object necessary to resolve a GraphQL query. The query root for all content queries
is mapped to the property name content
and is of type
ContentRoot.
It is created as a Spring bean in the CaasConfig
class and provides access to the content
repository. The GraphQL property content
in the query root of the content-schema is bound to an
equally named method, annotated with @QueryMapping
in a standard Spring controller class. The mapped
method delivers the ContentRoot
object.
Binding any root type GraphQL property to an annotated Spring controller is effectively done by the Spring-GraphQL library. Using this approach, it's easy to extend the query root with custom extensions. The integration of the eCommerce extension and the metadata root is implemented in the same way.
# GraphQL-Schema extension: extend type Query { customProperty: CustomRoot } type CustomRoot { types: [CustomType] } type CustomType { name: String }
// Java class @Controller public class CustomRootController { private final CustomRoot customRoot; public CustomRootController (CustomRoot customRoot) { this.customRoot = customRoot; } @QueryMapping public CustomRoot customProperty() { return customRoot; } }
The Java class ContentRoot
reflects the GraphQL root type in the query
root of the same name. All fields, defined in the GraphQL type correspond to a getter of the same name, for example the
page
query, which corresponds to the getter public getPage(DataFetchingEnvironment environment)
.
The result of the getter method is the so called root object (not identical to the query root) on which the following
resolving process relies.
On top of the reflection based invocation of the getter methods, CoreMedia added the @fetch
directive, which allows to express the data fetching for a property in the GraphQL scheme using the Spring
Expression Language (SpEL). The Spring EL allows a less restrictive approach to use the query root or even to
invoke completely different objects instead of the ContentRoot
, namely most of the adapters,
like the SettingsAdapter
or the NavigationAdapter
.