Skip to content

fix: updated generateQueryFragments option to only generate fragments at least 2 selections#2962

Merged
dariuszkuc merged 4 commits intoapollographql:mainfrom
duckki:duckki/generate-query-fagments-min-size
Mar 20, 2024
Merged

fix: updated generateQueryFragments option to only generate fragments at least 2 selections#2962
dariuszkuc merged 4 commits intoapollographql:mainfrom
duckki:duckki/generate-query-fagments-min-size

Conversation

@duckki
Copy link
Contributor

@duckki duckki commented Mar 20, 2024

This is a follow-up of #2958.

I've changed SelectionSet.minimizeSelectionSet to create a new fragment only when the selection set has at least 2 items.

This behavior is inspired by the behavior of reuseQueryFragments option. However, I wasn't sure whether re-using the NamedFragments.selectionSetIsWorthUsing function here is right or not. So, I didn't reuse it.

@duckki duckki requested a review from a team as a code owner March 20, 2024 01:43
@netlify
Copy link

netlify bot commented Mar 20, 2024

👷 Deploy request for apollo-federation-docs pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 60484d4

@apollo-cla
Copy link

@duckki: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/

@changeset-bot
Copy link

changeset-bot bot commented Mar 20, 2024

⚠️ No Changeset found

Latest commit: 60484d4

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

@codesandbox-ci
Copy link

codesandbox-ci bot commented Mar 20, 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
Member

@dariuszkuc dariuszkuc left a comment

Choose a reason for hiding this comment

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

This does not account for nested selection sets, ie foo { bar { baz } } (which still should be used. TLDR should this be recursive call (maybe function should also return its length?).

// to be common is when the subset ends up being just `__typename`: this would basically mean the fragment
// don't really apply to the subgraph, and that this will ensure this is the case.
private selectionSetIsWorthUsing(selectionSet: SelectionSet): boolean {
static selectionSetIsWorthUsing(selectionSet: SelectionSet): boolean {
Copy link
Member

Choose a reason for hiding this comment

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

can we move it to a top level function instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me see. Do you have a suggestion where to put it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can place it just above the export class NamedFragmentDefinition ... line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just pushed an update.

  • I moved the function below the class SelectionSet, since it's about that class.
  • I changed the name to selectionSetIsWorthReusing so it makes more sense outside its original context.

@dariuszkuc dariuszkuc merged commit 8dd5c08 into apollographql:main Mar 20, 2024
@duckki duckki deleted the duckki/generate-query-fagments-min-size branch March 26, 2024 18:28
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.

4 participants