graphql_composition/
result.rs

1use graphql_federated_graph::FederatedGraph;
2
3use crate::Diagnostics;
4
5/// The result of a [`compose()`](crate::compose()) invocation.
6pub struct CompositionResult {
7    pub(crate) federated_graph: Option<FederatedGraph>,
8    pub(crate) diagnostics: Diagnostics,
9}
10
11impl CompositionResult {
12    /// Simplify the result data to a yes-no answer: did composition succeed?
13    ///
14    /// `Ok()` contains the [FederatedGraph].
15    /// `Err()` contains all [Diagnostics].
16    pub fn into_result(self) -> Result<FederatedGraph, Diagnostics> {
17        if let Some(federated_graph) = self.federated_graph {
18            Ok(federated_graph)
19        } else {
20            // means a fatal error occured
21            Err(self.diagnostics)
22        }
23    }
24
25    /// Composition warnings and errors.
26    pub fn diagnostics(&self) -> &Diagnostics {
27        &self.diagnostics
28    }
29}