fix(federation/qp): suppress the type condition at root-level inline spread in subgraph fetch operations#7580
fix(federation/qp): suppress the type condition at root-level inline spread in subgraph fetch operations#7580
Conversation
|
@duckki, please consider creating a changeset entry in |
✅ Docs preview readyThe preview is ready to be viewed. View the preview File Changes 0 new, 6 changed, 0 removedBuild ID: e8bdebe6e64ad22cee30c462 URL: https://www.apollographql.com/docs/deploy-preview/e8bdebe6e64ad22cee30c462 |
| let element_key = element.key().to_owned_key(); | ||
| let mut selection = Arc::make_mut(&mut self.selections) | ||
| .entry(ele.key()) | ||
| .entry(element_key.as_borrowed_key()) |
There was a problem hiding this comment.
this seems redundant? guessing its a leftover from debugging?
There was a problem hiding this comment.
It was a necessary change. After can_rebase_on change, some tests failed at .or_insert call below because ele.key() and element.key() became different in some cases (... on Query vs ...).
In general, ele and element may be different and it makes sense to look up element.key(), instead of ele.key(). It appears that resulting in a different key via rebase here never happened before.
BTW, to_owned_key/as_borrowed_key calls had to be added, since element itself is going to move into the closure below. So, the key had to be cloned using to_owned_key (the normal clone() would only do a shallow cloning).
Background
We allow renaming root types (like
MyQuery, instead ofQuery) in subgraph schemas. But, the supergraph schema does not record that renaming information. Thus, if an inline spread at root level like... on Query { ... }is present in the subgraph operation, it can cause runtime errors at the subgraph server since it will be invalid in the (original) subgraph schema.Proposed fix
We can simply drop any root type condition by changing
... on Queryto.... The unconditioned inline spread still may be necessary for directives.Discussion
Potential additional optimizations:
@defermay add an extra root-level inline spread, which could be avoided preemptively. But, this PR didn't implement that.Checklist
Complete the checklist (and note appropriate exceptions) before the PR is marked ready-for-review.
Closes #7573