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: fix recursion logic in minimizeSelectionSet #3158

Merged
merged 3 commits into from
Sep 30, 2024
Merged

Conversation

dariuszkuc
Copy link
Member

When generating fragments we were only "minimizing" subselections for fields and inline fragments that could be extracted. If inline fragment cannot be replaced with a fragment spread, we should still minimize its selection set as it potentially can be optimized as well.

When generating fragments we were only "minimizing" subselections for fields and inline fragments that could be extracted. If inline fragment cannot be replaced with a fragment spread, we should still minimize its selection set as it potentially can be optimized as well.
@dariuszkuc dariuszkuc requested a review from a team as a code owner September 27, 2024 20:56
Copy link

changeset-bot bot commented Sep 27, 2024

🦋 Changeset detected

Latest commit: ccf770a

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

This PR includes changesets to release 7 packages
Name Type
@apollo/federation-internals Patch
@apollo/gateway Patch
@apollo/composition Patch
@apollo/query-planner 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

Copy link

netlify bot commented Sep 27, 2024

Deploy Preview for apollo-federation-docs canceled.

Name Link
🔨 Latest commit ccf770a
🔍 Latest deploy log https://app.netlify.com/sites/apollo-federation-docs/deploys/66f72b2450568700088c3325

Copy link

codesandbox-ci bot commented Sep 27, 2024

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.

Copy link

@TylerBloom TylerBloom left a comment

Choose a reason for hiding this comment

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

LGTM. Do you know if the Rust side needs the same fix?

@dariuszkuc
Copy link
Member Author

LGTM. Do you know if the Rust side needs the same fix?

RS implementation is good -> that's how we found this.

Copy link
Member

@goto-bus-stop goto-bus-stop left a comment

Choose a reason for hiding this comment

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

nice!

