From 2a6747612beab0f8f035ae1a0acb9dde4504479c Mon Sep 17 00:00:00 2001 From: Audun Halland Date: Tue, 24 Oct 2023 02:37:56 +0200 Subject: [PATCH] feat: Add a method to LookAheadMethods to get the unaliased field name --- juniper/src/executor/look_ahead.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/juniper/src/executor/look_ahead.rs b/juniper/src/executor/look_ahead.rs index 54643db7c..7e507f802 100644 --- a/juniper/src/executor/look_ahead.rs +++ b/juniper/src/executor/look_ahead.rs @@ -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. @@ -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) } @@ -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) }