apollographql / router

A configurable, high-performance routing runtime for Apollo Federation 🚀
https://www.apollographql.com/docs/router/
Other
813 stars 271 forks source link

Extensions field received from subgraph is not forwarded #6178

Closed consra closed 3 weeks ago

consra commented 3 weeks ago

Describe the bug

I have a subgraph which is returning the following:

{
  "extensions": {
    "request-id": "UUID"
  },
  data: {...},
}

but the router is returning only this part without including the extensions field

{
  data: {...},
}

To Reproduce

A subgraph should return in the extensions a new field. The router won't forward the extensions field received from the subgraph.

Expected behavior

The extension field from the subgraph is returned to the caller as expected.

Output

N\A

Desktop (please complete the following information):

Additional context

N/A

abernix commented 3 weeks ago

If you want to preserve extensions values from subgraphs you can do that using Rhai script, it just won't happen automatically since it's just safer for us to not blindly attempt it than to to attempt it and get it wrong.

Unlike federation itself, there is no principled way (there is no declarative syntax) to merge extensions from multiple subgraphs in any automatic way. Say, if every subgraph returned request-id, it gets quickly into nuanced ordering details and property stomping that wouldn't be able to be sure that you got the right value. We're just not guaranteed an understanding of whether it will or will not be a problem to take a guess, nor can we make sure that it doesn't become a problem over time. (In fact, there is actually no specification for extensions at all, other than it’s just a map, so we don’t know if if those should be converted into an array when there are multiple, or if one should squash another, or if one should win over another, etc.)

So because of that, we can only handle well-known extensions (like our own) for which we understand their handling characteristics and how to safely merge them together.