|
| 1 | +use crate::error::FederationError; |
1 | 2 | use crate::query_graph::graph_path::{
|
2 | 3 | ExcludedConditions, ExcludedDestinations, OpGraphPathContext,
|
3 | 4 | };
|
4 | 5 | use crate::query_graph::path_tree::OpPathTree;
|
5 | 6 | use crate::query_plan::QueryPlanCost;
|
6 | 7 | use petgraph::graph::EdgeIndex;
|
| 8 | +use std::sync::Arc; |
7 | 9 |
|
8 | 10 | /// Note that `ConditionResolver`s are guaranteed to be only called for edge with conditions.
|
9 | 11 | pub(crate) trait ConditionResolver {
|
10 | 12 | fn resolve(
|
| 13 | + &mut self, |
11 | 14 | edge: EdgeIndex,
|
12 |
| - context: OpGraphPathContext, |
13 |
| - excluded_destinations: ExcludedDestinations, |
14 |
| - excluded_conditions: ExcludedConditions, |
15 |
| - ) -> ConditionResolution; |
| 15 | + context: &OpGraphPathContext, |
| 16 | + excluded_destinations: &ExcludedDestinations, |
| 17 | + excluded_conditions: &ExcludedConditions, |
| 18 | + ) -> Result<ConditionResolution, FederationError>; |
16 | 19 | }
|
17 | 20 |
|
| 21 | +// TODO: This could probably be refactored into an enum. |
| 22 | +#[derive(Debug, Clone)] |
18 | 23 | pub(crate) struct ConditionResolution {
|
19 |
| - satisfied: bool, |
20 |
| - cost: QueryPlanCost, |
21 |
| - path_tree: Option<OpPathTree>, |
22 |
| - // Note that this is not guaranteed to be set even if satistied === false. |
23 |
| - unsatisfied_condition_reason: Option<UnsatisfiedConditionReason>, |
| 24 | + pub(crate) satisfied: bool, |
| 25 | + pub(crate) cost: QueryPlanCost, |
| 26 | + pub(crate) path_tree: Option<Arc<OpPathTree>>, |
| 27 | + // Note that this is not guaranteed to be set even if satisfied is false. |
| 28 | + pub(crate) unsatisfied_condition_reason: Option<UnsatisfiedConditionReason>, |
24 | 29 | }
|
25 | 30 |
|
| 31 | +#[derive(Debug, Clone)] |
26 | 32 | pub(crate) enum UnsatisfiedConditionReason {
|
27 | 33 | NoPostRequireKey,
|
28 | 34 | }
|
29 | 35 |
|
| 36 | +impl ConditionResolution { |
| 37 | + pub(crate) fn no_conditions() -> Self { |
| 38 | + Self { |
| 39 | + satisfied: true, |
| 40 | + cost: 0, |
| 41 | + path_tree: None, |
| 42 | + unsatisfied_condition_reason: None, |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + pub(crate) fn unsatisfied_conditions() -> Self { |
| 47 | + Self { |
| 48 | + satisfied: false, |
| 49 | + cost: -1, |
| 50 | + path_tree: None, |
| 51 | + unsatisfied_condition_reason: None, |
| 52 | + } |
| 53 | + } |
| 54 | +} |
| 55 | + |
30 | 56 | pub(crate) struct CachingConditionResolver;
|
31 | 57 |
|
32 | 58 | impl ConditionResolver for CachingConditionResolver {
|
33 | 59 | fn resolve(
|
| 60 | + &mut self, |
34 | 61 | _edge: EdgeIndex,
|
35 |
| - _context: OpGraphPathContext, |
36 |
| - _excluded_destinations: ExcludedDestinations, |
37 |
| - _excluded_conditions: ExcludedConditions, |
38 |
| - ) -> ConditionResolution { |
| 62 | + _context: &OpGraphPathContext, |
| 63 | + _excluded_destinations: &ExcludedDestinations, |
| 64 | + _excluded_conditions: &ExcludedConditions, |
| 65 | + ) -> Result<ConditionResolution, FederationError> { |
39 | 66 | todo!()
|
40 | 67 | }
|
41 | 68 | }
|
0 commit comments