Skip to content

Commit

Permalink
defer will have labels so no need to pass schema
Browse files Browse the repository at this point in the history
  • Loading branch information
dariuszkuc committed Dec 17, 2024
1 parent 77a5361 commit 6342406
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
14 changes: 3 additions & 11 deletions apollo-federation/src/operation/directive_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,19 +336,11 @@ impl DirectiveList {
Some(item)
}

/// Removes @defer directive from the self it has a matching label.
pub(crate) fn remove_defer(
&mut self,
defer_labels: &IndexSet<String>,
schema: &apollo_compiler::Schema,
) {
/// Removes @defer directive from self if it has a matching label.
pub(crate) fn remove_defer(&mut self, defer_labels: &IndexSet<String>) {
let label = self
.get(&DEFER_DIRECTIVE_NAME)
.and_then(|directive| {
directive
.argument_by_name(&DEFER_LABEL_ARGUMENT_NAME, schema)
.ok()
})
.and_then(|directive| directive.specified_argument_by_name(&DEFER_LABEL_ARGUMENT_NAME))
.and_then(|arg| arg.as_str());

if label.is_some_and(|label| defer_labels.contains(label)) {
Expand Down
14 changes: 7 additions & 7 deletions apollo-federation/src/operation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2902,6 +2902,7 @@ impl Fragment {
self.selection_set.has_defer()
}

/// Create a new fragment without @defer directive applications that have a matching label.
fn reduce_defer(
&self,
defer_labels: &IndexSet<String>,
Expand All @@ -2921,7 +2922,7 @@ impl Fragment {
}

impl NamedFragments {
/// Creates new fragment definitions with the @defer directive removed if it has a matching label.
/// Creates new fragment definitions by removing all @defer directives that had a matching label.
fn reduce_defer(&self, defer_labels: &IndexSet<String>) -> Result<Self, FederationError> {
let mut new_fragments = NamedFragments {
fragments: Default::default(),
Expand Down Expand Up @@ -2954,11 +2955,10 @@ impl FragmentSpread {
self.directives.has(&DEFER_DIRECTIVE_NAME)
}

/// Create a new fragment spread without @defer directive applications that have a matching label.
fn reduce_defer(&self, defer_labels: &IndexSet<String>) -> Result<Self, FederationError> {
let mut reduce_defer = self.clone();
reduce_defer
.directives
.remove_defer(defer_labels, reduce_defer.schema.schema());
reduce_defer.directives.remove_defer(defer_labels);
Ok(reduce_defer)
}
}
Expand All @@ -2975,11 +2975,10 @@ impl InlineFragment {
self.directives.has(&DEFER_DIRECTIVE_NAME)
}

/// Create a new inline fragment without @defer directive applications that have a matching label.
fn reduce_defer(&self, defer_labels: &IndexSet<String>) -> Result<Self, FederationError> {
let mut reduce_defer = self.clone();
reduce_defer
.directives
.remove_defer(defer_labels, reduce_defer.schema.schema());
reduce_defer.directives.remove_defer(defer_labels);
Ok(reduce_defer)
}
}
Expand Down Expand Up @@ -3075,6 +3074,7 @@ impl Selection {
}
}

/// Create a new selection without @defer directive applications that have a matching label.
fn reduce_defer(
&self,
defer_labels: &IndexSet<String>,
Expand Down

0 comments on commit 6342406

Please sign in to comment.