Skip to content

Commit 926cbb7

Browse files
Update possiblePlans() to use BigInt (#3128)
1 parent 6b52c60 commit 926cbb7

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

.changeset/smart-needles-breathe.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@apollo/query-planner": patch
3+
---
4+
5+
Switched plan count from `Number` to a `BigInt`.

query-planner-js/src/buildPlan.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ class QueryPlanningTraversal<RV extends Vertex> {
665665
const maxPlansToCompute = this.parameters.config.debug.maxEvaluatedPlans;
666666
while (planCount > maxPlansToCompute && firstBranch.length > 1) {
667667
// we remove the right-most option of the first branch, and them move that branch to it's new place.
668-
const prevSize = firstBranch.length;
668+
const prevSize = BigInt(firstBranch.length);
669669
firstBranch.pop();
670670
planCount -= planCount / prevSize;
671671
this.reorderFirstBranch();
@@ -678,7 +678,7 @@ class QueryPlanningTraversal<RV extends Vertex> {
678678
// Note that if `!this.isTopLevel`, then this means we're resolving a sub-plan for an edge condition, and we
679679
// don't want to count those as "evaluated plans".
680680
if (this.parameters.statistics && this.isTopLevel) {
681-
this.parameters.statistics.evaluatedPlanCount += planCount;
681+
this.parameters.statistics.evaluatedPlanCount += Number(planCount);
682682
}
683683

684684
debug.log(() => `All branches:${this.closedBranches.map((opts, i) => `\n${i}:${opts.map((opt => `\n - ${closedPathToString(opt)}`))}`)}`);
@@ -3596,16 +3596,16 @@ function mapOptionsToSelections<RV extends Vertex>(
35963596
return selectionSet.selectionsInReverseOrder().map(node => [node, options]);
35973597
}
35983598

3599-
function possiblePlans(closedBranches: ClosedBranch<any>[]): number {
3600-
let totalCombinations = 1;
3599+
function possiblePlans(closedBranches: ClosedBranch<any>[]): bigint {
3600+
let totalCombinations = BigInt(1);
36013601
for (let i = 0; i < closedBranches.length; ++i){
3602-
const eltSize = closedBranches[i].length;
3603-
if (eltSize === 0) {
3602+
const eltSize = BigInt(closedBranches[i].length);
3603+
if (eltSize === BigInt(0)) {
36043604
// This would correspond to not being to find *any* path for a particular queried field, which means we have no plan
36053605
// for the overall query. Now, this shouldn't happen in practice if composition validation has been run successfully
36063606
// (and is not buggy), since the goal of composition validation is exactly to ensure we can never run into this path.
36073607
// In any case, we will throw later if that happens, but let's just return the proper result here, which is no plan at all.
3608-
return 0;
3608+
return BigInt(0);
36093609
}
36103610
totalCombinations *= eltSize;
36113611
}

0 commit comments

Comments
 (0)