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

Adds debug query planner option to skip query planning for a single s… #2441

Merged
merged 1 commit into from
Mar 8, 2023

Conversation

pcmanus
Copy link
Contributor

@pcmanus pcmanus commented Mar 7, 2023

…ubgraph

This commit adds a new option to the query planner config that, when used and when the supergraph is built from only a single subgraph, skip the query planning algorithm and instead generates a single fetch (to the one subgraph) that directly uses the gateway "input" query.

This option is disabled by default and marked as a "debug" option as it is a bit of a hack and so we're not suggesting committing to supporting it forever. But it is easy enough to have now and can be convenient at least for testing/debugging.

Note in particular that, when used, some of the features enabled by the query planner (for instance @defer) cannot be enabled. The option will also stop having any effect as soon as another subgraph is added, not matter what that 2nd subgraph contains.

@changeset-bot
Copy link

changeset-bot bot commented Mar 7, 2023

🦋 Changeset detected

Latest commit: 9e0653d

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

This PR includes changesets to release 7 packages
Name Type
@apollo/query-planner Minor
@apollo/gateway Minor
@apollo/federation-internals Minor
@apollo/composition Minor
@apollo/query-graphs Minor
@apollo/subgraph Minor
apollo-federation-integration-testsuite Minor

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

@codesandbox-ci
Copy link

codesandbox-ci bot commented Mar 7, 2023

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.

@netlify
Copy link

netlify bot commented Mar 7, 2023

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

Visit the deploys page to approve it

Name Link
🔨 Latest commit a1d19b5

@pcmanus pcmanus force-pushed the skip-qp-on-single-subgraph branch 5 times, most recently from 78ab228 to a1d19b5 Compare March 7, 2023 16:43
@pcmanus pcmanus changed the base branch from main to next March 7, 2023 16:43
@pcmanus pcmanus force-pushed the skip-qp-on-single-subgraph branch from a1d19b5 to 9e34f2a Compare March 7, 2023 17:33
// A federated query graph always have 1 more sources than there is subgraph, because the root vertices
// belong to no subgraphs and use a special source named '_'. So we skip that "fake" source.
const subgraphs = mapKeys(this.federatedQueryGraph.sources).filter((name) => name !== FEDERATED_GRAPH_ROOT_SOURCE);
if (subgraphs.length === 1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you want the else case to error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No. I think the config name and documentation makes it clear that it only applies to single subgraphs, and it's clearly flagged as for debug/testing so I'm not really worried about someone not understanding why they don't get what they want out of this. On the flip side, erroring could make it more annoying to use as you'd have to remember to disable the option when you go from 1 to 2 subgraph, or get a runtime crash. Admittedly this is all a bit subjective since again, it is clearly flagged for debug/testing, but I personally markedly prefer it not having a else.

Copy link
Contributor

@clenfest clenfest left a comment

Choose a reason for hiding this comment

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

A couple of asks, but otherwise LGTM.

…ubgraph

This commit adds a new option to the query planner config that, when
used and when the supergraph is built from only a single subgraph, skip
the query planning algorithm and instead generates a single fetch (to
the one subgraph) that directly uses the gateway "input" query.

This option is disabled by default and marked as a "debug" option as it
is a bit of a hack and so we're not suggesting committing to supporting
it forever. But it is easy enough to have now and can be convenient at
least for testing/debugging.

Note in particular that, when used, some of the features enabled by
the query planner (for instance `@defer`) cannot be enabled. The option
will also stop having any effect as soon as another subgraph is added,
not matter what that 2nd subgraph contains.
@pcmanus pcmanus force-pushed the skip-qp-on-single-subgraph branch from 9e34f2a to 9e0653d Compare March 8, 2023 09:43
@pcmanus pcmanus merged commit ade7ceb into apollographql:next Mar 8, 2023
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.

None yet

2 participants