Expand description
REST <-> GraphQL translation (DW-100).
The GraphqlTranslator implements super::ProtocolTranslator for
routes that front a GraphQL upstream with a REST client (or vice
versa). Two directions:
- REST-to-GraphQL (
kind: rest_to_graphql): the client sends a REST JSON body; the translator builds a GraphQL request from a config-supplied query template. The template carries$variableplaceholders that are filled from the JSON body’s fields, and the filled query plus avariablesmap become the GraphQL-over-HTTP POST body the upstream expects. - GraphQL-to-REST (
kind: graphql_to_rest): the upstream returns a GraphQL response envelope{ "data": { ... } }; the translator unwraps thedataobject and returns it as the REST JSON body the client expects. (A GraphQLerrorsarray maps to a 502 with the errors as the body.)
§Template syntax
The query template is plain GraphQL text with $variable references.
Each $name in the template is resolved from the inbound JSON body’s
top-level name field (the value is also placed in the variables
map sent to the upstream, so the upstream’s own variable resolution
works). A $name the body does not supply fails the translation
closed (the request never reaches the upstream with a dangling
variable).
§Feature gating
Compiled under the protocol_translation cargo feature.
Structs§
- Graphql
Translator - The REST-to-GraphQL / GraphQL-to-REST translator.
Enums§
- Graphql
Direction - The translation direction.