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

Fix nested fragments on interfaces (when a directive is present) #2864

Closed
wants to merge 1 commit into from

Conversation

trevor-scheer
Copy link
Member

The following query:

query {
  i {
    _id
    ... on I2 {
      ... on I2 @test {
        id
      }
    }
  }
}

Blows up with the following error:

Cannot add fragment of condition "I2" (runtimes: [T1,T2]) to parent type "T1" (runtimes: T1)

When the @test directive is removed, we collapse the inline fragments and this error doesn't occur, but we can't do that when a directive application is present.

This seems to be due to the way that the query planner handles interface conditions, by expanding them into their runtime types. My understanding right now is roughly this:

Expanding the above query in theory looks something like:

query {
  i {
    _id
    ... on T1 {
      ... on I2 @test {
        id
      }
    }
    ... on T2 {
      ... on I2 @test {
        id
      }
    }
  }
}

...but this T2 as parent type of an I2 is triggering the error since canRebaseOn is returning false.

Minimal reproduction of #2862

@trevor-scheer trevor-scheer requested a review from a team as a code owner November 22, 2023 00:11
Copy link

changeset-bot bot commented Nov 22, 2023

⚠️ No Changeset found

Latest commit: 8dd82d0

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

netlify bot commented Nov 22, 2023

Deploy Preview for apollo-federation-docs canceled.

Name Link
🔨 Latest commit 8dd82d0
🔍 Latest deploy log https://app.netlify.com/sites/apollo-federation-docs/deploys/655d472618a2870008d856bd

@trevor-scheer trevor-scheer marked this pull request as draft November 22, 2023 00:11
Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@dariuszkuc
Copy link
Member

Superseded by #2875

@dariuszkuc dariuszkuc closed this Dec 5, 2023
@dariuszkuc dariuszkuc deleted the trevor/fix-nested-fragments-on-itfs branch December 5, 2023 00:51
dariuszkuc added a commit that referenced this pull request Dec 5, 2023
… query graphs

This PR addresses issues with handling fragments when they specify directive conditions:
* when exploding the types we were not propagating directive conditions
* when processing fragment that specifies super type of an existing type and also specifies directive condition, we were incorrectly preserving the unnecessary type condition. This type condition was problematic as it could be referecing types from supergraph that were not available in the local schema. Instead, we now drop the redundant type condition and only preserve the directives (if specified).

Related:
* fixes #2862
* supersedes #2864
dariuszkuc added a commit that referenced this pull request Dec 5, 2023
…phs (#2875)

This PR addresses issues with handling fragments when they specify
directive conditions:
* when exploding the types we were not propagating directive conditions
* when processing fragment that specifies super type of an existing type
and also specifies directive condition, we were incorrectly preserving
the unnecessary type condition. This type condition was problematic as
it could be referencing types from supergraph that were not available in
the local schema. Instead, we now drop the redundant type condition and
only preserve the directives (if specified).

Related:
* fixes #2862
* supersedes #2864

---------

Co-authored-by: Chris Lenfest <clenfest@apollographql.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants