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

Reapply #2639 (with fix for #2680) #2687

Merged
merged 2 commits into from
Jul 19, 2023
Merged

Conversation

trevor-scheer
Copy link
Member

This PR ports #2684 to the 2.5.x release line.

This commit reapplies #2639 with an additional fix related to reproducing and resolving #2680.

The bug existed in the SelectionSet.contains logic in the final check to provide a ContainsResult. Here the lengths of the compared selection sets are used to determine subset or strictly equal. In the case that the __typename field was ignored up above, the comparison becomes invalid unless we offset the comparison by 1 to account for the non-existent field.

This commit reapplies #2639 with an additional fix related to
reproducing and resolving #2680.

The bug existed in the SelectionSet.contains logic in the final
check to provide a ContainsResult. Here the lengths of the
compared selection sets are used to determine subset or
strictly equal. In the case that the __typename field was
ignored up above, the comparison becomes invalid unless we
offset the comparison by 1 to account for the non-existent field.
@trevor-scheer trevor-scheer requested a review from a team as a code owner July 19, 2023 16:54
@changeset-bot
Copy link

changeset-bot bot commented Jul 19, 2023

🦋 Changeset detected

Latest commit: c6eddfa

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 7 packages
Name Type
@apollo/query-planner Patch
@apollo/federation-internals Patch
@apollo/gateway Patch
@apollo/composition Patch
@apollo/query-graphs Patch
@apollo/subgraph Patch
apollo-federation-integration-testsuite Patch

Not sure what this means? Click here to learn what changesets are.

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

@netlify
Copy link

netlify bot commented Jul 19, 2023

Deploy Preview for apollo-federation-docs canceled.

Name Link
🔨 Latest commit c6eddfa
🔍 Latest deploy log https://app.netlify.com/sites/apollo-federation-docs/deploys/64b8155f6ee7c000086a245d

@codesandbox-ci
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.

@trevor-scheer trevor-scheer merged commit b9052fd into main Jul 19, 2023
4 checks passed
@trevor-scheer trevor-scheer deleted the trevor/forward-port-2684 branch July 19, 2023 21:59
@glasser
Copy link
Member

glasser commented Jul 20, 2023

This part is the fix, right?

@@ -1856,8 +1856,12 @@ export class SelectionSet {
     }
 
     let isEqual = true;
+    let didIgnoreTypename = false;
     for (const [key, thatSelection] of that._keyedSelections) {
       if (key === typenameFieldName && ignoreMissingTypename) {
+        if (!this._keyedSelections.has(typenameFieldName)) {
+          didIgnoreTypename = true;
+        }
         continue;
       }
 
@@ -1869,7 +1873,7 @@ export class SelectionSet {
       isEqual &&= selectionResult === ContainsResult.EQUAL;
     }
 
-    return isEqual && that._selections.length === this._selections.length
+    return isEqual && that._selections.length === (this._selections.length + (didIgnoreTypename ? 1 : 0))
       ? ContainsResult.EQUAL
       : ContainsResult.STRICTLY_CONTAINED;
   }

@trevor-scheer
Copy link
Member Author

@glasser correct

@glasser
Copy link
Member

glasser commented Jul 20, 2023

oh that's more obvious in the non-backport :)

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