-
Notifications
You must be signed in to change notification settings - Fork 254
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 a query planning bug where invalid subgraph queries are generated with reuseQueryFragments
set true
#2963
Conversation
👷 Deploy request for apollo-federation-docs pending review.Visit the deploys page to approve it
|
🦋 Changeset detectedLatest commit: 1a5211e The changes in this PR will be included in the next version bump. This PR includes changesets to release 7 packages
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 |
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. |
- updated computeExpandedSelectionSetAtType function not to trim fragment's validators if the fragment's type condition is not an object type. - This change is necessary because `FieldsInSetCanMerge` rule is more restrictive in that case. - The untrimmed validator should avoid generating invalid queries, but it may be less efficient. apollographql#2952
@dariuszkuc I just rebased this PR on top of current origin/main. Please review. Thanks! |
@goto-bus-stop Please also review this one :)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It took me a little bit to grasp the issue here 😇
Test and implementation looks good 👍🏻
internals-js/src/operations.ts
Outdated
@@ -1224,6 +1224,14 @@ export class NamedFragmentDefinition extends DirectiveTargetElement<NamedFragmen | |||
const expandedSelectionSet = this.expandedSelectionSet(); | |||
const selectionSet = expandedSelectionSet.normalize({ parentType: type }); | |||
|
|||
if( ! isObjectType(this.typeCondition) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if( ! isObjectType(this.typeCondition) ) { | |
if (!isObjectType(this.typeCondition)) { |
just style (not familiar with this repo, i'm not sure why it isn't enforced 🤔 )
* @param subgraphs | ||
*/ | ||
function validateSubFetches( | ||
plan: any, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
plan: any, | |
plan: PlanNode | SubscriptionNode | undefined, |
if these types are not available in this file they should be imported from ../QueryPlan.ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pre-approval to unblock merging after the plan: any
is addressed 😄
@goto-bus-stop Thanks for the review. I pushed a fix. |
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated. # Releases ## @apollo/[email protected] ### Patch Changes - Fix a query planning bug where invalid subgraph queries are generated with `reuseQueryFragments` set true. ([#2952](#2952)) ([#2963](#2963)) - Updated dependencies \[[`ec04c50b4fb832bfd281ecf9c0c2dd7656431b96`](ec04c50), [`a494631918156f0431ceace74281c076cf1d5d51`](a494631)]: - @apollo/[email protected] - @apollo/[email protected] ## @apollo/[email protected] ### Patch Changes - Updated dependencies \[[`ec04c50b4fb832bfd281ecf9c0c2dd7656431b96`](ec04c50), [`3e2c845c74407a136b9e0066e44c1ad1467d3013`](3e2c845), [`a494631918156f0431ceace74281c076cf1d5d51`](a494631)]: - @apollo/[email protected] - @apollo/[email protected] - @apollo/[email protected] ## @apollo/[email protected] ### Patch Changes - Fix a query planning bug where invalid subgraph queries are generated with `reuseQueryFragments` set true. ([#2952](#2952)) ([#2963](#2963)) - Fixed query planner to pass the directives from original query to subgraph operations (#2961) ([#2967](#2967)) ## @apollo/[email protected] ### Patch Changes - Updated dependencies \[[`ec04c50b4fb832bfd281ecf9c0c2dd7656431b96`](ec04c50), [`a494631918156f0431ceace74281c076cf1d5d51`](a494631)]: - @apollo/[email protected] ## @apollo/[email protected] ### Patch Changes - Fix a query planning bug where invalid subgraph queries are generated with `reuseQueryFragments` set true. ([#2952](#2952)) ([#2963](#2963)) - Type conditioned fetching ([#2949](#2949)) When querying a field that is in a path of 2 or more unions, the query planner was not able to handle different selections and would aggressively collapse selections in fetches yielding an incorrect plan. This change introduces new syntax to express type conditions in (key and flatten) paths. Type conditioned fetching can be enabled through a flag, and execution is supported in the router only. (#2938) - Fixed query planner to pass the directives from original query to subgraph operations (#2961) ([#2967](#2967)) - Updated dependencies \[[`ec04c50b4fb832bfd281ecf9c0c2dd7656431b96`](ec04c50), [`a494631918156f0431ceace74281c076cf1d5d51`](a494631)]: - @apollo/[email protected] - @apollo/[email protected] ## @apollo/[email protected] ### Patch Changes - Updated dependencies \[[`ec04c50b4fb832bfd281ecf9c0c2dd7656431b96`](ec04c50), [`a494631918156f0431ceace74281c076cf1d5d51`](a494631)]: - @apollo/[email protected] ## [email protected] Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This PR fixes #2952.
Summary of changes
FieldsInSetCanMerge
rule is more restrictive in that case.Test plan