pub trait HybridComposition {
// Required methods
async fn compose_services_without_satisfiability(
&mut self,
subgraph_definitions: Vec<SubgraphDefinition>,
) -> Option<SupergraphSdl<'_>>;
async fn validate_satisfiability(
&mut self,
) -> Result<Vec<Issue>, Vec<Issue>>;
fn update_supergraph_sdl(&mut self, supergraph_sdl: String);
fn add_issues<Source: Iterator<Item = Issue>>(&mut self, issues: Source);
// Provided methods
async fn compose(&mut self, subgraph_definitions: Vec<SubgraphDefinition>) { ... }
async fn experimental_compose(
self,
subgraph_definitions: Vec<SubgraphDefinition>,
) -> Result<PluginResult, Vec<Issue>>
where Self: Sized { ... }
async fn experimental_upgrade_subgraphs(
&mut self,
subgraphs: Vec<SubgraphDefinition>,
) -> Result<Vec<SubgraphDefinition>, Vec<Issue>> { ... }
async fn experimental_merge_subgraphs(
&mut self,
subgraphs: Vec<SubgraphDefinition>,
) -> Result<MergeResult, Vec<Issue>> { ... }
async fn experimental_validate_satisfiability(
&mut self,
supergraph_sdl: &str,
) -> Result<Vec<Issue>, Vec<Issue>> { ... }
}Expand description
This trait includes all the Rust-side composition logic, plus hooks for the JavaScript side.
If you implement the functions in this trait to build your own JavaScript interface, then you
can call HybridComposition::compose to run the complete composition process.
JavaScript should be implemented using @apollo/composition@2.9.0-connectors.0.
Required Methods§
Sourceasync fn compose_services_without_satisfiability(
&mut self,
subgraph_definitions: Vec<SubgraphDefinition>,
) -> Option<SupergraphSdl<'_>>
async fn compose_services_without_satisfiability( &mut self, subgraph_definitions: Vec<SubgraphDefinition>, ) -> Option<SupergraphSdl<'_>>
Call the JavaScript composeServices function from @apollo/composition plus whatever
extra logic you need. Make sure to disable satisfiability, like composeServices(definitions, {runSatisfiability: false})
Sourceasync fn validate_satisfiability(&mut self) -> Result<Vec<Issue>, Vec<Issue>>
async fn validate_satisfiability(&mut self) -> Result<Vec<Issue>, Vec<Issue>>
Call the JavaScript validateSatisfiability function from @apollo/composition plus whatever
extra logic you need.
§Input
The validateSatisfiability function wants an argument like { supergraphSdl }. That field
should be the value that’s updated when [update_supergraph_sdl] is called.
§Output
If satisfiability completes from JavaScript, either a list of hints (could be empty, the Ok case) or a list
of errors (never empty, the Err case) will be returned. If Satisfiability can’t be run, you can return a single error
(Err(vec![Issue])) indicating what went wrong.
Sourcefn update_supergraph_sdl(&mut self, supergraph_sdl: String)
fn update_supergraph_sdl(&mut self, supergraph_sdl: String)
Allows the Rust composition code to modify the stored supergraph SDL (for example, to expand connectors).
Sourcefn add_issues<Source: Iterator<Item = Issue>>(&mut self, issues: Source)
fn add_issues<Source: Iterator<Item = Issue>>(&mut self, issues: Source)
When the Rust composition/validation code finds issues, it will call this method to add them to the list of issues that will be returned to the user.
It’s on the implementor of this trait to convert From<Issue>
Provided Methods§
Sourceasync fn compose(&mut self, subgraph_definitions: Vec<SubgraphDefinition>)
async fn compose(&mut self, subgraph_definitions: Vec<SubgraphDefinition>)
Runs the complete composition process, hooking into both the Rust and JavaScript implementations.
§Asyncness
While this function is async to allow for flexible JavaScript execution, it is a CPU-heavy task. Take care when consuming this in an async context, as it may block longer than desired.
§Algorithm
- Run Rust-based validation on the subgraphs
- Call [
compose_services_without_satisfiability] to run JavaScript-based composition - Run Rust-based validation on the supergraph
- Call
validate_satisfiabilityto run JavaScript-based validation on the supergraph
Sourceasync fn experimental_compose(
self,
subgraph_definitions: Vec<SubgraphDefinition>,
) -> Result<PluginResult, Vec<Issue>>where
Self: Sized,
async fn experimental_compose(
self,
subgraph_definitions: Vec<SubgraphDefinition>,
) -> Result<PluginResult, Vec<Issue>>where
Self: Sized,
Runs the composition process with granular composition phases that allow replacing individual steps with Rust and/or JavaScript implementations.
subgraph validation - Initialize subgraphs - parses SDL into a GraphQL schema
- Expands subgraphs - adds all missing federation definitions
- Upgrade subgraphs - upgrades fed v1 schemas to fed v2
- Validate subgraphs
- Pre-merge validations (includes connectors validations)
- Merge subgraphs into a supergrpah
- Post merge validations
expand supergraph - Validate satisfiability
In case of a composition failure, we return a list of errors from the current composition phase.
Sourceasync fn experimental_upgrade_subgraphs(
&mut self,
subgraphs: Vec<SubgraphDefinition>,
) -> Result<Vec<SubgraphDefinition>, Vec<Issue>>
async fn experimental_upgrade_subgraphs( &mut self, subgraphs: Vec<SubgraphDefinition>, ) -> Result<Vec<SubgraphDefinition>, Vec<Issue>>
Maps to buildSubgraph & upgradeSubgraphsIfNecessary and performs following steps
- Parses raw SDL schemas into Subgraph
- Adds missing federation definitions to the subgraph schemas
- Upgrades federation v1 subgraphs to federation v2 schemas. This is a no-op if it is already a federation v2 subgraph.
- Validates the expanded/upgraded subgraph schemas.
Sourceasync fn experimental_merge_subgraphs(
&mut self,
subgraphs: Vec<SubgraphDefinition>,
) -> Result<MergeResult, Vec<Issue>>
async fn experimental_merge_subgraphs( &mut self, subgraphs: Vec<SubgraphDefinition>, ) -> Result<MergeResult, Vec<Issue>>
In case of a merge failure, returns a list of errors.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.