Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forward GraphQL request extensions to subgraphs with YAML #4876

Open
smyrick opened this issue Mar 27, 2024 · 0 comments
Open

Forward GraphQL request extensions to subgraphs with YAML #4876

smyrick opened this issue Mar 27, 2024 · 0 comments

Comments

@smyrick
Copy link
Member

smyrick commented Mar 27, 2024

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.extensions on an incoming request (likely at the SupergraphRequest phase)
  • Choose which fields I want and save them into the context
  • Add a hook for SubgraphRequest which reads the context and saves specific fields into that subgraph request.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
      }
    }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant