fix: updated generateQueryFragments option to only generate fragments at least 2 selections#2962
Conversation
…ts at least 2 selections - follow-up of apollographql#2958
👷 Deploy request for apollo-federation-docs pending review.Visit the deploys page to approve it
|
|
@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/ |
|
|
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. |
internals-js/src/operations.ts
Outdated
| // 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 { |
There was a problem hiding this comment.
can we move it to a top level function instead?
There was a problem hiding this comment.
Let me see. Do you have a suggestion where to put it?
There was a problem hiding this comment.
I can place it just above the export class NamedFragmentDefinition ... line.
There was a problem hiding this comment.
I just pushed an update.
- I moved the function below the
class SelectionSet, since it's about that class. - I changed the name to
selectionSetIsWorthReusingso it makes more sense outside its original context.
- renamed it to `selectionSetIsWorthReusing`
This is a follow-up of #2958.
I've changed
SelectionSet.minimizeSelectionSetto create a new fragment only when the selection set has at least 2 items.This behavior is inspired by the behavior of
reuseQueryFragmentsoption. However, I wasn't sure whether re-using theNamedFragments.selectionSetIsWorthUsingfunction here is right or not. So, I didn't reuse it.