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 potential QP issue with shareable root fields #2239

Merged
merged 2 commits into from
Nov 10, 2022

Conversation

pcmanus
Copy link
Contributor

@pcmanus pcmanus commented Nov 8, 2022

Slightly complex to explain, but on some example, during query planning, the query planner had to consider plans whose dependencies where essentially:

`Root Fetch 1`
                         \
                          `Dependent fetch`
                         /
`Root Fetch 2`

but the "processing" code wasn't expecting that and that triggered an assert (the patch has a unit test that, if run against pre-patch main triggers that assertion; note that the assertion is thrown during query planning, but the final query plan of that test does not look like the one above). The patch fixes this issue.

@netlify
Copy link

netlify bot commented Nov 8, 2022

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

Visit the deploys page to approve it

Name Link
🔨 Latest commit 90c9d8c

@codesandbox-ci
Copy link

codesandbox-ci bot commented Nov 8, 2022

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.

@@ -4285,3 +4370,55 @@ describe('__typename handling', () => {
`);
});
});

describe('mutations', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note to reviewer: that test is not really directly related to this patch, but I notice that buildPlan.test.ts had no simple Mutation test. Mutation were still tested elsewhere (in the plan execution tests mostly, but also in plenty of older test files) but as I often use that one test file as a shortcut for "have I broken query planning", it's convenient to have at least a simple mutation test there.

};

function parallelCost(values: number[]): number {
return sum(values);
}

function sequenceCost(stages: number[]): number {
return stages.reduceRight((acc, stage, idx) => (acc + ((idx + 1) * pipeliningCost * stage)), 0);
return stages.reduceRight((acc, stage, idx) => (acc + (Math.max(1, idx * pipeliningCost) * stage)), 0);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note to reviewer: this change is due to the fact that the code now more or less rely on the fact that calling processor.reduceSequence on a single element is essentially a no-op, and that was true for the reduceSequence that generates the actual plan, but for not the costing of the plan here. Doesn't really change the overall logic otherwise.

@pcmanus pcmanus self-assigned this Nov 8, 2022
next: toHandleNext,
unhandled: remainingNext,
deferredGroups: allDeferredGroups,
};
}

private mergeRemainings(r1: UnhandledGroups, r2: UnhandledGroups): [FetchGroup[], UnhandledGroups] {
if (r1.length === 0 && r2.length === 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this code necessary? Seems like the code would return the same value if r1 and r2 are [] if this if block didn't exist.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that was me prematurely optimising for no reason. I've removed it, it's unnecessary, sorry about the noise.

@pcmanus pcmanus merged commit 4ce4206 into apollographql:main Nov 10, 2022
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.

2 participants