Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add a method to LookAheadMethods to get the unaliased field name #1211

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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