Headless Server Developer Manual / Version 2406.0
Table Of Contents
Every persisted query may be accessed via REST. To enable access via REST, it is necessary, to add a
mapping of the persisted query to the intended endpoint. By default, the mapping is defined in the file
resources/graphql/rest-mapping/simple-mapping.properties
.
The name of the mapping file is configurable with the property caas.rest.query-mapping-pattern
.
The pattern must be suitable for a Spring PathMatchingResourcePatternResolver
which is used to load these resources.
# Spring PathMatchingResourcePattern to file or files # Defaults to 'graphql/rest-mapping/*.properties' # Example: caas.rest.query-mapping-pattern = graphql/rest-mapping/my-mappings.properties
Any persisted query which should be made accessible via REST must be mapped with the filename of the file where the query is defined, without the extension (.graphql), followed by an equal sign and the intended mapping. The mapping file expects one mapping per line. The format of a mapping may be one of the following two. Both possibilities are equivalent.
# 1. query-id = uri-template article = /article/{id} # 2. query-id = JSON Object containing at least the key 'uriTemplate' with the template as its value. # e.g. article = {"uriTemplate": "/article/{id}"}
Additionally, the JSON object must contain type mappings for all query variables, which are not of type "string". Due to the fact, that http parameters are strings by nature, the stricter validation of GraphQL query parameters requires a conversion of http parameters into the correct type. Supported conversion types are these basic scalars:
- boolean
- integer
- float
The mapping then may look similar to this:
# query-id = JSON Object containing type mapping additionally. search = {"uriTemplate": "/search/", "limit": "integer", "offset": "integer", "includeSubTypes": "boolean"}
The mapping file allows commenting lines via a #
in the beginning of a line.
Empty lines are also ignored, so using them for grouping is no problem.
The mapped URI fragment is always relative to the endpoint /caas/v1
.
In addition to a plain URI fragment, it is allowed, adding REST path parameters to the mapped URI fragment
using the URI template pattern: {myPathVariable}
. The path parameters are automatically
dispatched to the persisted query as GraphQL variables, as well as any query parameters.