Skip to content

Commit

Permalink
feat: Add a method to LookAheadMethods to get the unaliased field name
Browse files Browse the repository at this point in the history
  • Loading branch information
audunhalland committed Nov 9, 2023
1 parent d0fc062 commit 2a67476
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions juniper/src/executor/look_ahead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,11 @@ pub trait LookAheadMethods<'sel, S> {
/// Returns the (potentially aliased) name of the field, represented by the current selection.
fn field_name(&self) -> &'sel str;

/// Returns the child selection for the specified field.
///
/// If a child has an alias, it will only match if the alias matches the specified `name`.
/// Get the unaliased name of the field represented by the current selection
fn field_name_unaliased(&self) -> &'sel str;

/// Get the the child selection for a given field
/// If a child has an alias, it will only match if the alias matches `name`
fn select_child(&self, name: &str) -> Option<&Self>;

/// Checks if a child selection with the specified `name` exists.
Expand Down Expand Up @@ -393,6 +395,10 @@ impl<'a, S> LookAheadMethods<'a, S> for ConcreteLookAheadSelection<'a, S> {
self.alias.unwrap_or(self.name)
}

fn field_name_unaliased(&self) -> &'a str {
self.name
}

fn select_child(&self, name: &str) -> Option<&Self> {
self.children.iter().find(|c| c.field_name() == name)
}
Expand Down Expand Up @@ -438,6 +444,10 @@ impl<'a, S> LookAheadMethods<'a, S> for LookAheadSelection<'a, S> {
self.alias.unwrap_or(self.name)
}

fn field_name_unaliased(&self) -> &'a str {
self.name
}

fn select_child(&self, name: &str) -> Option<&Self> {
self.children.iter().find(|c| c.field_name() == name)
}
Expand Down

0 comments on commit 2a67476

Please sign in to comment.