Skip to content
This repository was archived by the owner on May 3, 2024. It is now read-only.

Commit 4e422fa

Browse files
committed
WIP
1 parent fd4fb0e commit 4e422fa

File tree

8 files changed

+1346
-65
lines changed

8 files changed

+1346
-65
lines changed

src/link/argument.rs

+19
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::error::{FederationError, SingleFederationError};
2+
use crate::link::graphql_definition::BooleanOrVariable;
23
use apollo_compiler::ast::Value;
34
use apollo_compiler::schema::{Directive, Name};
45
use apollo_compiler::{Node, NodeStr};
@@ -141,3 +142,21 @@ pub(crate) fn directive_required_boolean_argument(
141142
.into()
142143
})
143144
}
145+
146+
pub(crate) fn directive_optional_variable_boolean_argument(
147+
application: &Node<Directive>,
148+
name: &Name,
149+
) -> Result<Option<BooleanOrVariable>, FederationError> {
150+
match application.argument_by_name(name) {
151+
Some(value) => match value.deref() {
152+
Value::Variable(name) => Ok(Some(BooleanOrVariable::Variable(name.clone()))),
153+
Value::Boolean(value) => Ok(Some(BooleanOrVariable::Boolean(*value))),
154+
Value::Null => Ok(None),
155+
_ => Err(FederationError::internal(format!(
156+
"Argument \"{}\" of directive \"@{}\" must be a boolean.",
157+
name, application.name
158+
))),
159+
},
160+
None => Ok(None),
161+
}
162+
}

src/link/graphql_definition.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
1-
use apollo_compiler::executable::Name;
2-
use apollo_compiler::NodeStr;
1+
use crate::error::FederationError;
2+
use crate::link::argument::{
3+
directive_optional_string_argument, directive_optional_variable_boolean_argument,
4+
};
5+
use apollo_compiler::executable::{Directive, Name};
6+
use apollo_compiler::{name, Node, NodeStr};
37

48
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
59
pub(crate) struct DeferDirectiveArguments {
610
label: Option<NodeStr>,
711
if_: Option<BooleanOrVariable>,
812
}
913

14+
pub(crate) fn defer_directive_arguments(
15+
application: &Node<Directive>,
16+
) -> Result<DeferDirectiveArguments, FederationError> {
17+
Ok(DeferDirectiveArguments {
18+
label: directive_optional_string_argument(application, &name!("label"))?,
19+
if_: directive_optional_variable_boolean_argument(application, &name!("if"))?,
20+
})
21+
}
22+
1023
/// This struct is meant for recording the original structure/intent of `@skip`/`@include`
1124
/// applications within the elements of a `GraphPath`. Accordingly, the order of them matters within
1225
/// a `Vec`, and superfluous struct instances aren't elided; `Conditions` is the more appropriate

src/query_graph/condition_resolver.rs

+40-13
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,68 @@
1+
use crate::error::FederationError;
12
use crate::query_graph::graph_path::{
23
ExcludedConditions, ExcludedDestinations, OpGraphPathContext,
34
};
45
use crate::query_graph::path_tree::OpPathTree;
56
use crate::query_plan::QueryPlanCost;
67
use petgraph::graph::EdgeIndex;
8+
use std::sync::Arc;
79

810
/// Note that `ConditionResolver`s are guaranteed to be only called for edge with conditions.
911
pub(crate) trait ConditionResolver {
1012
fn resolve(
13+
&mut self,
1114
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>;
1619
}
1720

21+
// TODO: This could probably be refactored into an enum.
22+
#[derive(Debug, Clone)]
1823
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>,
2429
}
2530

31+
#[derive(Debug, Clone)]
2632
pub(crate) enum UnsatisfiedConditionReason {
2733
NoPostRequireKey,
2834
}
2935

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+
3056
pub(crate) struct CachingConditionResolver;
3157

3258
impl ConditionResolver for CachingConditionResolver {
3359
fn resolve(
60+
&mut self,
3461
_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> {
3966
todo!()
4067
}
4168
}

0 commit comments

Comments
 (0)