From 71c63049e78a272e5f6a6801fd735cd40627222c Mon Sep 17 00:00:00 2001 From: Audun Halland Date: Tue, 7 Mar 2023 00:30:32 +0100 Subject: [PATCH 1/5] feat: Include Spanning in Arguments --- juniper/src/schema/meta.rs | 6 +++--- juniper/src/schema/schema.rs | 2 +- juniper/src/schema/translate/graphql_parser.rs | 2 +- juniper/src/types/async_await.rs | 3 ++- juniper/src/types/base.rs | 13 ++++++++++--- juniper/src/types/subscriptions.rs | 3 ++- 6 files changed, 19 insertions(+), 10 deletions(-) diff --git a/juniper/src/schema/meta.rs b/juniper/src/schema/meta.rs index 04f5eda96..e2bbebc2c 100644 --- a/juniper/src/schema/meta.rs +++ b/juniper/src/schema/meta.rs @@ -12,7 +12,7 @@ use crate::{ schema::model::SchemaType, types::base::TypeKind, value::{DefaultScalarValue, ParseScalarValue}, - FieldError, + FieldError, Spanning, }; /// Whether an item is deprecated, with context. @@ -202,7 +202,7 @@ pub struct Argument<'a, S> { #[doc(hidden)] pub arg_type: Type<'a>, #[doc(hidden)] - pub default_value: Option>, + pub default_value: Option>>, } impl<'a, S> Argument<'a, S> { @@ -739,7 +739,7 @@ impl<'a, S> Argument<'a, S> { /// Overwrites any previously set default value. #[must_use] pub fn default_value(mut self, val: InputValue) -> Self { - self.default_value = Some(val); + self.default_value = Some(Spanning::unlocated(val)); self } } diff --git a/juniper/src/schema/schema.rs b/juniper/src/schema/schema.rs index 618227462..98729cae2 100644 --- a/juniper/src/schema/schema.rs +++ b/juniper/src/schema/schema.rs @@ -386,7 +386,7 @@ impl<'a, S: ScalarValue + 'a> Argument<'a, S> { #[graphql(name = "defaultValue")] fn default_value_(&self) -> Option { - self.default_value.as_ref().map(ToString::to_string) + self.default_value.as_ref().map(|v| v.item.to_string()) } } diff --git a/juniper/src/schema/translate/graphql_parser.rs b/juniper/src/schema/translate/graphql_parser.rs index 7612b610b..db8dbdc17 100644 --- a/juniper/src/schema/translate/graphql_parser.rs +++ b/juniper/src/schema/translate/graphql_parser.rs @@ -89,7 +89,7 @@ impl GraphQLParserTranslator { default_value: input .default_value .as_ref() - .map(|x| GraphQLParserTranslator::translate_value(x)), + .map(|x| GraphQLParserTranslator::translate_value(&x.item)), directives: vec![], } } diff --git a/juniper/src/types/async_await.rs b/juniper/src/types/async_await.rs index f0988cf3b..adbb8175e 100644 --- a/juniper/src/types/async_await.rs +++ b/juniper/src/types/async_await.rs @@ -244,7 +244,8 @@ where m.item .iter() .filter_map(|(k, v)| { - v.item.clone().into_const(exec_vars).map(|v| (k.item, v)) + let value = v.item.clone().into_const(exec_vars)?; + Some((k.item, Spanning::new(v.span, value))) }) .collect() }), diff --git a/juniper/src/types/base.rs b/juniper/src/types/base.rs index c99825091..fb5c37ae2 100644 --- a/juniper/src/types/base.rs +++ b/juniper/src/types/base.rs @@ -68,13 +68,13 @@ pub enum TypeKind { /// Field argument container #[derive(Debug)] pub struct Arguments<'a, S = DefaultScalarValue> { - args: Option>>, + args: Option>>>, } impl<'a, S> Arguments<'a, S> { #[doc(hidden)] pub fn new( - mut args: Option>>, + mut args: Option>>>, meta_args: &'a Option>>, ) -> Self where @@ -117,10 +117,16 @@ impl<'a, S> Arguments<'a, S> { self.args .as_ref() .and_then(|args| args.get(name)) + .map(|spanning| &spanning.item) .map(InputValue::convert) .transpose() .map_err(IntoFieldError::into_field_error) } + + /// Gets a direct reference to the spanned argument input value + pub fn get_input_value(&self, name: &str) -> Option<&Spanning>> { + self.args.as_ref().and_then(|args| args.get(name)) + } } /// Primary trait used to resolve GraphQL values. @@ -472,7 +478,8 @@ where m.item .iter() .filter_map(|(k, v)| { - v.item.clone().into_const(exec_vars).map(|v| (k.item, v)) + let value = v.item.clone().into_const(exec_vars)?; + Some((k.item, Spanning::new(v.span, value))) }) .collect() }), diff --git a/juniper/src/types/subscriptions.rs b/juniper/src/types/subscriptions.rs index 4b575c82a..11cb8c716 100644 --- a/juniper/src/types/subscriptions.rs +++ b/juniper/src/types/subscriptions.rs @@ -316,7 +316,8 @@ where m.item .iter() .filter_map(|(k, v)| { - v.item.clone().into_const(exec_vars).map(|v| (k.item, v)) + let value = v.item.clone().into_const(exec_vars)?; + Some((k.item, Spanning::new(v.span, value))) }) .collect() }), From 429cd09ddd9095ee8f4519f86b7141b32e1a7877 Mon Sep 17 00:00:00 2001 From: Audun Halland Date: Tue, 14 Mar 2023 00:57:53 +0100 Subject: [PATCH 2/5] feat: Include spanning in LookAheadArguments --- juniper/src/executor/look_ahead.rs | 124 +++++++++++++++++++++-------- juniper/src/parser/utils.rs | 14 +++- 2 files changed, 100 insertions(+), 38 deletions(-) diff --git a/juniper/src/executor/look_ahead.rs b/juniper/src/executor/look_ahead.rs index 54643db7c..9de0c8103 100644 --- a/juniper/src/executor/look_ahead.rs +++ b/juniper/src/executor/look_ahead.rs @@ -2,7 +2,7 @@ use std::collections::HashMap; use crate::{ ast::{Directive, Fragment, InputValue, Selection}, - parser::Spanning, + parser::{Span, Spanning}, value::ScalarValue, }; @@ -18,6 +18,8 @@ pub enum Applies<'a> { OnlyType(&'a str), } +type BorrowedSpanning<'a, T> = Spanning; + /// A JSON-like value that can is used as argument in the query execution /// /// In contrast to `InputValue` these values do only contain constants, @@ -28,37 +30,57 @@ pub enum LookAheadValue<'a, S: 'a> { Null, Scalar(&'a S), Enum(&'a str), - List(Vec>), - Object(Vec<(&'a str, LookAheadValue<'a, S>)>), + List(Vec>>), + Object( + Vec<( + BorrowedSpanning<'a, &'a str>, + BorrowedSpanning<'a, LookAheadValue<'a, S>>, + )>, + ), } impl<'a, S> LookAheadValue<'a, S> where S: ScalarValue, { - fn from_input_value(input_value: &'a InputValue, vars: &'a Variables) -> Self { - match *input_value { - InputValue::Null => LookAheadValue::Null, - InputValue::Scalar(ref s) => LookAheadValue::Scalar(s), - InputValue::Enum(ref e) => LookAheadValue::Enum(e), + fn from_input_value( + input_value: BorrowedSpanning<'a, &'a InputValue>, + vars: &'a Variables, + ) -> BorrowedSpanning<'a, Self> { + fn borrow_spanning(span: &Span, item: T) -> BorrowedSpanning<'_, T> { + Spanning { item, span } + } + + let span = &input_value.span; + + match input_value.item { + InputValue::Null => borrow_spanning(span, LookAheadValue::Null), + InputValue::Scalar(ref s) => borrow_spanning(span, LookAheadValue::Scalar(s)), + InputValue::Enum(ref e) => borrow_spanning(span, LookAheadValue::Enum(e)), InputValue::Variable(ref name) => vars .get(name) - .map(|v| Self::from_input_value(v, vars)) - .unwrap_or(LookAheadValue::Null), - InputValue::List(ref l) => LookAheadValue::List( - l.iter() - .map(|i| LookAheadValue::from_input_value(&i.item, vars)) - .collect(), + .map(|v| Self::from_input_value(borrow_spanning(span, v), vars)) + .unwrap_or(borrow_spanning(span, LookAheadValue::Null)), + InputValue::List(ref l) => borrow_spanning( + span, + LookAheadValue::List( + l.iter() + .map(|i| LookAheadValue::from_input_value(i.as_ref(), vars)) + .collect(), + ), ), - InputValue::Object(ref o) => LookAheadValue::Object( - o.iter() - .map(|(n, i)| { - ( - &n.item as &str, - LookAheadValue::from_input_value(&i.item, vars), - ) - }) - .collect(), + InputValue::Object(ref o) => borrow_spanning( + span, + LookAheadValue::Object( + o.iter() + .map(|(n, i)| { + ( + borrow_spanning(&n.span, n.item.as_str()), + LookAheadValue::from_input_value(i.as_ref(), vars), + ) + }) + .collect(), + ), ), } } @@ -68,7 +90,7 @@ where #[derive(Debug, Clone, PartialEq)] pub struct LookAheadArgument<'a, S: 'a> { name: &'a str, - value: LookAheadValue<'a, S>, + value: BorrowedSpanning<'a, LookAheadValue<'a, S>>, } impl<'a, S> LookAheadArgument<'a, S> @@ -81,7 +103,7 @@ where ) -> Self { LookAheadArgument { name: name.item, - value: LookAheadValue::from_input_value(&value.item, vars), + value: LookAheadValue::from_input_value(value.as_ref(), vars), } } @@ -92,7 +114,12 @@ where /// The value of the argument pub fn value(&'a self) -> &LookAheadValue<'a, S> { - &self.value + &self.value.item + } + + /// The input source span of the argument + pub fn span(&self) -> &Span { + self.value.span } } @@ -145,7 +172,7 @@ where .find(|item| item.0.item == "if") .map(|(_, v)| { if let LookAheadValue::Scalar(s) = - LookAheadValue::from_input_value(&v.item, vars) + LookAheadValue::from_input_value(v.as_ref(), vars).item { s.as_bool().unwrap_or(false) } else { @@ -160,7 +187,7 @@ where .find(|item| item.0.item == "if") .map(|(_, v)| { if let LookAheadValue::Scalar(b) = - LookAheadValue::from_input_value(&v.item, vars) + LookAheadValue::from_input_value(v.as_ref(), vars).item { b.as_bool().map(::std::ops::Not::not).unwrap_or(false) } else { @@ -472,12 +499,12 @@ impl<'a, S> LookAheadMethods<'a, S> for LookAheadSelection<'a, S> { #[cfg(test)] mod tests { - use std::collections::HashMap; + use std::{collections::HashMap, ops::Range}; use crate::{ ast::{Document, OwnedDocument}, graphql_vars, - parser::UnlocatedParseResult, + parser::{SourcePosition, UnlocatedParseResult}, schema::model::SchemaType, validation::test_harness::{MutationRoot, QueryRoot, SubscriptionRoot}, value::{DefaultScalarValue, ScalarValue}, @@ -509,6 +536,13 @@ mod tests { fragments } + fn span(range: Range<(usize, usize, usize)>) -> Span { + Span { + start: SourcePosition::new(range.start.0, range.start.1, range.start.2), + end: SourcePosition::new(range.end.0, range.end.1, range.end.2), + } + } + #[test] fn check_simple_query() { let docs = parse_document_source::( @@ -711,12 +745,17 @@ query Hero { &fragments, ) .unwrap(); + let span0 = span((32, 2, 18)..(38, 2, 24)); + let span1 = span((77, 4, 24)..(81, 4, 28)); let expected = LookAheadSelection { name: "hero", alias: None, arguments: vec![LookAheadArgument { name: "episode", - value: LookAheadValue::Enum("EMPIRE"), + value: Spanning { + item: LookAheadValue::Enum("EMPIRE"), + span: &span0, + }, }], applies_for: Applies::All, children: vec![ @@ -732,7 +771,10 @@ query Hero { alias: None, arguments: vec![LookAheadArgument { name: "uppercase", - value: LookAheadValue::Scalar(&DefaultScalarValue::Boolean(true)), + value: Spanning { + item: LookAheadValue::Scalar(&DefaultScalarValue::Boolean(true)), + span: &span1, + }, }], children: Vec::new(), applies_for: Applies::All, @@ -768,12 +810,16 @@ query Hero($episode: Episode) { &fragments, ) .unwrap(); + let span0 = span((51, 2, 18)..(59, 2, 26)); let expected = LookAheadSelection { name: "hero", alias: None, arguments: vec![LookAheadArgument { name: "episode", - value: LookAheadValue::Enum("JEDI"), + value: Spanning { + item: LookAheadValue::Enum("JEDI"), + span: &span0, + }, }], applies_for: Applies::All, children: vec![ @@ -821,12 +867,16 @@ query Hero($episode: Episode) { &fragments, ) .unwrap(); + let span0 = span((51, 2, 18)..(59, 2, 26)); let expected = LookAheadSelection { name: "hero", alias: None, arguments: vec![LookAheadArgument { name: "episode", - value: LookAheadValue::Null, + value: Spanning { + item: LookAheadValue::Null, + span: &span0, + }, }], applies_for: Applies::All, children: vec![LookAheadSelection { @@ -1121,12 +1171,16 @@ fragment comparisonFields on Character { &fragments, ) .unwrap(); + let span0 = span((85, 2, 11)..(88, 2, 14)); let expected = LookAheadSelection { name: "hero", alias: None, arguments: vec![LookAheadArgument { name: "id", - value: LookAheadValue::Scalar(&DefaultScalarValue::Int(42)), + value: Spanning { + item: LookAheadValue::Scalar(&DefaultScalarValue::Int(42)), + span: &span0, + }, }], applies_for: Applies::All, children: vec![ diff --git a/juniper/src/parser/utils.rs b/juniper/src/parser/utils.rs index 3ff0318d5..ac8cf70ad 100644 --- a/juniper/src/parser/utils.rs +++ b/juniper/src/parser/utils.rs @@ -52,15 +52,15 @@ impl Span { /// Data structure used to wrap items into a [`Span`]. #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] -pub struct Spanning { +pub struct Spanning { /// Wrapped item. pub item: T, /// [`Span`] of the wrapped item. - pub span: Span, + pub span: Sp, } -impl Spanning { +impl Spanning { #[doc(hidden)] pub fn new(span: Span, item: T) -> Self { Self { item, span } @@ -126,6 +126,14 @@ impl Spanning { pub fn and_then Option>(self, f: F) -> Option> { f(self.item).map(|item| Spanning::new(self.span, item)) } + + /// Make a Spanning that contains a borrowed item and a borrowed span. + pub(crate) fn as_ref(&self) -> Spanning<&'_ T, &'_ Span> { + Spanning { + item: &self.item, + span: &self.span, + } + } } impl fmt::Display for Spanning { From 73b31acf45cde31144d6b06b2a4cef888bfbe167 Mon Sep 17 00:00:00 2001 From: Audun Halland Date: Thu, 9 Nov 2023 15:34:36 +0100 Subject: [PATCH 3/5] chore: Update CHANGELOG.md --- juniper/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/juniper/CHANGELOG.md b/juniper/CHANGELOG.md index 4dc03f95d..97551abc6 100644 --- a/juniper/CHANGELOG.md +++ b/juniper/CHANGELOG.md @@ -54,6 +54,7 @@ All user visible changes to `juniper` crate will be documented in this file. Thi - Upgraded [GraphiQL] to 3.0.9 version (requires new [`graphql-transport-ws` GraphQL over WebSocket Protocol] integration on server, see `juniper_warp/examples/subscription.rs`). ([#1188], [#1193], [#1204]) - Made `LookAheadMethods::children()` method to return slice instead of `Vec`. ([#1200]) - Abstracted `Spanning::start` and `Spanning::end` fields into separate struct `Span`. ([#1207], [#1208]) +- Added `Span` to `Arguments` and `LookAheadArguments`. ([#1209]) ### Added @@ -134,6 +135,7 @@ All user visible changes to `juniper` crate will be documented in this file. Thi [#1204]: /../../pull/1204 [#1207]: /../../pull/1207 [#1208]: /../../pull/1208 +[#1209]: /../../pull/1209 [ba1ed85b]: /../../commit/ba1ed85b3c3dd77fbae7baf6bc4e693321a94083 [CVE-2022-31173]: /../../security/advisories/GHSA-4rx6-g5vg-5f3j From 7c21d34b3636a05f1133f8af6090da43b0ff7845 Mon Sep 17 00:00:00 2001 From: tyranron Date: Thu, 9 Nov 2023 18:19:57 +0200 Subject: [PATCH 4/5] Remove `Spanning` for `meta::Argument::default_value` --- juniper/CHANGELOG.md | 3 ++- juniper/src/schema/meta.rs | 6 +++--- juniper/src/schema/schema.rs | 2 +- juniper/src/schema/translate/graphql_parser.rs | 2 +- juniper/src/types/base.rs | 2 +- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/juniper/CHANGELOG.md b/juniper/CHANGELOG.md index 97551abc6..26939bad8 100644 --- a/juniper/CHANGELOG.md +++ b/juniper/CHANGELOG.md @@ -54,7 +54,7 @@ All user visible changes to `juniper` crate will be documented in this file. Thi - Upgraded [GraphiQL] to 3.0.9 version (requires new [`graphql-transport-ws` GraphQL over WebSocket Protocol] integration on server, see `juniper_warp/examples/subscription.rs`). ([#1188], [#1193], [#1204]) - Made `LookAheadMethods::children()` method to return slice instead of `Vec`. ([#1200]) - Abstracted `Spanning::start` and `Spanning::end` fields into separate struct `Span`. ([#1207], [#1208]) -- Added `Span` to `Arguments` and `LookAheadArguments`. ([#1209]) +- Added `Span` to `Arguments` and `LookAheadArguments`. ([#1206], [#1209]) ### Added @@ -133,6 +133,7 @@ All user visible changes to `juniper` crate will be documented in this file. Thi [#1199]: /../../pull/1199 [#1200]: /../../pull/1200 [#1204]: /../../pull/1204 +[#1206]: /../../pull/1206 [#1207]: /../../pull/1207 [#1208]: /../../pull/1208 [#1209]: /../../pull/1209 diff --git a/juniper/src/schema/meta.rs b/juniper/src/schema/meta.rs index e2bbebc2c..04f5eda96 100644 --- a/juniper/src/schema/meta.rs +++ b/juniper/src/schema/meta.rs @@ -12,7 +12,7 @@ use crate::{ schema::model::SchemaType, types::base::TypeKind, value::{DefaultScalarValue, ParseScalarValue}, - FieldError, Spanning, + FieldError, }; /// Whether an item is deprecated, with context. @@ -202,7 +202,7 @@ pub struct Argument<'a, S> { #[doc(hidden)] pub arg_type: Type<'a>, #[doc(hidden)] - pub default_value: Option>>, + pub default_value: Option>, } impl<'a, S> Argument<'a, S> { @@ -739,7 +739,7 @@ impl<'a, S> Argument<'a, S> { /// Overwrites any previously set default value. #[must_use] pub fn default_value(mut self, val: InputValue) -> Self { - self.default_value = Some(Spanning::unlocated(val)); + self.default_value = Some(val); self } } diff --git a/juniper/src/schema/schema.rs b/juniper/src/schema/schema.rs index 98729cae2..618227462 100644 --- a/juniper/src/schema/schema.rs +++ b/juniper/src/schema/schema.rs @@ -386,7 +386,7 @@ impl<'a, S: ScalarValue + 'a> Argument<'a, S> { #[graphql(name = "defaultValue")] fn default_value_(&self) -> Option { - self.default_value.as_ref().map(|v| v.item.to_string()) + self.default_value.as_ref().map(ToString::to_string) } } diff --git a/juniper/src/schema/translate/graphql_parser.rs b/juniper/src/schema/translate/graphql_parser.rs index db8dbdc17..7612b610b 100644 --- a/juniper/src/schema/translate/graphql_parser.rs +++ b/juniper/src/schema/translate/graphql_parser.rs @@ -89,7 +89,7 @@ impl GraphQLParserTranslator { default_value: input .default_value .as_ref() - .map(|x| GraphQLParserTranslator::translate_value(&x.item)), + .map(|x| GraphQLParserTranslator::translate_value(x)), directives: vec![], } } diff --git a/juniper/src/types/base.rs b/juniper/src/types/base.rs index fb5c37ae2..0563497df 100644 --- a/juniper/src/types/base.rs +++ b/juniper/src/types/base.rs @@ -89,7 +89,7 @@ impl<'a, S> Arguments<'a, S> { let arg_name = arg.name.as_str(); if args.get(arg_name).is_none() { if let Some(val) = arg.default_value.as_ref() { - args.insert(arg_name, val.clone()); + args.insert(arg_name, Spanning::unlocated(val.clone())); } } } From cae5497d879daffd2602b6bfa9900da5f28dc421 Mon Sep 17 00:00:00 2001 From: tyranron Date: Thu, 9 Nov 2023 18:44:36 +0200 Subject: [PATCH 5/5] Bikeshed --- juniper/src/executor/look_ahead.rs | 57 +++++++++++++++--------------- juniper/src/parser/utils.rs | 2 +- juniper/src/types/async_await.rs | 4 +-- juniper/src/types/base.rs | 6 ++-- juniper/src/types/subscriptions.rs | 4 +-- juniper/src/types/utilities.rs | 7 ++-- 6 files changed, 39 insertions(+), 41 deletions(-) diff --git a/juniper/src/executor/look_ahead.rs b/juniper/src/executor/look_ahead.rs index 9de0c8103..3fe73c35e 100644 --- a/juniper/src/executor/look_ahead.rs +++ b/juniper/src/executor/look_ahead.rs @@ -18,13 +18,14 @@ pub enum Applies<'a> { OnlyType(&'a str), } +/// Shortcut for a [`Spanning`] containing a borrowed [`Span`]. type BorrowedSpanning<'a, T> = Spanning; -/// A JSON-like value that can is used as argument in the query execution +/// JSON-like value that can be used as an argument in the query execution. /// -/// In contrast to `InputValue` these values do only contain constants, +/// In contrast to an [`InputValue`], these values do only contain constants, /// meaning that variables are already resolved. -#[derive(Debug, Clone, PartialEq)] +#[derive(Clone, Debug, PartialEq)] #[allow(missing_docs)] pub enum LookAheadValue<'a, S: 'a> { Null, @@ -47,41 +48,41 @@ where input_value: BorrowedSpanning<'a, &'a InputValue>, vars: &'a Variables, ) -> BorrowedSpanning<'a, Self> { - fn borrow_spanning(span: &Span, item: T) -> BorrowedSpanning<'_, T> { - Spanning { item, span } - } - - let span = &input_value.span; - - match input_value.item { - InputValue::Null => borrow_spanning(span, LookAheadValue::Null), - InputValue::Scalar(ref s) => borrow_spanning(span, LookAheadValue::Scalar(s)), - InputValue::Enum(ref e) => borrow_spanning(span, LookAheadValue::Enum(e)), - InputValue::Variable(ref name) => vars - .get(name) - .map(|v| Self::from_input_value(borrow_spanning(span, v), vars)) - .unwrap_or(borrow_spanning(span, LookAheadValue::Null)), - InputValue::List(ref l) => borrow_spanning( - span, - LookAheadValue::List( + Spanning { + span: input_value.span, + item: match input_value.item { + InputValue::Null => Self::Null, + InputValue::Scalar(s) => Self::Scalar(s), + InputValue::Enum(e) => Self::Enum(e), + InputValue::Variable(name) => vars + .get(name) + .map(|item| { + let input_value = Spanning { + span: input_value.span, + item, + }; + Self::from_input_value(input_value, vars).item + }) + .unwrap_or(Self::Null), + InputValue::List(l) => Self::List( l.iter() - .map(|i| LookAheadValue::from_input_value(i.as_ref(), vars)) + .map(|i| Self::from_input_value(i.as_ref(), vars)) .collect(), ), - ), - InputValue::Object(ref o) => borrow_spanning( - span, - LookAheadValue::Object( + InputValue::Object(o) => Self::Object( o.iter() .map(|(n, i)| { ( - borrow_spanning(&n.span, n.item.as_str()), - LookAheadValue::from_input_value(i.as_ref(), vars), + Spanning { + span: &n.span, + item: n.item.as_str(), + }, + Self::from_input_value(i.as_ref(), vars), ) }) .collect(), ), - ), + }, } } } diff --git a/juniper/src/parser/utils.rs b/juniper/src/parser/utils.rs index ac8cf70ad..2494dce6a 100644 --- a/juniper/src/parser/utils.rs +++ b/juniper/src/parser/utils.rs @@ -127,7 +127,7 @@ impl Spanning { f(self.item).map(|item| Spanning::new(self.span, item)) } - /// Make a Spanning that contains a borrowed item and a borrowed span. + /// Converts into a [`Spanning`] containing a borrowed item and a borrowed [`Span`]. pub(crate) fn as_ref(&self) -> Spanning<&'_ T, &'_ Span> { Spanning { item: &self.item, diff --git a/juniper/src/types/async_await.rs b/juniper/src/types/async_await.rs index adbb8175e..df49ac356 100644 --- a/juniper/src/types/async_await.rs +++ b/juniper/src/types/async_await.rs @@ -244,8 +244,8 @@ where m.item .iter() .filter_map(|(k, v)| { - let value = v.item.clone().into_const(exec_vars)?; - Some((k.item, Spanning::new(v.span, value))) + let val = v.item.clone().into_const(exec_vars)?; + Some((k.item, Spanning::new(v.span, val))) }) .collect() }), diff --git a/juniper/src/types/base.rs b/juniper/src/types/base.rs index 0563497df..8392d24a0 100644 --- a/juniper/src/types/base.rs +++ b/juniper/src/types/base.rs @@ -123,7 +123,7 @@ impl<'a, S> Arguments<'a, S> { .map_err(IntoFieldError::into_field_error) } - /// Gets a direct reference to the spanned argument input value + /// Gets a direct reference to the [`Spanning`] argument [`InputValue`]. pub fn get_input_value(&self, name: &str) -> Option<&Spanning>> { self.args.as_ref().and_then(|args| args.get(name)) } @@ -478,8 +478,8 @@ where m.item .iter() .filter_map(|(k, v)| { - let value = v.item.clone().into_const(exec_vars)?; - Some((k.item, Spanning::new(v.span, value))) + let val = v.item.clone().into_const(exec_vars)?; + Some((k.item, Spanning::new(v.span, val))) }) .collect() }), diff --git a/juniper/src/types/subscriptions.rs b/juniper/src/types/subscriptions.rs index 11cb8c716..3e8211b8a 100644 --- a/juniper/src/types/subscriptions.rs +++ b/juniper/src/types/subscriptions.rs @@ -316,8 +316,8 @@ where m.item .iter() .filter_map(|(k, v)| { - let value = v.item.clone().into_const(exec_vars)?; - Some((k.item, Spanning::new(v.span, value))) + let val = v.item.clone().into_const(exec_vars)?; + Some((k.item, Spanning::new(v.span, val))) }) .collect() }), diff --git a/juniper/src/types/utilities.rs b/juniper/src/types/utilities.rs index f0e44b1f0..e8128eea0 100644 --- a/juniper/src/types/utilities.rs +++ b/juniper/src/types/utilities.rs @@ -72,11 +72,8 @@ where let mut remaining_required_fields = input_fields .iter() .filter_map(|f| { - if f.arg_type.is_non_null() && f.default_value.is_none() { - Some(&f.name) - } else { - None - } + (f.arg_type.is_non_null() && f.default_value.is_none()) + .then_some(&f.name) }) .collect::>();