@dariuszkuc dariuszkuc merged commit df5eb3c into main Sep 30, 2024
19 checks passed
@dariuszkuc dariuszkuc deleted the gen_fragments branch September 30, 2024 17:50
sachindshinde pushed a commit that referenced this pull request Oct 16, 2024
This PR was opened by the [Changesets
release](https:/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

- Updated dependencies
\[[`345661c558773e4eb5d5f0b28464a8d1acdc2a2d`](345661c),
[`e00e1c9892b48ac89823597113989830877966ef`](e00e1c9),
[`cc4573471696ef78d04fa00c4cf8e5c50314ba9f`](cc45734),
[`062572b3253e8640b60a0bf58b83945094b76b6f`](062572b),
[`df5eb3cb0e2b4802fcd425ab9c23714de2707db3`](df5eb3c),
[`1c99cb0dcc6c639ac351210932623ab0bd6907e4`](1c99cb0)]:
    -   @apollo/[email protected]
    -   @apollo/[email protected]

## @apollo/[email protected]

### Patch Changes

- Updated dependencies
\[[`345661c558773e4eb5d5f0b28464a8d1acdc2a2d`](345661c),
[`7fe1465cf35c2efe37ac5c73fac2b7ea04173318`](7fe1465),
[`cc4573471696ef78d04fa00c4cf8e5c50314ba9f`](cc45734),
[`062572b3253e8640b60a0bf58b83945094b76b6f`](062572b),
[`df5eb3cb0e2b4802fcd425ab9c23714de2707db3`](df5eb3c),
[`1c99cb0dcc6c639ac351210932623ab0bd6907e4`](1c99cb0)]:
    -   @apollo/[email protected]
    -   @apollo/[email protected]
    -   @apollo/[email protected]

## @apollo/[email protected]

### Patch Changes

- fix: normalize field set selection sets
([#3162](#3162))

`FieldSet` scalar represents a selection set without outer braces. This
means that users could potentially specify some selections that could be
normalized (i.e. eliminate duplicate field selections, hoist/collapse
unnecessary inline fragments, etc). Previously we were using `@requires`
field set selection AS-IS for edge conditions. With this change we will
now normalize the `FieldSet` selections before using them as fetch node
conditions.

- Fixed missing referenced variables in the `variableUsages` field of
fetch operations
([#3166](#3166))

Query variables used in fetch operation should be listed in the
`variableUsages` field. However, there was a bug where variables
referenced by query-level directives could be missing in the field.

- Fix fragment generation recursion logic to apply minification on all
subselections.
([#3158](#3158))

- Fixed a bug that `__typename` with applied directives gets lost in
fetch operations.
([#3164](#3164))

The sibling typename optimization used by query planner simplifies
operations by folding `__typename` selections into their sibling
selections. However, that optimization does not account for directives
or aliases. The bug was applying the optimization even if the
`__typename` has directives on it, which caused the selection to lose
its directives. Now, `__typename` with directives (or aliases) are
excluded from the optimization.

## @apollo/[email protected]

### Patch Changes

- Fixes edge case where contextual arguments can yield inefficient query
plans. Also fixes naming of query plan arguments which can be a problem
when using contextual variables in multiple subgraphs
([#3140](#3140))

- When eliminating suboptimal indirect paths during query planning,
properly check for a direct `@key` edge at the end of the potential
direct path.
([#3160](#3160))

- Fixed missing referenced variables in the `variableUsages` field of
fetch operations
([#3166](#3166))

Query variables used in fetch operation should be listed in the
`variableUsages` field. However, there was a bug where variables
referenced by query-level directives could be missing in the field.

- Updated dependencies
\[[`cc4573471696ef78d04fa00c4cf8e5c50314ba9f`](cc45734),
[`062572b3253e8640b60a0bf58b83945094b76b6f`](062572b),
[`df5eb3cb0e2b4802fcd425ab9c23714de2707db3`](df5eb3c),
[`1c99cb0dcc6c639ac351210932623ab0bd6907e4`](1c99cb0)]:
    -   @apollo/[email protected]

## @apollo/[email protected]

### Patch Changes

- Fixes edge case where contextual arguments can yield inefficient query
plans. Also fixes naming of query plan arguments which can be a problem
when using contextual variables in multiple subgraphs
([#3140](#3140))

- Ensure all useless fetch groups are removed
([#3163](#3163))

When removing "useless" fetch nodes/groups we remove them in-place while
still iterating over the same list. This leads to potentially skipping
processing of some the children fetch nodes, as when we remove nodes we
left shift all remaining children but the iterator keeps the old
position unchanged effectively skipping next child.

- fix: normalize field set selection sets
([#3162](#3162))

`FieldSet` scalar represents a selection set without outer braces. This
means that users could potentially specify some selections that could be
normalized (i.e. eliminate duplicate field selections, hoist/collapse
unnecessary inline fragments, etc). Previously we were using `@requires`
field set selection AS-IS for edge conditions. With this change we will
now normalize the `FieldSet` selections before using them as fetch node
conditions.

- Fixed missing referenced variables in the `variableUsages` field of
fetch operations
([#3166](#3166))

Query variables used in fetch operation should be listed in the
`variableUsages` field. However, there was a bug where variables
referenced by query-level directives could be missing in the field.

- Fixed a bug that `__typename` with applied directives gets lost in
fetch operations.
([#3164](#3164))

The sibling typename optimization used by query planner simplifies
operations by folding `__typename` selections into their sibling
selections. However, that optimization does not account for directives
or aliases. The bug was applying the optimization even if the
`__typename` has directives on it, which caused the selection to lose
its directives. Now, `__typename` with directives (or aliases) are
excluded from the optimization.

- Updated dependencies
\[[`345661c558773e4eb5d5f0b28464a8d1acdc2a2d`](345661c),
[`e00e1c9892b48ac89823597113989830877966ef`](e00e1c9),
[`cc4573471696ef78d04fa00c4cf8e5c50314ba9f`](cc45734),
[`062572b3253e8640b60a0bf58b83945094b76b6f`](062572b),
[`df5eb3cb0e2b4802fcd425ab9c23714de2707db3`](df5eb3c),
[`1c99cb0dcc6c639ac351210932623ab0bd6907e4`](1c99cb0)]:
    -   @apollo/[email protected]
    -   @apollo/[email protected]

## @apollo/[email protected]

### Patch Changes

- Updated dependencies
\[[`cc4573471696ef78d04fa00c4cf8e5c50314ba9f`](cc45734),
[`062572b3253e8640b60a0bf58b83945094b76b6f`](062572b),
[`df5eb3cb0e2b4802fcd425ab9c23714de2707db3`](df5eb3c),
[`1c99cb0dcc6c639ac351210932623ab0bd6907e4`](1c99cb0)]:
    -   @apollo/[email protected]

## [email protected]

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.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.

3 participants