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

Change query planner API to avoid double parsing and schema building #628

Merged
merged 4 commits into from
Apr 1, 2021

Conversation

martijnwalraven
Copy link
Contributor

We originally kept the same API we used for the wasm query planner, but that relied on passing in strings for the schema and operation. Since the query planner is now implemented in TypeScript again, we can avoid double parsing and schema building by passing in a composed schema and a parsed operation.

There are remaining inefficiencies in the gateway workflows that we'll want to address in follow-up PRs. In particular, the gateway still calls buildComposedSchema twice for every update, because it extracts the service list to perform health checks in a separate function. We also parse the supergraph SDL multiple times due to the way functions are structured. Solving this will likely require a rethinking of the way these workflows are composed, and the possible introduction of additional objects (see #580).

@martijnwalraven martijnwalraven changed the base branch from main to release-0.26.0 April 1, 2021 12:17
@martijnwalraven martijnwalraven changed the title Query planner API changes Change query planner API to avoid double parsing and schema building Apr 1, 2021
Copy link
Contributor

@pcmanus pcmanus left a comment

Choose a reason for hiding this comment

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

Afaict, this is a relatively simple cleanup and it looks good to me.

gateway-js/src/__tests__/execution-utils.ts Outdated Show resolved Hide resolved
gateway-js/src/index.ts Outdated Show resolved Hide resolved
We originally kept the same API we used for the wasm query planner, but that relied on passing in strings for the schema and operation. Since the query planner is now implemented in TypeScript again, we can avoid double parsing and schema building by passing in a composed schema and a parsed operation.
buildOperationContext(planner_ptr.composedSchema, parse(query)),
options,
);
// TODO: We should change the API to avoid confusion, because
Copy link
Member

Choose a reason for hiding this comment

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

Opened #632

Copy link
Member

@trevor-scheer trevor-scheer left a comment

Choose a reason for hiding this comment

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

LGTM!

@trevor-scheer trevor-scheer merged commit a6f293b into release-0.26.0 Apr 1, 2021
@trevor-scheer trevor-scheer deleted the martijn/query-planner-api-changes branch April 1, 2021 19:22
williamboman added a commit to williamboman/federation that referenced this pull request Apr 2, 2021
…tionHeaders

* upstream/main: (77 commits)
  Update CHANGELOGs for release
  Release
  Change query planner API to avoid double parsing and schema building (apollographql#628)
  Update documentation around delivery endpoint option (apollographql#630)
  Change `buildComposedSchema` test to check for specific directives and types
  Add `query-planner-js` to `tsconfig.test.json`
  Release
  chore(ci): Bump `cache-cargo` seed value.
  chore(ci): Remove special-case install of `gnu-tar` on `macos` GH Actions.
  chore(ci): Never try to restore the cache without the `cache-name` for npm
  chore(ci): Expand upon cache restore keys for Cargo restorations
  chore(ci): Be explicit about cache restore keys
  Release
  Update uplink usage to latest url and update query/generated types (apollographql#626)
  Release
  Update changelogs
  (optionally) REVERT ME: cachebuster
  Update the thing that TS didn't catch for me :sadface:
  Rename Endpoint -> Graph and serviceName -> graphName
  Avoid unnecessary check for undefined
  ...
williamboman added a commit to williamboman/federation that referenced this pull request Apr 2, 2021
…tionHeaders

* upstream/main: (77 commits)
  Update CHANGELOGs for release
  Release
  Change query planner API to avoid double parsing and schema building (apollographql#628)
  Update documentation around delivery endpoint option (apollographql#630)
  Change `buildComposedSchema` test to check for specific directives and types
  Add `query-planner-js` to `tsconfig.test.json`
  Release
  chore(ci): Bump `cache-cargo` seed value.
  chore(ci): Remove special-case install of `gnu-tar` on `macos` GH Actions.
  chore(ci): Never try to restore the cache without the `cache-name` for npm
  chore(ci): Expand upon cache restore keys for Cargo restorations
  chore(ci): Be explicit about cache restore keys
  Release
  Update uplink usage to latest url and update query/generated types (apollographql#626)
  Release
  Update changelogs
  (optionally) REVERT ME: cachebuster
  Update the thing that TS didn't catch for me :sadface:
  Rename Endpoint -> Graph and serviceName -> graphName
  Avoid unnecessary check for undefined
  ...
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

3 participants