Skip to content

feat(gateway): Remove internal dep on schema from composition #278

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

Merged
merged 12 commits into from
Jan 7, 2021

Conversation

trevor-scheer
Copy link
Contributor

@trevor-scheer trevor-scheer commented Nov 11, 2020

In an effort to more fully embrace CSDL within the Apollo ecosystem, this PR expands the Gateway's API to consume CSDL.

Currently, the query planner already depends on CSDL as input. This covers the majority of the Gateway's schema needs. All that remains is an internal dependency on a GraphQLSchema coming from composition.

It's fairly trivial to generate a GraphQLSchema from the CSDL itself, which unlocks the ability to provide CSDL directly to the gateway as input. This means that we can provide CSDL as configuration directly, or in the case of managed federation, host CSDL and significantly simplify the startup process of a managed gateway.

This change does introduce the ability to provide CSDL directly to the Gateway, however the remaining bits are strictly changes to internal details. With this change in place, our infra team can ship the work required to host CSDL which we can in turn depend on and simplify our waterfall of fetches and composition.

@trevor-scheer trevor-scheer force-pushed the trevor/use-csdl-internally branch from 89c7ed9 to 5e77db9 Compare December 3, 2020 20:38
@trevor-scheer trevor-scheer marked this pull request as ready for review December 3, 2020 20:39
@trevor-scheer trevor-scheer force-pushed the trevor/use-csdl-internally branch from 9ed1d16 to 2d61e3e Compare December 16, 2020 16:26
Copy link
Member

@abernix abernix left a comment

Choose a reason for hiding this comment

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

There's a package-lock.json change that seems unexpected, but presuming you back that out or if I'm missing something, and with the addition of a CHANGELOG.md, then LGTM.

(Squash in the end?)

This commit cuts the gateway over to relying solely on
the `composedSdl` output from composition. This unlocks
the ability for either a user or Apollo Studio to serve
the gateway CSDL instead of each SDL file per service.

This is fairly straightforward, as `schema` was only
depended on in one place by query plan execution, during
the final pass of graphql-js `execute()`. Instead, we now
construct a `GraphQLSchema` ourselves from the CSDL. This
comes with a caveat: the schema we're creating doesn't have
all of the annotations that once existed in the schema that
we were using from `composeAndValidate()`. However, this is
inconsequential for the way the schema is currently being
used during the final execution pass.
@trevor-scheer trevor-scheer force-pushed the trevor/use-csdl-internally branch from 2d61e3e to d2d7878 Compare January 5, 2021 19:23
@trevor-scheer trevor-scheer force-pushed the trevor/use-csdl-internally branch from d2d7878 to d8aeb2a Compare January 5, 2021 21:48
@trevor-scheer trevor-scheer changed the title feat(gateway): Remove internal dependency on schema from composition feat(gateway): Remove internal dep on schema from composition Jan 7, 2021
@trevor-scheer trevor-scheer merged commit d2e3490 into main Jan 7, 2021
@trevor-scheer trevor-scheer deleted the trevor/use-csdl-internally branch January 7, 2021 18:35
abernix added a commit that referenced this pull request Feb 23, 2021
… in Rust.

Note: The names and final form of this is subject to change after this lands.
None of the changes introduced in this commit are meant to be acted on by
users today.

This commit:

- Introduces a `harmonizer` Rust crate which composes schemas using the
  existing JavaScript/TypeScript composition function and returns a string
  representation of the composed schema -- tentatively, known as "CSDL"
  (composed schema definition language).  The name "CSDL" is subject to change.

  Today, CSDL is already an internal implementation detail which acts as a
  format that we could pass between the TypeScript runtime and the query
  planner, which is written in Rust.  By providing the mechanism to produce
  a static CSDL artifact, the gateway can be absolved from the responsibility
  to create this artifact in an opaque manner at runtime.  The ability to
  pass CSDL into a Gateway as configuration has been possible ever since
  the landing of #278,
  though until this commit, there hasn't been a way to produce it.

  As an implementation detail of the `harmonizer` library, this is
  accomplished by invoking a [Rollup.js]-bundled [IIFE] of the
  `@apollo/federation` package, in V8, via the [`deno_core`] V8 bindings.
  The IIFE JavaScript bundle itself is generated by bundling a (small) stub,
  native ECMAScript module that depends on `@apollo/federation` and calls its
  `composeAndValidate` function.  The Rollup.js build is invoked via a Rust
  `build.rs` script ([Build Scripts]).

  While the intention exists on the team to offer composition and validation
  written in native Rust, this intermediary is a short-cut that allows us to
  use the well-tested TypeScript logic that powers Federation today to achieve
  an immediate "win" without blocking other work while we move toward that
  future.

- Introduces a `harmonizer-cli` that invokes the `harmonize` lib.  Again,
  this will not be the (sole, at least) long-term home for where the
  production of this artifact will take place.  Today, it acts as an easy tool
  for those interfacing with this project.

