HybridComposition

Trait HybridComposition 

Source
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§

Source

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})

Source

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.

Source

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).

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§

Source

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
  1. Run Rust-based validation on the subgraphs
  2. Call [compose_services_without_satisfiability] to run JavaScript-based composition
  3. Run Rust-based validation on the supergraph
  4. Call validate_satisfiability to run JavaScript-based validation on the supergraph
Source

async fn experimental_compose( self, subgraph_definitions: Vec<SubgraphDefinition>, ) -> Result<PluginResult, Vec<Issue>>
where Self: Sized,

*** EXPERIMENTAL ***

Runs the composition process with granular composition phases that allow replacing individual steps with Rust and/or JavaScript implementations.

  1. subgraph validation
  2. Initialize subgraphs - parses SDL into a GraphQL schema
  3. Expands subgraphs - adds all missing federation definitions
  4. Upgrade subgraphs - upgrades fed v1 schemas to fed v2
  5. Validate subgraphs
  6. Pre-merge validations (includes connectors validations)
  7. Merge subgraphs into a supergrpah
  8. Post merge validations
  9. expand supergraph
  10. Validate satisfiability

In case of a composition failure, we return a list of errors from the current composition phase.

Source

async fn experimental_upgrade_subgraphs( &mut self, subgraphs: Vec<SubgraphDefinition>, ) -> Result<Vec<SubgraphDefinition>, Vec<Issue>>

Maps to buildSubgraph & upgradeSubgraphsIfNecessary and performs following steps

  1. Parses raw SDL schemas into Subgraph
  2. Adds missing federation definitions to the subgraph schemas
  3. Upgrades federation v1 subgraphs to federation v2 schemas. This is a no-op if it is already a federation v2 subgraph.
  4. Validates the expanded/upgraded subgraph schemas.
Source

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.

Source

async fn experimental_validate_satisfiability( &mut self, supergraph_sdl: &str, ) -> Result<Vec<Issue>, Vec<Issue>>

If successful, returns a list of hints (possibly empty); Otherwise, 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.

Implementors§