From 258fda403b5319199b42bbcd61b8d7f25c2f1e3f Mon Sep 17 00:00:00 2001 From: Oliver Cooper Date: Fri, 10 Sep 2021 17:21:56 +1200 Subject: [PATCH 1/2] Get selection fields from Lookahead --- src/look_ahead.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/look_ahead.rs b/src/look_ahead.rs index 68e56637..f1b1f97c 100644 --- a/src/look_ahead.rs +++ b/src/look_ahead.rs @@ -54,6 +54,17 @@ impl<'a> Lookahead<'a> { pub fn exists(&self) -> bool { !self.fields.is_empty() } + + pub fn selection_fields(&self) -> Vec> { + self.fields + .iter() + .map(|field| SelectionField { + fragments: self.fragments, + field, + context: self.context, + }) + .collect() + } } impl<'a> From> for Lookahead<'a> { From bb74b2f46d090c4409e1e3655dada3473ee198ec Mon Sep 17 00:00:00 2001 From: Oliver Cooper Date: Tue, 28 Sep 2021 16:50:27 +1300 Subject: [PATCH 2/2] Document selection_fields --- src/look_ahead.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/look_ahead.rs b/src/look_ahead.rs index f1b1f97c..ccd874a8 100644 --- a/src/look_ahead.rs +++ b/src/look_ahead.rs @@ -55,6 +55,9 @@ impl<'a> Lookahead<'a> { !self.fields.is_empty() } + /// Get the `SelectionField`s for each of the fields covered by this `Lookahead`. + /// + /// There will be multiple fields in situations where the same field is queried twice. pub fn selection_fields(&self) -> Vec> { self.fields .iter()