[Rollup.js]: http://rollupjs.org/
[IIFE]: Instantly Invoked Function Expression
[`deno_core`]: https://crates.io/crates/deno_core
[Build Scripts]: https://doc.rust-lang.org/cargo/reference/build-scripts.html

Co-authored-by: Ashi Krishnan <[email protected]>
abernix added a commit that referenced this pull request Mar 2, 2021
… in Rust.

Note: The names and final form of this is subject to change after this lands.
None of the changes introduced in this commit are meant to be acted on by
users today.

This commit:

- Introduces a `harmonizer` Rust crate which composes schemas using the
  existing JavaScript/TypeScript composition function and returns a string
  representation of the composed schema -- tentatively, known as "CSDL"
  (composed schema definition language).  The name "CSDL" is subject to change.

  Today, CSDL is already an internal implementation detail which acts as a
  format that we could pass between the TypeScript runtime and the query
  planner, which is written in Rust.  By providing the mechanism to produce
  a static CSDL artifact, the gateway can be absolved from the responsibility
  to create this artifact in an opaque manner at runtime.  The ability to
  pass CSDL into a Gateway as configuration has been possible ever since
  the landing of #278,
  though until this commit, there hasn't been a way to produce it.

  As an implementation detail of the `harmonizer` library, this is
  accomplished by invoking a [Rollup.js]-bundled [IIFE] of the
  `@apollo/federation` package, in V8, via the [`deno_core`] V8 bindings.
  The IIFE JavaScript bundle itself is generated by bundling a (small) stub,
  native ECMAScript module that depends on `@apollo/federation` and calls its
  `composeAndValidate` function.  The Rollup.js build is invoked via a Rust
  `build.rs` script ([Build Scripts]).

  While the intention exists on the team to offer composition and validation
  written in native Rust, this intermediary is a short-cut that allows us to
  use the well-tested TypeScript logic that powers Federation today to achieve
  an immediate "win" without blocking other work while we move toward that
  future.

- Introduces a `harmonizer-cli` that invokes the `harmonize` lib.  Again,
  this will not be the (sole, at least) long-term home for where the
  production of this artifact will take place.  Today, it acts as an easy tool
  for those interfacing with this project.

- Sets up and installs Node.js and npm - which are required to build and
  test this Rust implementation - in our Rust GitHub Actions runs.
  This builds on the work in:
    #480

[Rollup.js]: http://rollupjs.org/
[IIFE]: Instantly Invoked Function Expression
[`deno_core`]: https://crates.io/crates/deno_core
[Build Scripts]: https://doc.rust-lang.org/cargo/reference/build-scripts.html

Co-authored-by: Ashi Krishnan <[email protected]>
abernix added a commit that referenced this pull request Mar 5, 2021
… in Rust.

Note: The names and final form of this is subject to change after this lands.
None of the changes introduced in this commit are meant to be acted on by
users today.

This commit:

- Introduces a `harmonizer` Rust crate which composes schemas using the
  existing JavaScript/TypeScript composition function and returns a string
  representation of the composed schema -- tentatively, known as "CSDL"
  (composed schema definition language).  The name "CSDL" is subject to change.

  Today, CSDL is already an internal implementation detail which acts as a
  format that we could pass between the TypeScript runtime and the query
  planner, which is written in Rust.  By providing the mechanism to produce
  a static CSDL artifact, the gateway can be absolved from the responsibility
  to create this artifact in an opaque manner at runtime.  The ability to
  pass CSDL into a Gateway as configuration has been possible ever since
  the landing of #278,
  though until this commit, there hasn't been a way to produce it.

  As an implementation detail of the `harmonizer` library, this is
  accomplished by invoking a [Rollup.js]-bundled [IIFE] of the
  `@apollo/federation` package, in V8, via the [`deno_core`] V8 bindings.
  The IIFE JavaScript bundle itself is generated by bundling a (small) stub,
  native ECMAScript module that depends on `@apollo/federation` and calls its
  `composeAndValidate` function.  The Rollup.js build is invoked via a Rust
  `build.rs` script ([Build Scripts]).

  While the intention exists on the team to offer composition and validation
  written in native Rust, this intermediary is a short-cut that allows us to
  use the well-tested TypeScript logic that powers Federation today to achieve
  an immediate "win" without blocking other work while we move toward that
  future.

- Introduces a `harmonizer-cli` that invokes the `harmonize` lib.  Again,
  this will not be the (sole, at least) long-term home for where the
  production of this artifact will take place.  Today, it acts as an easy tool
  for those interfacing with this project.

- Sets up and installs Node.js and npm - which are required to build and
  test this Rust implementation - in our Rust GitHub Actions runs.
  This builds on the work in:
    #480

[Rollup.js]: http://rollupjs.org/
[IIFE]: Instantly Invoked Function Expression
[`deno_core`]: https://crates.io/crates/deno_core
[Build Scripts]: https://doc.rust-lang.org/cargo/reference/build-scripts.html

Co-authored-by: Ashi Krishnan <[email protected]>
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