graphql_composition/
result.rs

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