Skip to content

Comments

fix(federation/qp): suppress the type condition at root-level inline spread in subgraph fetch operations#7580

Merged
duckki merged 4 commits intodevfrom
duckki/fed-638
Jun 4, 2025
Merged

fix(federation/qp): suppress the type condition at root-level inline spread in subgraph fetch operations#7580
duckki merged 4 commits intodevfrom
duckki/fed-638

Conversation

@duckki
Copy link
Contributor

@duckki duckki commented May 27, 2025

Background

We allow renaming root types (like MyQuery, instead of Query) 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 Query to .... The unconditioned inline spread still may be necessary for directives.

Discussion

Potential additional optimizations:

  • Root-level inline spreads could be eliminated completely, if no directives are present. But, this PR did not attempt to do that.
  • @defer may 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.

  • Changes are compatible[^1]
  • Documentation[^2] completed
  • Performance impact assessed and acceptable
  • Tests added and passing[^3]
    • Unit Tests
    • Integration Tests
    • Manual Tests

Closes #7573

@github-actions
Copy link
Contributor

@duckki, please consider creating a changeset entry in /.changesets/. These instructions describe the process and tooling.

@svc-apollo-docs
Copy link
Collaborator

svc-apollo-docs commented May 28, 2025

✅ Docs preview ready

The preview is ready to be viewed. View the preview

File Changes

0 new, 6 changed, 0 removed
* graphos/routing/(latest)/configuration/yaml.mdx
* graphos/routing/(latest)/customization/custom-binary.mdx
* graphos/routing/(latest)/operations/subscriptions/configuration.mdx
* graphos/routing/(latest)/performance/caching/distributed.mdx
* graphos/routing/(latest)/performance/caching/in-memory.mdx
* graphos/routing/(latest)/security/demand-control.mdx

Build ID: e8bdebe6e64ad22cee30c462

URL: https://www.apollographql.com/docs/deploy-preview/e8bdebe6e64ad22cee30c462

@duckki duckki marked this pull request as ready for review May 28, 2025 18:51
@duckki duckki requested a review from a team May 28, 2025 18:51
@duckki duckki requested review from a team as code owners May 28, 2025 18:51
@duckki duckki changed the title fix(federation/qp): suppress root type conditions in subgraph fetch operations fix(federation/qp): suppress the type condition at root-level inline spread in subgraph fetch operations May 28, 2025
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())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems redundant? guessing its a leftover from debugging?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

@duckki duckki requested a review from sachindshinde June 3, 2025 00:40
@duckki duckki merged commit e138410 into dev Jun 4, 2025
15 checks passed
@duckki duckki deleted the duckki/fed-638 branch June 4, 2025 17:17
garypen pushed a commit that referenced this pull request Jun 9, 2025
Co-authored-by: Gary Pennington <gary@apollographql.com>
@abernix abernix mentioned this pull request Jul 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants