router
router copied to clipboard
Forward GraphQL request extensions to subgraphs with YAML
Is your feature request related to a problem? Please describe.
The GraphQL request has the ability to specify an extensions block which may have some custom information needed by my subgraphs or it expects that to exist in the extensions block as well.
In order for me to get that info to subgraphs, I need to add a Rhai script or coprocessor that does the follow:
- Parse the
request.body.extensionson an incoming request (likely at theSupergraphRequestphase) - Choose which fields I want and save them into the
context - Add a hook for
SubgraphRequestwhich reads thecontextand saves specific fields into that subgraphrequest.body.extensions
Describe the solution you'd like
Similar to the configuration we can do today with HTTP headers in YAML, allow configuring which extensions keys can be forwarded
Sample HTTP request
{
"query": "query MyOperation ...",
"variables": {},
"extensions": {
"my-custom-field-a": 1,
"my-custom-field-b": 2,
}
}
Sample future Router config
extensions:
all:
request:
- propagate:
named: "my-custom-field-a"
subgraphs:
products:
request:
- insert:
name: "custom-extension"
value: "foo"
Describe alternatives you've considered
I can solve this today with Rhai or coprocesser but that requires some code when the logic here is the same as headers
Additional context
We need to be aware of not forwarding everything. APQs and Apollo put some things in the extensions so we want this configurable on a per field.
We also need to consider if we want to allow nested forwarding. Headers are just one key-value so that is easy. Extensions though can be nested objects so maybe for YAML we just support the root level, and more advanced uses require Rhai or Coprocessor.
We could maybe support a JSONPath selector though for simple value fowarding like how we support it for span attribute selection from the data response body
{
"query": "query MyOperation ...",
"variables": {},
"extensions": {
"foo": {
"bar": {
"baz": 1
}
}
}
}