diff --git a/juniper/src/ast.rs b/juniper/src/ast.rs index 0a99c724..2881515b 100644 --- a/juniper/src/ast.rs +++ b/juniper/src/ast.rs @@ -5,7 +5,7 @@ use indexmap::IndexMap; use crate::{ executor::Variables, parser::Spanning, - value::{DefaultScalarValue, ScalarRefValue, ScalarValue}, + value::{DefaultScalarValue, ScalarValue}, }; /// A type literal in the syntax tree @@ -152,9 +152,7 @@ pub type Document<'a, S> = Vec<Definition<'a, S>>; /// Must be implemented manually when manually exposing new enums or scalars. pub trait FromInputValue<S = DefaultScalarValue>: Sized { /// Performs the conversion. - fn from_input_value(v: &InputValue<S>) -> Option<Self> - where - for<'b> &'b S: ScalarRefValue<'b>; + fn from_input_value(v: &InputValue<S>) -> Option<Self>; } /// Losslessly clones a Rust data type into an InputValue. @@ -316,7 +314,6 @@ where pub fn convert<T>(&self) -> Option<T> where T: FromInputValue<S>, - for<'b> &'b S: ScalarRefValue<'b>, { <T as FromInputValue<S>>::from_input_value(self) } @@ -346,30 +343,18 @@ where } /// View the underlying int value, if present. - #[deprecated(since = "0.11.0", note = "Use `InputValue::as_scalar_value` instead")] - pub fn as_int_value<'a>(&'a self) -> Option<i32> - where - &'a S: Into<Option<&'a i32>>, - { - self.as_scalar_value().cloned() + pub fn as_int_value<'a>(&'a self) -> Option<i32> { + self.as_scalar_value().and_then(|s| s.as_int()) } /// View the underlying float value, if present. - #[deprecated(since = "0.11.0", note = "Use `InputValue::as_scalar_value` instead")] - pub fn as_float_value<'a>(&'a self) -> Option<f64> - where - &'a S: Into<Option<&'a f64>>, - { - self.as_scalar_value().cloned() + pub fn as_float_value<'a>(&'a self) -> Option<f64> { + self.as_scalar_value().and_then(|s| s.as_float()) } /// View the underlying string value, if present. - #[deprecated(since = "0.11.0", note = "Use `InputValue::as_scalar_value` instead")] - pub fn as_string_value<'a>(&'a self) -> Option<&'a str> - where - &'a S: Into<Option<&'a String>>, - { - self.as_scalar_value().map(|s| s as &str) + pub fn as_string_value<'a>(&'a self) -> Option<&'a str> { + self.as_scalar_value().and_then(|s| s.as_str()) } /// View the underlying scalar value, if present. @@ -459,13 +444,17 @@ where impl<S> fmt::Display for InputValue<S> where S: ScalarValue, - for<'b> &'b S: ScalarRefValue<'b>, { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { InputValue::Null => write!(f, "null"), - InputValue::Scalar(ref s) if s.is_type::<String>() => write!(f, "\"{}\"", s), - InputValue::Scalar(ref s) => write!(f, "{}", s), + InputValue::Scalar(ref s) => { + if let Some(s) = s.as_str() { + write!(f, "\"{}\"", s) + } else { + write!(f, "{}", s) + } + } InputValue::Enum(ref v) => write!(f, "{}", v), InputValue::Variable(ref v) => write!(f, "${}", v), InputValue::List(ref v) => { diff --git a/juniper/src/executor/look_ahead.rs b/juniper/src/executor/look_ahead.rs index 3c8fd7e4..06e6a80c 100644 --- a/juniper/src/executor/look_ahead.rs +++ b/juniper/src/executor/look_ahead.rs @@ -1,7 +1,7 @@ use crate::{ ast::{Directive, Fragment, InputValue, Selection}, parser::Spanning, - value::{ScalarRefValue, ScalarValue}, + value::ScalarValue, }; use std::collections::HashMap; @@ -117,7 +117,6 @@ pub struct LookAheadSelection<'a, S: 'a> { impl<'a, S> Default for LookAheadSelection<'a, S> where S: ScalarValue, - &'a S: ScalarRefValue<'a>, { fn default() -> Self { LookAheadSelection { @@ -132,7 +131,6 @@ where impl<'a, S> LookAheadSelection<'a, S> where S: ScalarValue, - &'a S: ScalarRefValue<'a>, { fn should_include<'b, 'c>( directives: Option<&'b Vec<Spanning<Directive<S>>>>, @@ -157,9 +155,7 @@ where if let LookAheadValue::Scalar(s) = LookAheadValue::from_input_value(&v.item, vars) { - <&S as Into<Option<&bool>>>::into(s) - .cloned() - .unwrap_or(false) + s.as_boolean().unwrap_or(false) } else { false } @@ -174,9 +170,7 @@ where if let LookAheadValue::Scalar(b) = LookAheadValue::from_input_value(&v.item, vars) { - <&S as Into<Option<&bool>>>::into(b) - .map(::std::ops::Not::not) - .unwrap_or(false) + b.as_boolean().map(::std::ops::Not::not).unwrap_or(false) } else { false } @@ -439,14 +433,13 @@ mod tests { parser::UnlocatedParseResult, schema::model::SchemaType, validation::test_harness::{MutationRoot, QueryRoot}, - value::{DefaultScalarValue, ScalarRefValue, ScalarValue}, + value::{DefaultScalarValue, ScalarValue}, }; use std::collections::HashMap; fn parse_document_source<S>(q: &str) -> UnlocatedParseResult<Document<S>> where S: ScalarValue, - for<'b> &'b S: ScalarRefValue<'b>, { crate::parse_document_source(q, &SchemaType::new::<QueryRoot, MutationRoot>(&(), &())) } diff --git a/juniper/src/executor/mod.rs b/juniper/src/executor/mod.rs index c080f9d4..7ae9c79a 100644 --- a/juniper/src/executor/mod.rs +++ b/juniper/src/executor/mod.rs @@ -22,7 +22,7 @@ use crate::schema::{ use crate::{ types::{base::GraphQLType, name::Name}, - value::{DefaultScalarValue, ParseScalarValue, ScalarRefValue, ScalarValue}, + value::{DefaultScalarValue, ParseScalarValue, ScalarValue}, }; mod look_ahead; @@ -235,7 +235,6 @@ impl<S> IntoFieldError<S> for FieldError<S> { pub trait IntoResolvable<'a, S, T: GraphQLType<S>, C>: Sized where S: ScalarValue, - for<'b> &'b S: ScalarRefValue<'b>, { #[doc(hidden)] fn into(self, ctx: &'a C) -> FieldResult<Option<(&'a T::Context, T)>, S>; @@ -246,7 +245,6 @@ where T: GraphQLType<S>, S: ScalarValue, T::Context: FromContext<C>, - for<'b> &'b S: ScalarRefValue<'b>, { fn into(self, ctx: &'a C) -> FieldResult<Option<(&'a T::Context, T)>, S> { Ok(Some((FromContext::from(ctx), self))) @@ -258,7 +256,6 @@ where S: ScalarValue, T: GraphQLType<S>, T::Context: FromContext<C>, - for<'b> &'b S: ScalarRefValue<'b>, { fn into(self, ctx: &'a C) -> FieldResult<Option<(&'a T::Context, T)>, S> { self.map(|v: T| Some((<T::Context as FromContext<C>>::from(ctx), v))) @@ -270,7 +267,6 @@ impl<'a, S, T, C> IntoResolvable<'a, S, T, C> for (&'a T::Context, T) where S: ScalarValue, T: GraphQLType<S>, - for<'b> &'b S: ScalarRefValue<'b>, { fn into(self, _: &'a C) -> FieldResult<Option<(&'a T::Context, T)>, S> { Ok(Some(self)) @@ -281,7 +277,6 @@ impl<'a, S, T, C> IntoResolvable<'a, S, Option<T>, C> for Option<(&'a T::Context where S: ScalarValue, T: GraphQLType<S>, - for<'b> &'b S: ScalarRefValue<'b>, { fn into(self, _: &'a C) -> FieldResult<Option<(&'a T::Context, Option<T>)>, S> { Ok(self.map(|(ctx, v)| (ctx, Some(v)))) @@ -292,7 +287,6 @@ impl<'a, S, T, C> IntoResolvable<'a, S, T, C> for FieldResult<(&'a T::Context, T where S: ScalarValue, T: GraphQLType<S>, - for<'b> &'b S: ScalarRefValue<'b>, { fn into(self, _: &'a C) -> FieldResult<Option<(&'a T::Context, T)>, S> { self.map(Some) @@ -304,7 +298,6 @@ impl<'a, S, T, C> IntoResolvable<'a, S, Option<T>, C> where S: ScalarValue, T: GraphQLType<S>, - for<'b> &'b S: ScalarRefValue<'b>, { fn into(self, _: &'a C) -> FieldResult<Option<(&'a T::Context, Option<T>)>, S> { self.map(|o| o.map(|(ctx, v)| (ctx, Some(v)))) @@ -352,7 +345,6 @@ where impl<'a, CtxT, S> Executor<'a, CtxT, S> where S: ScalarValue, - for<'b> &'b S: ScalarRefValue<'b>, { /// Resolve a single arbitrary value, mapping the context to a new type pub fn resolve_with_ctx<NewCtxT, T>(&self, info: &T::TypeInfo, value: &T) -> ExecutionResult<S> @@ -671,7 +663,6 @@ where S: ScalarValue, QueryT: GraphQLType<S, Context = CtxT>, MutationT: GraphQLType<S, Context = CtxT>, - for<'b> &'b S: ScalarRefValue<'b>, { let mut fragments = vec![]; let mut operation = None; @@ -786,7 +777,6 @@ where MutationT: crate::GraphQLTypeAsync<S, Context = CtxT> + Send + Sync, MutationT::TypeInfo: Send + Sync, CtxT: Send + Sync, - for<'b> &'b S: ScalarRefValue<'b>, { let mut fragments = vec![]; let mut operation = None; @@ -908,7 +898,6 @@ where pub fn get_type<T>(&mut self, info: &T::TypeInfo) -> Type<'r> where T: GraphQLType<S>, - for<'b> &'b S: ScalarRefValue<'b>, { if let Some(name) = T::name(info) { let validated_name = name.parse::<Name>().unwrap(); @@ -930,7 +919,6 @@ where pub fn field<T>(&mut self, name: &str, info: &T::TypeInfo) -> Field<'r, S> where T: GraphQLType<S>, - for<'b> &'b S: ScalarRefValue<'b>, { Field { name: name.to_owned(), @@ -949,7 +937,6 @@ where ) -> Field<'r, S> where I: GraphQLType<S>, - for<'b> &'b S: ScalarRefValue<'b>, { Field { name: name.to_owned(), @@ -964,7 +951,6 @@ where pub fn arg<T>(&mut self, name: &str, info: &T::TypeInfo) -> Argument<'r, S> where T: GraphQLType<S> + FromInputValue<S>, - for<'b> &'b S: ScalarRefValue<'b>, { Argument::new(name, self.get_type::<T>(info)) } @@ -981,7 +967,6 @@ where ) -> Argument<'r, S> where T: GraphQLType<S> + ToInputValue<S> + FromInputValue<S>, - for<'b> &'b S: ScalarRefValue<'b>, { Argument::new(name, self.get_type::<Option<T>>(info)).default_value(value.to_input_value()) } @@ -999,26 +984,22 @@ where pub fn build_scalar_type<T>(&mut self, info: &T::TypeInfo) -> ScalarMeta<'r, S> where T: FromInputValue<S> + GraphQLType<S> + ParseScalarValue<S> + 'r, - for<'b> &'b S: ScalarRefValue<'b>, { let name = T::name(info).expect("Scalar types must be named. Implement name()"); ScalarMeta::new::<T>(Cow::Owned(name.to_string())) } /// Create a list meta type - pub fn build_list_type<T: GraphQLType<S>>(&mut self, info: &T::TypeInfo) -> ListMeta<'r> - where - for<'b> &'b S: ScalarRefValue<'b>, - { + pub fn build_list_type<T: GraphQLType<S>>(&mut self, info: &T::TypeInfo) -> ListMeta<'r> { let of_type = self.get_type::<T>(info); ListMeta::new(of_type) } /// Create a nullable meta type - pub fn build_nullable_type<T: GraphQLType<S>>(&mut self, info: &T::TypeInfo) -> NullableMeta<'r> - where - for<'b> &'b S: ScalarRefValue<'b>, - { + pub fn build_nullable_type<T: GraphQLType<S>>( + &mut self, + info: &T::TypeInfo, + ) -> NullableMeta<'r> { let of_type = self.get_type::<T>(info); NullableMeta::new(of_type) } @@ -1034,7 +1015,6 @@ where ) -> ObjectMeta<'r, S> where T: GraphQLType<S>, - for<'b> &'b S: ScalarRefValue<'b>, { let name = T::name(info).expect("Object types must be named. Implement name()"); @@ -1051,7 +1031,6 @@ where ) -> EnumMeta<'r, S> where T: FromInputValue<S> + GraphQLType<S>, - for<'b> &'b S: ScalarRefValue<'b>, { let name = T::name(info).expect("Enum types must be named. Implement name()"); @@ -1067,7 +1046,6 @@ where ) -> InterfaceMeta<'r, S> where T: GraphQLType<S>, - for<'b> &'b S: ScalarRefValue<'b>, { let name = T::name(info).expect("Interface types must be named. Implement name()"); @@ -1080,7 +1058,6 @@ where pub fn build_union_type<T>(&mut self, info: &T::TypeInfo, types: &[Type<'r>]) -> UnionMeta<'r> where T: GraphQLType<S>, - for<'b> &'b S: ScalarRefValue<'b>, { let name = T::name(info).expect("Union types must be named. Implement name()"); @@ -1095,7 +1072,6 @@ where ) -> InputObjectMeta<'r, S> where T: FromInputValue<S> + GraphQLType<S>, - for<'b> &'b S: ScalarRefValue<'b>, { let name = T::name(info).expect("Input object types must be named. Implement name()"); diff --git a/juniper/src/http/mod.rs b/juniper/src/http/mod.rs index 2d4e62bd..d4ce4d41 100644 --- a/juniper/src/http/mod.rs +++ b/juniper/src/http/mod.rs @@ -12,7 +12,7 @@ use serde_derive::{Deserialize, Serialize}; use crate::{ ast::InputValue, executor::ExecutionError, - value::{DefaultScalarValue, ScalarRefValue, ScalarValue}, + value::{DefaultScalarValue, ScalarValue}, FieldError, GraphQLError, GraphQLType, RootNode, Value, Variables, }; @@ -83,7 +83,6 @@ where S: ScalarValue, QueryT: GraphQLType<S, Context = CtxT>, MutationT: GraphQLType<S, Context = CtxT>, - for<'b> &'b S: ScalarRefValue<'b>, { GraphQLResponse(crate::execute( &self.query, @@ -107,7 +106,6 @@ where MutationT: crate::GraphQLTypeAsync<S, Context = CtxT> + Send + Sync, MutationT::TypeInfo: Send + Sync, CtxT: Send + Sync, - for<'b> &'b S: ScalarRefValue<'b>, { let op = self.operation_name(); let vars = &self.variables(); diff --git a/juniper/src/integrations/chrono.rs b/juniper/src/integrations/chrono.rs index 41a35a33..08c54d6f 100644 --- a/juniper/src/integrations/chrono.rs +++ b/juniper/src/integrations/chrono.rs @@ -32,7 +32,7 @@ graphql_scalar!(DateTime<FixedOffset> as "DateTimeFixedOffset" where Scalar = <S } from_input_value(v: &InputValue) -> Option<DateTime<FixedOffset>> { - v.as_scalar_value::<String>() + v.as_string_value() .and_then(|s| DateTime::parse_from_rfc3339(s).ok()) } @@ -53,7 +53,7 @@ graphql_scalar!(DateTime<Utc> as "DateTimeUtc" where Scalar = <S>{ } from_input_value(v: &InputValue) -> Option<DateTime<Utc>> { - v.as_scalar_value::<String>() + v.as_string_value() .and_then(|s| (s.parse::<DateTime<Utc>>().ok())) } @@ -79,7 +79,7 @@ graphql_scalar!(NaiveDate where Scalar = <S>{ } from_input_value(v: &InputValue) -> Option<NaiveDate> { - v.as_scalar_value::<String>() + v.as_string_value() .and_then(|s| NaiveDate::parse_from_str(s, "%Y-%m-%d").ok()) } @@ -102,8 +102,8 @@ graphql_scalar!(NaiveDateTime where Scalar = <S> { } from_input_value(v: &InputValue) -> Option<NaiveDateTime> { - v.as_scalar_value::<f64>() - .and_then(|f| NaiveDateTime::from_timestamp_opt(*f as i64, 0)) + v.as_float_value() + .and_then(|f| NaiveDateTime::from_timestamp_opt(f as i64, 0)) } from_str<'a>(value: ScalarToken<'a>) -> ParseScalarResult<'a, S> { diff --git a/juniper/src/integrations/url.rs b/juniper/src/integrations/url.rs index 0f7019f8..1ee695f3 100644 --- a/juniper/src/integrations/url.rs +++ b/juniper/src/integrations/url.rs @@ -13,7 +13,7 @@ graphql_scalar!(Url where Scalar = <S>{ } from_input_value(v: &InputValue) -> Option<Url> { - v.as_scalar_value::<String>() + v.as_string_value() .and_then(|s| Url::parse(s).ok()) } diff --git a/juniper/src/integrations/uuid.rs b/juniper/src/integrations/uuid.rs index a5962195..98f88a48 100644 --- a/juniper/src/integrations/uuid.rs +++ b/juniper/src/integrations/uuid.rs @@ -14,7 +14,7 @@ graphql_scalar!(Uuid where Scalar = <S> { } from_input_value(v: &InputValue) -> Option<Uuid> { - v.as_scalar_value::<String>() + v.as_string_value() .and_then(|s| Uuid::parse_str(s).ok()) } diff --git a/juniper/src/lib.rs b/juniper/src/lib.rs index dd1cfffa..68a132bb 100644 --- a/juniper/src/lib.rs +++ b/juniper/src/lib.rs @@ -170,10 +170,7 @@ pub use crate::{ scalars::{EmptyMutation, ID}, }, validation::RuleError, - value::{ - DefaultScalarValue, Object, ParseScalarResult, ParseScalarValue, ScalarRefValue, - ScalarValue, Value, - }, + value::{DefaultScalarValue, Object, ParseScalarResult, ParseScalarValue, ScalarValue, Value}, }; /// A pinned, boxed future that can be polled. @@ -204,7 +201,6 @@ pub fn execute<'a, S, CtxT, QueryT, MutationT>( ) -> Result<(Value<S>, Vec<ExecutionError<S>>), GraphQLError<'a>> where S: ScalarValue, - for<'b> &'b S: ScalarRefValue<'b>, QueryT: GraphQLType<S, Context = CtxT>, MutationT: GraphQLType<S, Context = CtxT>, { @@ -246,7 +242,6 @@ where MutationT: GraphQLTypeAsync<S, Context = CtxT> + Send + Sync, MutationT::TypeInfo: Send + Sync, CtxT: Send + Sync, - for<'b> &'b S: ScalarRefValue<'b>, { let document = parse_document_source(document_source, &root_node.schema)?; { @@ -279,7 +274,6 @@ pub fn introspect<'a, S, CtxT, QueryT, MutationT>( ) -> Result<(Value<S>, Vec<ExecutionError<S>>), GraphQLError<'a>> where S: ScalarValue, - for<'b> &'b S: ScalarRefValue<'b>, QueryT: GraphQLType<S, Context = CtxT>, MutationT: GraphQLType<S, Context = CtxT>, { diff --git a/juniper/src/macros/common.rs b/juniper/src/macros/common.rs index 88320cd6..9178f5a7 100644 --- a/juniper/src/macros/common.rs +++ b/juniper/src/macros/common.rs @@ -32,7 +32,6 @@ macro_rules! __juniper_impl_trait { impl<$($other,)* $generic $(: $bound)*> $crate::$impl_trait<$generic> for $name where $generic: $crate::ScalarValue, - for<'__b> &'__b $generic: $crate::ScalarRefValue<'__b>, { $($body)* } @@ -48,7 +47,6 @@ macro_rules! __juniper_impl_trait { where $($where)* $generic: $crate::ScalarValue, - for<'__b> &'__b $generic: $crate::ScalarRefValue<'__b>, { $($body)* } diff --git a/juniper/src/macros/interface.rs b/juniper/src/macros/interface.rs index 44d1c398..1bbe4ead 100644 --- a/juniper/src/macros/interface.rs +++ b/juniper/src/macros/interface.rs @@ -145,7 +145,7 @@ macro_rules! graphql_interface { info: &Self::TypeInfo, registry: &mut $crate::Registry<'r, $crate::__juniper_insert_generic!($($scalar)+)> ) -> $crate::meta::MetaType<'r, $crate::__juniper_insert_generic!($($scalar)+)> - where for<'__b> &'__b $crate::__juniper_insert_generic!($($scalar)+): $crate::ScalarRefValue<'__b>, + where $crate::__juniper_insert_generic!($($scalar)+): 'r { // Ensure all child types are registered diff --git a/juniper/src/macros/mod.rs b/juniper/src/macros/mod.rs index 4da45a6a..e6634438 100644 --- a/juniper/src/macros/mod.rs +++ b/juniper/src/macros/mod.rs @@ -8,8 +8,6 @@ mod object; mod interface; #[macro_use] mod scalar; -#[macro_use] -mod union; #[cfg(test)] mod tests; diff --git a/juniper/src/macros/object.rs b/juniper/src/macros/object.rs index 60fc2b92..062b3b8b 100644 --- a/juniper/src/macros/object.rs +++ b/juniper/src/macros/object.rs @@ -361,7 +361,7 @@ macro_rules! graphql_object { info: &Self::TypeInfo, registry: &mut $crate::Registry<'r, $crate::__juniper_insert_generic!($($scalar)+)> ) -> $crate::meta::MetaType<'r, $crate::__juniper_insert_generic!($($scalar)+)> - where for<'__b> &'__b $crate::__juniper_insert_generic!($($scalar)+): $crate::ScalarRefValue<'__b>, + where $crate::__juniper_insert_generic!($($scalar)+): 'r { let fields = &[$( diff --git a/juniper/src/macros/scalar.rs b/juniper/src/macros/scalar.rs index f2453a27..66b530b0 100644 --- a/juniper/src/macros/scalar.rs +++ b/juniper/src/macros/scalar.rs @@ -90,7 +90,7 @@ macro_rules! graphql_scalar { info: &Self::TypeInfo, registry: &mut $crate::Registry<'r, $crate::__juniper_insert_generic!($($scalar)+)> ) -> $crate::meta::MetaType<'r, $crate::__juniper_insert_generic!($($scalar)+)> - where for<'__b> &'__b $crate::__juniper_insert_generic!($($scalar)+): $crate::ScalarRefValue<'__b>, + where $crate::__juniper_insert_generic!($($scalar)+): 'r { let meta = registry.build_scalar_type::<Self>(info); @@ -390,7 +390,7 @@ macro_rules! graphql_scalar { info: &Self::TypeInfo, registry: &mut $crate::Registry<'r, $crate::__juniper_insert_generic!($($scalar)+)> ) -> $crate::meta::MetaType<'r, $crate::__juniper_insert_generic!($($scalar)+)> - where for<'__b> &'__b $crate::__juniper_insert_generic!($($scalar)+): $crate::ScalarRefValue<'__b>, + where $crate::__juniper_insert_generic!($($scalar)+): 'r { let meta = registry.build_scalar_type::<Self>(info); diff --git a/juniper/src/macros/tests/args.rs b/juniper/src/macros/tests/args.rs index 95b8dacb..24c66f62 100644 --- a/juniper/src/macros/tests/args.rs +++ b/juniper/src/macros/tests/args.rs @@ -73,17 +73,17 @@ impl Root { 0 } -// TODO: enable once [parameter attributes are supported by proc macros] -// (https://github.com/graphql-rust/juniper/pull/441) -// fn attr_arg_descr( -// #[graphql(description = "The arg")] -// arg: i32) -> i32 -// { 0 } -// fn attr_arg_descr_collapse( -// #[graphql(description = "The first arg")] -// #[graphql(description = "and more details")] -// arg: i32, -// ) -> i32 { 0 } + // TODO: enable once [parameter attributes are supported by proc macros] + // (https://github.com/graphql-rust/juniper/pull/441) + // fn attr_arg_descr( + // #[graphql(description = "The arg")] + // arg: i32) -> i32 + // { 0 } + // fn attr_arg_descr_collapse( + // #[graphql(description = "The first arg")] + // #[graphql(description = "and more details")] + // arg: i32, + // ) -> i32 { 0 } #[graphql(arguments(arg(default = 123,),))] fn arg_with_default(arg: i32) -> i32 { diff --git a/juniper/src/macros/tests/scalar.rs b/juniper/src/macros/tests/scalar.rs index 3759a4b2..7e879712 100644 --- a/juniper/src/macros/tests/scalar.rs +++ b/juniper/src/macros/tests/scalar.rs @@ -27,7 +27,7 @@ graphql_scalar!(DefaultName where Scalar = <S> { } from_input_value(v: &InputValue) -> Option<DefaultName> { - v.as_scalar_value::<i32>().map(|i| DefaultName(*i)) + v.as_scalar_value().and_then(|s| s.as_int()).map(|i| DefaultName(i)) } from_str<'a>(value: ScalarToken<'a>) -> ParseScalarResult<'a, S> { diff --git a/juniper/src/macros/union.rs b/juniper/src/macros/union.rs deleted file mode 100644 index cfdde368..00000000 --- a/juniper/src/macros/union.rs +++ /dev/null @@ -1,143 +0,0 @@ -/* - * -/** -Expose GraphQL unions - -Like interfaces, mapping unions can be tricky in idiomatic Rust. Because of -their similarity, the helper macros are similar, too: you provide a set of -expressions that resolve the union into the actual concrete type. - -## Syntax - -See the documentation for [`graphql_object!`][1] on the general item and type -syntax. `graphql_union!` supports only `description` and `interface_resolvers` -items, no fields or interfaces can be declared. - -See the documentation for [`graphql_interface!`][2] on the syntax for interface -resolvers. - -[1]: macro.graphql_object!.html -[2]: macro.graphql_interface!.html -*/ - - - -#[macro_export] -macro_rules! graphql_union { - - ( - @generate, - meta = { - lifetimes = [$($lifetimes:tt,)*], - name = $name:ty, - ctx = $ctx:ty, - main_self = $main_self:ident, - outname = {$($outname:tt)*}, - scalar = {$($scalar:tt)*}, - $(description = $desciption:tt,)* - additional = { - resolver = { - $(context = $resolver_ctx: ident,)* - items = [ - $({ - src = $resolver_src: ty, - resolver = $resolver_expr: expr, - },)* - ], - }, - }, - }, - items = [], - ) => { - $crate::__juniper_impl_trait!( - impl<$($scalar)* $(, $lifetimes)* > GraphQLType for $name { - type Context = $ctx; - type TypeInfo = (); - - fn name(_ : &Self::TypeInfo) -> Option<&str> { - Some($($outname)*) - } - - fn meta<'r>( - info: &Self::TypeInfo, - registry: &mut $crate::Registry<'r, $crate::__juniper_insert_generic!($($scalar)+)> - ) -> $crate::meta::MetaType<'r, $crate::__juniper_insert_generic!($($scalar)+)> - where for<'__b> &'__b $crate::__juniper_insert_generic!($($scalar)+): $crate::ScalarRefValue<'__b>, - $crate::__juniper_insert_generic!($($scalar)+): 'r - { - let types = &[ - $( - registry.get_type::<$resolver_src>(&()), - )* - ]; - registry.build_union_type::<$name>( - info, types - ) - $(.description($desciption))* - .into_meta() - } - - #[allow(unused_variables)] - fn concrete_type_name(&$main_self, context: &Self::Context, _info: &Self::TypeInfo) -> String { - $(let $resolver_ctx = &context;)* - - $( - if ($resolver_expr as ::std::option::Option<$resolver_src>).is_some() { - return - <$resolver_src as $crate::GraphQLType<_>>::name(&()).unwrap().to_owned(); - } - )* - - panic!("Concrete type not handled by instance resolvers on {}", $($outname)*); - } - - fn resolve_into_type( - &$main_self, - _info: &Self::TypeInfo, - type_name: &str, - _: Option<&[$crate::Selection<$crate::__juniper_insert_generic!($($scalar)*)>]>, - executor: &$crate::Executor<Self::Context, $crate::__juniper_insert_generic!($($scalar)*)>, - ) -> $crate::ExecutionResult<$crate::__juniper_insert_generic!($($scalar)*)> { - $(let $resolver_ctx = &executor.context();)* - - $( - if type_name == (<$resolver_src as $crate::GraphQLType<_>>::name(&())).unwrap() { - return executor.resolve(&(), &$resolver_expr); - } - )* - - panic!("Concrete type not handled by instance resolvers on {}", $($outname)*); - } - } - ); - }; - - - ( - @parse, - meta = {$($meta:tt)*}, - rest = $($rest:tt)* - ) => { - $crate::__juniper_parse_field_list!( - success_callback = graphql_union, - additional_parser = { - callback = __juniper_parse_instance_resolver, - header = {}, - }, - meta = {$($meta)*}, - items = [], - rest = $($rest)* - ); - }; - (@$($stuff:tt)*) => { - compile_error!("Invalid syntax for `graphql_union!`"); - }; - - ($($rest: tt)*) => { - $crate::__juniper_parse_object_header!( - callback = graphql_union, - rest = $($rest)* - ); - }; -} -*/ diff --git a/juniper/src/parser/tests/document.rs b/juniper/src/parser/tests/document.rs index cfe18d64..24f99963 100644 --- a/juniper/src/parser/tests/document.rs +++ b/juniper/src/parser/tests/document.rs @@ -6,13 +6,12 @@ use crate::{ schema::model::SchemaType, types::scalars::EmptyMutation, validation::test_harness::{MutationRoot, QueryRoot}, - value::{DefaultScalarValue, ScalarRefValue, ScalarValue}, + value::{DefaultScalarValue, ScalarValue}, }; fn parse_document<S>(s: &str) -> Document<S> where S: ScalarValue, - for<'b> &'b S: ScalarRefValue<'b>, { parse_document_source(s, &SchemaType::new::<QueryRoot, MutationRoot>(&(), &())) .expect(&format!("Parse error on input {:#?}", s)) @@ -21,7 +20,6 @@ where fn parse_document_error<'a, S>(s: &'a str) -> Spanning<ParseError<'a>> where S: ScalarValue, - for<'b> &'b S: ScalarRefValue<'b>, { match parse_document_source::<S>(s, &SchemaType::new::<QueryRoot, MutationRoot>(&(), &())) { Ok(doc) => panic!("*No* parse error on input {:#?} =>\n{:#?}", s, doc), diff --git a/juniper/src/parser/tests/value.rs b/juniper/src/parser/tests/value.rs index 87ba272f..f0c34ed0 100644 --- a/juniper/src/parser/tests/value.rs +++ b/juniper/src/parser/tests/value.rs @@ -7,7 +7,7 @@ use juniper_codegen::{ use crate::{ ast::{FromInputValue, InputValue, Type}, parser::{value::parse_value_literal, Lexer, Parser, SourcePosition, Spanning}, - value::{DefaultScalarValue, ParseScalarValue, ScalarRefValue, ScalarValue}, + value::{DefaultScalarValue, ParseScalarValue, ScalarValue}, }; use crate::{ @@ -72,7 +72,6 @@ where fn parse_value<S>(s: &str, meta: &MetaType<S>) -> Spanning<InputValue<S>> where S: ScalarValue, - for<'a> &'a S: ScalarRefValue<'a>, { let mut lexer = Lexer::new(s); let mut parser = Parser::new(&mut lexer).expect(&format!("Lexer error on input {:#?}", s)); diff --git a/juniper/src/schema/meta.rs b/juniper/src/schema/meta.rs index a15cdbf4..d8621035 100644 --- a/juniper/src/schema/meta.rs +++ b/juniper/src/schema/meta.rs @@ -10,7 +10,7 @@ use crate::{ parser::{ParseError, ScalarToken}, schema::model::SchemaType, types::base::TypeKind, - value::{DefaultScalarValue, ParseScalarValue, ScalarRefValue, ScalarValue}, + value::{DefaultScalarValue, ParseScalarValue, ScalarValue}, }; /// Whether an item is deprecated, with context. @@ -395,7 +395,6 @@ where pub fn new<T>(name: Cow<'a, str>) -> Self where T: FromInputValue<S> + ParseScalarValue<S> + 'a, - for<'b> &'b S: ScalarRefValue<'b>, { ScalarMeta { name, @@ -491,7 +490,6 @@ where pub fn new<T>(name: Cow<'a, str>, values: &[EnumValue]) -> Self where T: FromInputValue<S>, - for<'b> &'b S: ScalarRefValue<'b>, { EnumMeta { name, @@ -575,9 +573,7 @@ where { /// Build a new input type with the specified name and input fields pub fn new<T: FromInputValue<S>>(name: Cow<'a, str>, input_fields: &[Argument<'a, S>]) -> Self - where - for<'b> &'b S: ScalarRefValue<'b>, - { +where { InputObjectMeta { name, description: None, @@ -765,7 +761,6 @@ impl<'a, S: fmt::Debug> fmt::Debug for InputObjectMeta<'a, S> { fn try_parse_fn<S, T>(v: &InputValue<S>) -> bool where T: FromInputValue<S>, - for<'b> &'b S: ScalarRefValue<'b>, { <T as FromInputValue<S>>::from_input_value(v).is_some() } diff --git a/juniper/src/schema/model.rs b/juniper/src/schema/model.rs index a1c003d7..35ba4522 100644 --- a/juniper/src/schema/model.rs +++ b/juniper/src/schema/model.rs @@ -9,7 +9,7 @@ use crate::{ executor::{Context, Registry}, schema::meta::{Argument, InterfaceMeta, MetaType, ObjectMeta, PlaceholderMeta, UnionMeta}, types::{base::GraphQLType, name::Name}, - value::{DefaultScalarValue, ScalarRefValue, ScalarValue}, + value::{DefaultScalarValue, ScalarValue}, }; /// Root query node of a schema @@ -20,7 +20,6 @@ use crate::{ pub struct RootNode<'a, QueryT: GraphQLType<S>, MutationT: GraphQLType<S>, S = DefaultScalarValue> where S: ScalarValue, - for<'b> &'b S: ScalarRefValue<'b>, { #[doc(hidden)] pub query_type: QueryT, @@ -80,16 +79,12 @@ where S: ScalarValue + 'a, QueryT: GraphQLType<S, TypeInfo = ()>, MutationT: GraphQLType<S, TypeInfo = ()>, - for<'b> &'b S: ScalarRefValue<'b>, { /// Construct a new root node from query and mutation nodes /// /// If the schema should not support mutations, use the /// `new` constructor instead. - pub fn new(query_obj: QueryT, mutation_obj: MutationT) -> Self - where - for<'b> &'b S: ScalarRefValue<'b>, - { + pub fn new(query_obj: QueryT, mutation_obj: MutationT) -> Self { RootNode::new_with_info(query_obj, mutation_obj, (), ()) } } @@ -99,7 +94,6 @@ where QueryT: GraphQLType<S>, MutationT: GraphQLType<S>, S: ScalarValue + 'a, - for<'b> &'b S: ScalarRefValue<'b>, { /// Construct a new root node from query and mutation nodes, /// while also providing type info objects for the query and @@ -109,10 +103,7 @@ where mutation_obj: MutationT, query_info: QueryT::TypeInfo, mutation_info: MutationT::TypeInfo, - ) -> Self - where - for<'b> &'b S: ScalarRefValue<'b>, - { + ) -> Self { RootNode { query_type: query_obj, mutation_type: mutation_obj, @@ -132,7 +123,6 @@ impl<'a, S> SchemaType<'a, S> { S: ScalarValue + 'a, QueryT: GraphQLType<S>, MutationT: GraphQLType<S>, - for<'b> &'b S: ScalarRefValue<'b>, { let mut directives = FnvHashMap::default(); let query_type_name: String; @@ -425,7 +415,6 @@ where fn new_skip(registry: &mut Registry<'a, S>) -> DirectiveType<'a, S> where S: ScalarValue, - for<'b> &'b S: ScalarRefValue<'b>, { Self::new( "skip", @@ -441,7 +430,6 @@ where fn new_include(registry: &mut Registry<'a, S>) -> DirectiveType<'a, S> where S: ScalarValue, - for<'b> &'b S: ScalarRefValue<'b>, { Self::new( "include", diff --git a/juniper/src/schema/schema.rs b/juniper/src/schema/schema.rs index 14c3f2c2..f614daa7 100644 --- a/juniper/src/schema/schema.rs +++ b/juniper/src/schema/schema.rs @@ -2,7 +2,7 @@ use crate::{ ast::Selection, executor::{ExecutionResult, Executor, Registry}, types::base::{Arguments, GraphQLType, TypeKind}, - value::{ScalarRefValue, ScalarValue, Value}, + value::{ScalarValue, Value}, }; use crate::schema::{ @@ -18,7 +18,6 @@ where S: ScalarValue, QueryT: GraphQLType<S, Context = CtxT>, MutationT: GraphQLType<S, Context = CtxT>, - for<'b> &'b S: ScalarRefValue<'b>, { type Context = CtxT; type TypeInfo = QueryT::TypeInfo; @@ -30,7 +29,6 @@ where fn meta<'r>(info: &QueryT::TypeInfo, registry: &mut Registry<'r, S>) -> MetaType<'r, S> where S: 'r, - for<'b> &'b S: ScalarRefValue<'b>, { QueryT::meta(info, registry) } @@ -86,7 +84,6 @@ where MutationT: crate::GraphQLTypeAsync<S, Context = CtxT>, MutationT::TypeInfo: Send + Sync, CtxT: Send + Sync, - for<'b> &'b S: ScalarRefValue<'b>, { fn resolve_field_async<'b>( &'b self, diff --git a/juniper/src/tests/type_info_tests.rs b/juniper/src/tests/type_info_tests.rs index 0d7afac0..cd4f03e9 100644 --- a/juniper/src/tests/type_info_tests.rs +++ b/juniper/src/tests/type_info_tests.rs @@ -7,7 +7,7 @@ use crate::{ base::{Arguments, GraphQLType}, scalars::EmptyMutation, }, - value::{ScalarRefValue, ScalarValue, Value}, + value::{ScalarValue, Value}, }; pub struct NodeTypeInfo { @@ -22,7 +22,6 @@ pub struct Node { impl<S> GraphQLType<S> for Node where S: ScalarValue, - for<'b> &'b S: ScalarRefValue<'b>, { type Context = (); type TypeInfo = NodeTypeInfo; diff --git a/juniper/src/types/async_await.rs b/juniper/src/types/async_await.rs index d3693172..e7b0385c 100644 --- a/juniper/src/types/async_await.rs +++ b/juniper/src/types/async_await.rs @@ -1,6 +1,6 @@ use crate::{ ast::{Directive, FromInputValue, InputValue, Selection}, - value::{Object, ScalarRefValue, ScalarValue, Value}, + value::{Object, ScalarValue, Value}, }; use crate::{ @@ -17,7 +17,6 @@ where Self::Context: Send + Sync, Self::TypeInfo: Send + Sync, S: ScalarValue + Send + Sync, - for<'b> &'b S: ScalarRefValue<'b>, { fn resolve_field_async<'a>( &'a self, @@ -75,7 +74,6 @@ where S: ScalarValue + Send + Sync, CtxT: Send + Sync, 'e: 'a, - for<'b> &'b S: ScalarRefValue<'b>, { Box::pin(resolve_selection_set_into_async_recursive( instance, @@ -107,7 +105,6 @@ where T::TypeInfo: Send + Sync, S: ScalarValue + Send + Sync, CtxT: Send + Sync, - for<'b> &'b S: ScalarRefValue<'b>, { use futures::stream::{FuturesOrdered, StreamExt}; diff --git a/juniper/src/types/base.rs b/juniper/src/types/base.rs index b3705630..39fd08de 100644 --- a/juniper/src/types/base.rs +++ b/juniper/src/types/base.rs @@ -5,7 +5,7 @@ use juniper_codegen::GraphQLEnumInternal as GraphQLEnum; use crate::{ ast::{Directive, FromInputValue, InputValue, Selection}, executor::Variables, - value::{DefaultScalarValue, Object, ScalarRefValue, ScalarValue, Value}, + value::{DefaultScalarValue, Object, ScalarValue, Value}, }; use crate::{ @@ -116,7 +116,6 @@ where pub fn get<T>(&self, key: &str) -> Option<T> where T: FromInputValue<S>, - for<'b> &'b S: ScalarRefValue<'b>, { match self.args { Some(ref args) => match args.get(key) { @@ -238,7 +237,6 @@ impl GraphQLType for User pub trait GraphQLType<S = DefaultScalarValue>: Sized where S: ScalarValue, - for<'b> &'b S: ScalarRefValue<'b>, { /// The expected context type for this GraphQL type /// @@ -353,7 +351,6 @@ pub(crate) fn resolve_selection_set_into<T, CtxT, S>( where T: GraphQLType<S, Context = CtxT>, S: ScalarValue, - for<'b> &'b S: ScalarRefValue<'b>, { let meta_type = executor .schema() @@ -505,7 +502,6 @@ pub(super) fn is_excluded<S>( ) -> bool where S: ScalarValue, - for<'b> &'b S: ScalarRefValue<'b>, { if let Some(ref directives) = *directives { for &Spanning { diff --git a/juniper/src/types/containers.rs b/juniper/src/types/containers.rs index 06634072..c3051033 100644 --- a/juniper/src/types/containers.rs +++ b/juniper/src/types/containers.rs @@ -1,7 +1,7 @@ use crate::{ ast::{FromInputValue, InputValue, Selection, ToInputValue}, schema::meta::MetaType, - value::{ScalarRefValue, ScalarValue, Value}, + value::{ScalarValue, Value}, }; use crate::{ @@ -13,7 +13,6 @@ impl<S, T, CtxT> GraphQLType<S> for Option<T> where S: ScalarValue, T: GraphQLType<S, Context = CtxT>, - for<'b> &'b S: ScalarRefValue<'b>, { type Context = CtxT; type TypeInfo = T::TypeInfo; @@ -25,7 +24,6 @@ where fn meta<'r>(info: &T::TypeInfo, registry: &mut Registry<'r, S>) -> MetaType<'r, S> where S: 'r, - for<'b> &'b S: ScalarRefValue<'b>, { registry.build_nullable_type::<T>(info).into_meta() } @@ -48,10 +46,7 @@ where T: FromInputValue<S>, S: ScalarValue, { - fn from_input_value<'a>(v: &'a InputValue<S>) -> Option<Option<T>> - where - for<'b> &'b S: ScalarRefValue<'b>, - { + fn from_input_value<'a>(v: &'a InputValue<S>) -> Option<Option<T>> { match v { &InputValue::Null => Some(None), v => match v.convert() { @@ -79,7 +74,6 @@ impl<S, T, CtxT> GraphQLType<S> for Vec<T> where T: GraphQLType<S, Context = CtxT>, S: ScalarValue, - for<'b> &'b S: ScalarRefValue<'b>, { type Context = CtxT; type TypeInfo = T::TypeInfo; @@ -91,7 +85,6 @@ where fn meta<'r>(info: &T::TypeInfo, registry: &mut Registry<'r, S>) -> MetaType<'r, S> where S: 'r, - for<'b> &'b S: ScalarRefValue<'b>, { registry.build_list_type::<T>(info).into_meta() } @@ -112,9 +105,7 @@ where S: ScalarValue, { fn from_input_value<'a>(v: &'a InputValue<S>) -> Option<Vec<T>> - where - for<'b> &'b S: ScalarRefValue<'b>, - { +where { match *v { InputValue::List(ref ls) => { let v: Vec<_> = ls.iter().filter_map(|i| i.item.convert()).collect(); @@ -150,7 +141,6 @@ impl<'a, S, T, CtxT> GraphQLType<S> for &'a [T] where S: ScalarValue, T: GraphQLType<S, Context = CtxT>, - for<'b> &'b S: ScalarRefValue<'b>, { type Context = CtxT; type TypeInfo = T::TypeInfo; @@ -162,7 +152,6 @@ where fn meta<'r>(info: &T::TypeInfo, registry: &mut Registry<'r, S>) -> MetaType<'r, S> where S: 'r, - for<'b> &'b S: ScalarRefValue<'b>, { registry.build_list_type::<T>(info).into_meta() } @@ -196,7 +185,6 @@ where S: ScalarValue, I: Iterator<Item = T> + ExactSizeIterator, T: GraphQLType<S>, - for<'b> &'b S: ScalarRefValue<'b>, { let stop_on_null = executor .current_type() @@ -230,7 +218,6 @@ where T: crate::GraphQLTypeAsync<S>, T::TypeInfo: Send + Sync, T::Context: Send + Sync, - for<'b> &'b S: ScalarRefValue<'b>, { use futures::stream::{FuturesOrdered, StreamExt}; use std::iter::FromIterator; @@ -263,7 +250,6 @@ where T::TypeInfo: Send + Sync, S: ScalarValue + Send + Sync, CtxT: Send + Sync, - for<'b> &'b S: ScalarRefValue<'b>, { fn resolve_async<'a>( &'a self, @@ -283,7 +269,6 @@ where T::TypeInfo: Send + Sync, S: ScalarValue + Send + Sync, CtxT: Send + Sync, - for<'b> &'b S: ScalarRefValue<'b>, { fn resolve_async<'a>( &'a self, @@ -303,7 +288,6 @@ where T::TypeInfo: Send + Sync, S: ScalarValue + Send + Sync, CtxT: Send + Sync, - for<'b> &'b S: ScalarRefValue<'b>, { fn resolve_async<'a>( &'a self, diff --git a/juniper/src/types/pointers.rs b/juniper/src/types/pointers.rs index f5103b69..c7b37ce4 100644 --- a/juniper/src/types/pointers.rs +++ b/juniper/src/types/pointers.rs @@ -5,14 +5,13 @@ use crate::{ executor::{ExecutionResult, Executor, Registry}, schema::meta::MetaType, types::base::{Arguments, GraphQLType}, - value::{ScalarRefValue, ScalarValue, Value}, + value::{ScalarValue, Value}, }; impl<S, T, CtxT> GraphQLType<S> for Box<T> where S: ScalarValue, T: GraphQLType<S, Context = CtxT>, - for<'b> &'b S: ScalarRefValue<'b>, { type Context = CtxT; type TypeInfo = T::TypeInfo; @@ -24,7 +23,6 @@ where fn meta<'r>(info: &T::TypeInfo, registry: &mut Registry<'r, S>) -> MetaType<'r, S> where S: 'r, - for<'b> &'b S: ScalarRefValue<'b>, { T::meta(info, registry) } @@ -64,10 +62,7 @@ where S: ScalarValue, T: FromInputValue<S>, { - fn from_input_value<'a>(v: &'a InputValue<S>) -> Option<Box<T>> - where - for<'b> &'b S: ScalarRefValue<'b>, - { + fn from_input_value<'a>(v: &'a InputValue<S>) -> Option<Box<T>> { match <T as FromInputValue<S>>::from_input_value(v) { Some(v) => Some(Box::new(v)), None => None, @@ -89,7 +84,6 @@ impl<'e, S, T, CtxT> GraphQLType<S> for &'e T where S: ScalarValue, T: GraphQLType<S, Context = CtxT>, - for<'b> &'b S: ScalarRefValue<'b>, { type Context = CtxT; type TypeInfo = T::TypeInfo; @@ -101,7 +95,6 @@ where fn meta<'r>(info: &T::TypeInfo, registry: &mut Registry<'r, S>) -> MetaType<'r, S> where S: 'r, - for<'b> &'b S: ScalarRefValue<'b>, { T::meta(info, registry) } @@ -143,7 +136,6 @@ where T: crate::GraphQLTypeAsync<S>, T::TypeInfo: Send + Sync, T::Context: Send + Sync, - for<'c> &'c S: ScalarRefValue<'c>, { fn resolve_field_async<'b>( &'b self, @@ -179,7 +171,6 @@ impl<S, T> GraphQLType<S> for Arc<T> where S: ScalarValue, T: GraphQLType<S>, - for<'b> &'b S: ScalarRefValue<'b>, { type Context = T::Context; type TypeInfo = T::TypeInfo; @@ -191,7 +182,6 @@ where fn meta<'r>(info: &T::TypeInfo, registry: &mut Registry<'r, S>) -> MetaType<'r, S> where S: 'r, - for<'b> &'b S: ScalarRefValue<'b>, { T::meta(info, registry) } diff --git a/juniper/src/types/scalars.rs b/juniper/src/types/scalars.rs index e0b084fc..c828a230 100644 --- a/juniper/src/types/scalars.rs +++ b/juniper/src/types/scalars.rs @@ -7,7 +7,7 @@ use crate::{ parser::{LexerError, ParseError, ScalarToken, Token}, schema::meta::MetaType, types::base::GraphQLType, - value::{ParseScalarResult, ScalarRefValue, ScalarValue, Value}, + value::{ParseScalarResult, ScalarValue, Value}, }; /// An ID as defined by the GraphQL specification @@ -169,7 +169,6 @@ where impl<'a, S> GraphQLType<S> for &'a str where S: ScalarValue, - for<'b> &'b S: ScalarRefValue<'b>, { type Context = (); type TypeInfo = (); @@ -181,7 +180,6 @@ where fn meta<'r>(_: &(), registry: &mut Registry<'r, S>) -> MetaType<'r, S> where S: 'r, - for<'b> &'b S: ScalarRefValue<'b>, { registry.build_scalar_type::<String>(&()).into_meta() } @@ -200,7 +198,6 @@ where impl<'e, S> crate::GraphQLTypeAsync<S> for &'e str where S: ScalarValue + Send + Sync, - for<'b> &'b S: ScalarRefValue<'b>, { fn resolve_async<'a>( &'a self, @@ -314,7 +311,6 @@ unsafe impl<T> Send for EmptyMutation<T> {} impl<S, T> GraphQLType<S> for EmptyMutation<T> where S: ScalarValue, - for<'b> &'b S: ScalarRefValue<'b>, { type Context = T; type TypeInfo = (); @@ -326,7 +322,6 @@ where fn meta<'r>(_: &(), registry: &mut Registry<'r, S>) -> MetaType<'r, S> where S: 'r, - for<'b> &'b S: ScalarRefValue<'b>, { registry.build_object_type::<Self>(&(), &[]).into_meta() } @@ -340,7 +335,6 @@ where Self::TypeInfo: Send + Sync, Self::Context: Send + Sync, T: Send + Sync, - for<'b> &'b S: ScalarRefValue<'b>, { } diff --git a/juniper/src/validation/input_value.rs b/juniper/src/validation/input_value.rs index 13d4cacc..02da737a 100644 --- a/juniper/src/validation/input_value.rs +++ b/juniper/src/validation/input_value.rs @@ -9,7 +9,7 @@ use crate::{ model::{SchemaType, TypeType}, }, validation::RuleError, - value::{ScalarRefValue, ScalarValue}, + value::ScalarValue, }; #[derive(Debug)] @@ -26,7 +26,6 @@ pub fn validate_input_values<S>( ) -> Vec<RuleError> where S: ScalarValue, - for<'b> &'b S: ScalarRefValue<'b>, { let mut errs = vec![]; @@ -49,7 +48,6 @@ fn validate_var_defs<S>( errors: &mut Vec<RuleError>, ) where S: ScalarValue, - for<'b> &'b S: ScalarRefValue<'b>, { for &(ref name, ref def) in var_defs.iter() { let raw_type_name = def.var_type.item.innermost_name(); @@ -91,7 +89,6 @@ fn unify_value<'a, S>( ) -> Vec<RuleError> where S: ScalarValue, - for<'b> &'b S: ScalarRefValue<'b>, { let mut errors: Vec<RuleError> = vec![]; @@ -222,12 +219,13 @@ fn unify_enum<'a, S>( ) -> Vec<RuleError> where S: ScalarValue, - for<'b> &'b S: ScalarRefValue<'b>, { let mut errors: Vec<RuleError> = vec![]; + match *value { - InputValue::Scalar(ref scalar) if scalar.is_type::<String>() => { - if let Some(ref name) = <&S as Into<Option<&String>>>::into(scalar) { + // TODO: avoid this bad duplicate as_str() call. (value system refactor) + InputValue::Scalar(ref scalar) if scalar.as_str().is_some() => { + if let Some(ref name) = scalar.as_str() { if !meta.values.iter().any(|ev| &ev.name == *name) { errors.push(unification_error( var_name, @@ -268,7 +266,6 @@ fn unify_input_object<'a, S>( ) -> Vec<RuleError> where S: ScalarValue, - for<'b> &'b S: ScalarRefValue<'b>, { let mut errors: Vec<RuleError> = vec![]; diff --git a/juniper/src/validation/rules/overlapping_fields_can_be_merged.rs b/juniper/src/validation/rules/overlapping_fields_can_be_merged.rs index 146184c2..ae4b5b06 100644 --- a/juniper/src/validation/rules/overlapping_fields_can_be_merged.rs +++ b/juniper/src/validation/rules/overlapping_fields_can_be_merged.rs @@ -752,7 +752,7 @@ mod tests { expect_fails_rule, expect_fails_rule_with_schema, expect_passes_rule, expect_passes_rule_with_schema, RuleError, }, - value::{DefaultScalarValue, ScalarRefValue, ScalarValue}, + value::{DefaultScalarValue, ScalarValue}, }; #[test] @@ -1379,7 +1379,6 @@ mod tests { impl<S> GraphQLType<S> for SomeBox where S: ScalarValue, - for<'b> &'b S: ScalarRefValue<'b>, { type Context = (); type TypeInfo = (); @@ -1405,7 +1404,6 @@ mod tests { impl<S> GraphQLType<S> for StringBox where S: ScalarValue, - for<'b> &'b S: ScalarRefValue<'b>, { type Context = (); type TypeInfo = (); @@ -1437,7 +1435,6 @@ mod tests { impl<S> GraphQLType<S> for IntBox where S: ScalarValue, - for<'b> &'b S: ScalarRefValue<'b>, { type Context = (); type TypeInfo = (); @@ -1469,7 +1466,6 @@ mod tests { impl<S> GraphQLType<S> for NonNullStringBox1 where S: ScalarValue, - for<'b> &'b S: ScalarRefValue<'b>, { type Context = (); type TypeInfo = (); @@ -1491,7 +1487,6 @@ mod tests { impl<S> GraphQLType<S> for NonNullStringBox1Impl where S: ScalarValue, - for<'b> &'b S: ScalarRefValue<'b>, { type Context = (); type TypeInfo = (); @@ -1523,7 +1518,6 @@ mod tests { impl<S> GraphQLType<S> for NonNullStringBox2 where S: ScalarValue, - for<'b> &'b S: ScalarRefValue<'b>, { type Context = (); type TypeInfo = (); @@ -1545,7 +1539,6 @@ mod tests { impl<S> GraphQLType<S> for NonNullStringBox2Impl where S: ScalarValue, - for<'b> &'b S: ScalarRefValue<'b>, { type Context = (); type TypeInfo = (); @@ -1577,7 +1570,6 @@ mod tests { impl<S> GraphQLType<S> for Node where S: ScalarValue, - for<'b> &'b S: ScalarRefValue<'b>, { type Context = (); type TypeInfo = (); @@ -1602,7 +1594,6 @@ mod tests { impl<S> GraphQLType<S> for Edge where S: ScalarValue, - for<'b> &'b S: ScalarRefValue<'b>, { type Context = (); type TypeInfo = (); @@ -1624,7 +1615,6 @@ mod tests { impl<S> GraphQLType<S> for Connection where S: ScalarValue, - for<'b> &'b S: ScalarRefValue<'b>, { type Context = (); type TypeInfo = (); @@ -1646,7 +1636,6 @@ mod tests { impl<S> GraphQLType<S> for QueryRoot where S: ScalarValue, - for<'b> &'b S: ScalarRefValue<'b>, { type Context = (); type TypeInfo = (); diff --git a/juniper/src/validation/test_harness.rs b/juniper/src/validation/test_harness.rs index c4e076b5..9aa1d039 100644 --- a/juniper/src/validation/test_harness.rs +++ b/juniper/src/validation/test_harness.rs @@ -10,7 +10,7 @@ use crate::{ }, types::{base::GraphQLType, scalars::ID}, validation::{visit, MultiVisitorNil, RuleError, ValidatorContext, Visitor}, - value::{ScalarRefValue, ScalarValue}, + value::ScalarValue, }; struct Being; @@ -68,7 +68,6 @@ struct ComplexInput { impl<S> GraphQLType<S> for Being where S: ScalarValue, - for<'b> &'b S: ScalarRefValue<'b>, { type Context = (); type TypeInfo = (); @@ -92,7 +91,6 @@ where impl<S> GraphQLType<S> for Pet where S: ScalarValue, - for<'b> &'b S: ScalarRefValue<'b>, { type Context = (); type TypeInfo = (); @@ -116,7 +114,6 @@ where impl<S> GraphQLType<S> for Canine where S: ScalarValue, - for<'b> &'b S: ScalarRefValue<'b>, { type Context = (); type TypeInfo = (); @@ -140,7 +137,6 @@ where impl<S> GraphQLType<S> for DogCommand where S: ScalarValue, - for<'b> &'b S: ScalarRefValue<'b>, { type Context = (); type TypeInfo = (); @@ -170,10 +166,7 @@ impl<S> FromInputValue<S> for DogCommand where S: ScalarValue, { - fn from_input_value<'a>(v: &InputValue<S>) -> Option<DogCommand> - where - for<'b> &'b S: ScalarRefValue<'b>, - { + fn from_input_value<'a>(v: &InputValue<S>) -> Option<DogCommand> { match v.as_enum_value() { Some("SIT") => Some(DogCommand::Sit), Some("HEEL") => Some(DogCommand::Heel), @@ -186,7 +179,6 @@ where impl<S> GraphQLType<S> for Dog where S: ScalarValue, - for<'b> &'b S: ScalarRefValue<'b>, { type Context = (); type TypeInfo = (); @@ -232,7 +224,6 @@ where impl<S> GraphQLType<S> for FurColor where S: ScalarValue, - for<'b> &'b S: ScalarRefValue<'b>, { type Context = (); type TypeInfo = (); @@ -263,12 +254,7 @@ impl<S> FromInputValue<S> for FurColor where S: ScalarValue, { - fn from_input_value<'a>(v: &InputValue<S>) -> Option<FurColor> - where - // S: 'a, - // &'a S: ScalarRefValue<'a>, - for<'b> &'b S: ScalarRefValue<'b>, - { + fn from_input_value<'a>(v: &InputValue<S>) -> Option<FurColor> { match v.as_enum_value() { Some("BROWN") => Some(FurColor::Brown), Some("BLACK") => Some(FurColor::Black), @@ -282,7 +268,6 @@ where impl<S> GraphQLType<S> for Cat where S: ScalarValue, - for<'b> &'b S: ScalarRefValue<'b>, { type Context = (); type TypeInfo = (); @@ -315,7 +300,6 @@ where impl<S> GraphQLType<S> for CatOrDog where S: ScalarValue, - for<'b> &'b S: ScalarRefValue<'b>, { type Context = (); type TypeInfo = (); @@ -337,7 +321,6 @@ where impl<S> GraphQLType<S> for Intelligent where S: ScalarValue, - for<'b> &'b S: ScalarRefValue<'b>, { type Context = (); type TypeInfo = (); @@ -359,7 +342,6 @@ where impl<S> GraphQLType<S> for Human where S: ScalarValue, - for<'b> &'b S: ScalarRefValue<'b>, { type Context = (); type TypeInfo = (); @@ -393,7 +375,6 @@ where impl<S> GraphQLType<S> for Alien where S: ScalarValue, - for<'b> &'b S: ScalarRefValue<'b>, { type Context = (); type TypeInfo = (); @@ -427,7 +408,6 @@ where impl<S> GraphQLType<S> for DogOrHuman where S: ScalarValue, - for<'b> &'b S: ScalarRefValue<'b>, { type Context = (); type TypeInfo = (); @@ -449,7 +429,6 @@ where impl<S> GraphQLType<S> for HumanOrAlien where S: ScalarValue, - for<'b> &'b S: ScalarRefValue<'b>, { type Context = (); type TypeInfo = (); @@ -471,7 +450,6 @@ where impl<S> GraphQLType<S> for ComplexInput where S: ScalarValue, - for<'b> &'b S: ScalarRefValue<'b>, { type Context = (); type TypeInfo = (); @@ -502,11 +480,7 @@ impl<S> FromInputValue<S> for ComplexInput where S: ScalarValue, { - fn from_input_value<'a>(v: &InputValue<S>) -> Option<ComplexInput> - where - for<'b> &'b S: ScalarRefValue<'b>, // S: 'a, - // &'a S: ScalarRefValue<'a> - { + fn from_input_value<'a>(v: &InputValue<S>) -> Option<ComplexInput> { let obj = match v.to_object_value() { Some(o) => o, None => return None, @@ -528,7 +502,6 @@ where impl<S> GraphQLType<S> for ComplicatedArgs where S: ScalarValue, - for<'b> &'b S: ScalarRefValue<'b>, { type Context = (); type TypeInfo = (); @@ -592,7 +565,6 @@ where impl<S> GraphQLType<S> for QueryRoot where S: ScalarValue, - for<'b> &'b S: ScalarRefValue<'b>, { type Context = (); type TypeInfo = (); @@ -626,7 +598,6 @@ where impl<S> GraphQLType<S> for MutationRoot where S: ScalarValue, - for<'b> &'b S: ScalarRefValue<'b>, { type Context = (); type TypeInfo = (); @@ -656,7 +627,6 @@ where pub fn validate<'a, Q, M, V, F, S>(r: Q, m: M, q: &'a str, factory: F) -> Vec<RuleError> where - for<'b> &'b S: ScalarRefValue<'b>, S: ScalarValue + 'a, Q: GraphQLType<S, TypeInfo = ()>, M: GraphQLType<S, TypeInfo = ()>, @@ -709,7 +679,6 @@ where pub fn expect_passes_rule<'a, V, F, S>(factory: F, q: &'a str) where S: ScalarValue + 'a, - for<'b> &'b S: ScalarRefValue<'b>, V: Visitor<'a, S> + 'a, F: Fn() -> V, { @@ -719,7 +688,6 @@ where pub fn expect_passes_rule_with_schema<'a, Q, M, V, F, S>(r: Q, m: M, factory: F, q: &'a str) where S: ScalarValue + 'a, - for<'b> &'b S: ScalarRefValue<'b>, Q: GraphQLType<S, TypeInfo = ()>, M: GraphQLType<S, TypeInfo = ()>, V: Visitor<'a, S> + 'a, @@ -736,7 +704,6 @@ where pub fn expect_fails_rule<'a, V, F, S>(factory: F, q: &'a str, expected_errors: &[RuleError]) where S: ScalarValue + 'a, - for<'b> &'b S: ScalarRefValue<'b>, V: Visitor<'a, S> + 'a, F: Fn() -> V, { @@ -751,7 +718,6 @@ pub fn expect_fails_rule_with_schema<'a, Q, M, V, F, S>( expected_errors: &[RuleError], ) where S: ScalarValue + 'a, - for<'b> &'b S: ScalarRefValue<'b>, Q: GraphQLType<S, TypeInfo = ()>, M: GraphQLType<S, TypeInfo = ()>, V: Visitor<'a, S> + 'a, diff --git a/juniper/src/value/mod.rs b/juniper/src/value/mod.rs index dc84256d..4258ec5e 100644 --- a/juniper/src/value/mod.rs +++ b/juniper/src/value/mod.rs @@ -7,9 +7,7 @@ mod scalar; pub use self::object::Object; -pub use self::scalar::{ - DefaultScalarValue, ParseScalarResult, ParseScalarValue, ScalarRefValue, ScalarValue, -}; +pub use self::scalar::{DefaultScalarValue, ParseScalarResult, ParseScalarValue, ScalarValue}; /// Serializable value returned from query and field execution. /// @@ -104,12 +102,12 @@ where } /// View the underlying float value, if present. - #[deprecated(since = "0.11.0", note = "Use `Value::as_scalar_value` instead")] pub fn as_float_value(&self) -> Option<f64> - where - for<'a> &'a S: ScalarRefValue<'a>, - { - self.as_scalar_value::<f64>().cloned() +where { + match self { + Value::Scalar(ref s) => s.as_float(), + _ => None, + } } /// View the underlying object value, if present. @@ -155,7 +153,6 @@ where } /// View the underlying string value, if present. - #[deprecated(since = "0.11.0", note = "Use `Value::as_scalar_value` instead")] pub fn as_string_value<'a>(&'a self) -> Option<&'a str> where Option<&'a String>: From<&'a S>, diff --git a/juniper/src/value/scalar.rs b/juniper/src/value/scalar.rs index 78042591..60186e45 100644 --- a/juniper/src/value/scalar.rs +++ b/juniper/src/value/scalar.rs @@ -63,6 +63,13 @@ pub trait ParseScalarValue<S = DefaultScalarValue> { /// } /// } /// +/// fn as_str(&self) -> Option<&str> { +/// match *self { +/// MyScalarValue::String(ref s) => Some(s.as_str()), +/// _ => None, +/// } +/// } +/// /// fn as_float(&self) -> Option<f64> { /// match *self { /// MyScalarValue::Int(ref i) => Some(*i as f64), @@ -157,19 +164,7 @@ pub trait ParseScalarValue<S = DefaultScalarValue> { /// # fn main() {} /// ``` pub trait ScalarValue: - Debug - + Display - + PartialEq - + Clone - + Serialize - + From<String> - + From<bool> - + From<i32> - + From<f64> - + Into<Option<bool>> - + Into<Option<i32>> - + Into<Option<f64>> - + Into<Option<String>> + Debug + Display + PartialEq + Clone + Serialize + From<String> + From<bool> + From<i32> + From<f64> { /// Serde visitor used to deserialize this scalar value type Visitor: for<'de> de::Visitor<'de, Value = Self> + Default; @@ -206,6 +201,12 @@ pub trait ScalarValue: /// scalar values fn as_string(&self) -> Option<String>; + /// Convert the given scalar value into a string value + /// + /// This function is used for implementing `GraphQLType` for `String` for all + /// scalar values + fn as_str(&self) -> Option<&str>; + /// Convert the given scalar value into a float value /// /// This function is used for implementing `GraphQLType` for `f64` for all @@ -221,33 +222,6 @@ pub trait ScalarValue: fn as_boolean(&self) -> Option<bool>; } -/// A marker trait extending the [`ScalarValue`](../trait.ScalarValue.html) trait -/// -/// This trait should not be relied on directly by most apps. However, you may -/// need a where clause in the form of `for<'b> &'b S: ScalarRefValue<'b>` to -/// abstract over different scalar value types. -/// -/// This is automatically implemented for a type as soon as the type implements -/// `ScalarValue` and the additional conversations. -pub trait ScalarRefValue<'a>: - Debug - + Into<Option<&'a bool>> - + Into<Option<&'a i32>> - + Into<Option<&'a String>> - + Into<Option<&'a f64>> -{ -} - -impl<'a, T> ScalarRefValue<'a> for &'a T -where - T: ScalarValue, - &'a T: Into<Option<&'a bool>> - + Into<Option<&'a i32>> - + Into<Option<&'a String>> - + Into<Option<&'a f64>>, -{ -} - /// The default scalar value representation in juniper /// /// This types closely follows the graphql specification. @@ -270,13 +244,6 @@ impl ScalarValue for DefaultScalarValue { } } - fn as_string(&self) -> Option<String> { - match *self { - DefaultScalarValue::String(ref s) => Some(s.clone()), - _ => None, - } - } - fn as_float(&self) -> Option<f64> { match *self { DefaultScalarValue::Int(ref i) => Some(*i as f64), @@ -285,6 +252,20 @@ impl ScalarValue for DefaultScalarValue { } } + fn as_str(&self) -> Option<&str> { + match *self { + DefaultScalarValue::String(ref s) => Some(s.as_str()), + _ => None, + } + } + + fn as_string(&self) -> Option<String> { + match *self { + DefaultScalarValue::String(ref s) => Some(s.clone()), + _ => None, + } + } + fn as_boolean(&self) -> Option<bool> { match *self { DefaultScalarValue::Boolean(ref b) => Some(*b), diff --git a/juniper_codegen/src/derive_enum.rs b/juniper_codegen/src/derive_enum.rs index 930fe707..3f88c5cf 100644 --- a/juniper_codegen/src/derive_enum.rs +++ b/juniper_codegen/src/derive_enum.rs @@ -211,7 +211,6 @@ pub fn impl_enum(ast: &syn::DeriveInput, is_internal: bool) -> TokenStream { impl<__S> #juniper_path::GraphQLTypeAsync<__S> for #ident where __S: #juniper_path::ScalarValue + Send + Sync, - for<'__b> &'__b __S: #juniper_path::ScalarRefValue<'__b> { fn resolve_async<'a>( &'a self, @@ -234,7 +233,6 @@ pub fn impl_enum(ast: &syn::DeriveInput, is_internal: bool) -> TokenStream { impl<__S> #juniper_path::GraphQLType<__S> for #ident where __S: #juniper_path::ScalarValue, - for<'__b> &'__b __S: #juniper_path::ScalarRefValue<'__b> { type Context = (); type TypeInfo = (); @@ -268,10 +266,9 @@ pub fn impl_enum(ast: &syn::DeriveInput, is_internal: bool) -> TokenStream { impl<__S: #juniper_path::ScalarValue> #juniper_path::FromInputValue<__S> for #ident { fn from_input_value(v: &#juniper_path::InputValue<__S>) -> Option<#ident> - where for<'__b> &'__b __S: #juniper_path::ScalarRefValue<'__b> { match v.as_enum_value().or_else(|| { - v.as_scalar_value::<String>().map(|s| s as &str) + v.as_string_value() }) { #from_inputs _ => None, diff --git a/juniper_codegen/src/derive_input_object.rs b/juniper_codegen/src/derive_input_object.rs index 0f428cfd..96beb869 100644 --- a/juniper_codegen/src/derive_input_object.rs +++ b/juniper_codegen/src/derive_input_object.rs @@ -157,6 +157,25 @@ pub fn impl_input_object(ast: &syn::DeriveInput, is_internal: bool) -> TokenStre let mut from_inputs = TokenStream::new(); let mut to_inputs = TokenStream::new(); + let (_, ty_generics, _) = generics.split_for_impl(); + + let mut generics = generics.clone(); + + let scalar = if let Some(scalar) = attrs.scalar { + scalar + } else { + generics.params.push(parse_quote!(__S)); + { + let where_clause = generics.where_clause.get_or_insert(parse_quote!(where)); + where_clause + .predicates + .push(parse_quote!(__S: #juniper_path::ScalarValue)); + } + Ident::new("__S", Span::call_site()) + }; + + let (impl_generics, _, where_clause) = generics.split_for_impl(); + for field in fields { let field_ty = &field.ty; let field_attrs = ObjFieldAttrs::from_input(field); @@ -241,7 +260,7 @@ pub fn impl_input_object(ast: &syn::DeriveInput, is_internal: bool) -> TokenStre #from_input_default Some(ref v) => #juniper_path::FromInputValue::from_input_value(v).unwrap(), None => { - #juniper_path::FromInputValue::from_input_value(&#juniper_path::InputValue::null()) + #juniper_path::FromInputValue::from_input_value(&#juniper_path::InputValue::<#scalar>::null()) .unwrap() }, } @@ -254,28 +273,6 @@ pub fn impl_input_object(ast: &syn::DeriveInput, is_internal: bool) -> TokenStre }); } - let (_, ty_generics, _) = generics.split_for_impl(); - - let mut generics = generics.clone(); - - let scalar = if let Some(scalar) = attrs.scalar { - scalar - } else { - generics.params.push(parse_quote!(__S)); - { - let where_clause = generics.where_clause.get_or_insert(parse_quote!(where)); - where_clause - .predicates - .push(parse_quote!(__S: #juniper_path::ScalarValue)); - where_clause - .predicates - .push(parse_quote!(for<'__b> &'__b __S: #juniper_path::ScalarRefValue<'__b>)); - } - Ident::new("__S", Span::call_site()) - }; - - let (impl_generics, _, where_clause) = generics.split_for_impl(); - let body = quote! { impl#impl_generics #juniper_path::GraphQLType<#scalar> for #ident #ty_generics #where_clause @@ -306,8 +303,6 @@ pub fn impl_input_object(ast: &syn::DeriveInput, is_internal: bool) -> TokenStre #where_clause { fn from_input_value(value: &#juniper_path::InputValue<#scalar>) -> Option<Self> - where - for<'__b> &'__b #scalar: #juniper_path::ScalarRefValue<'__b> { if let Some(obj) = value.to_object_value() { let item = #ident { diff --git a/juniper_codegen/src/derive_scalar_value.rs b/juniper_codegen/src/derive_scalar_value.rs index dddb18f9..7805702f 100644 --- a/juniper_codegen/src/derive_scalar_value.rs +++ b/juniper_codegen/src/derive_scalar_value.rs @@ -114,7 +114,6 @@ fn impl_scalar_struct( impl<S> #crate_name::GraphQLType<S> for #ident where S: #crate_name::ScalarValue, - for<'__b> &'__b S: #crate_name::ScalarRefValue<'__b>, { type Context = (); type TypeInfo = (); @@ -128,7 +127,6 @@ fn impl_scalar_struct( registry: &mut #crate_name::Registry<'r, S>, ) -> #crate_name::meta::MetaType<'r, S> where - for<'__b> &'__b S: #crate_name::ScalarRefValue<'__b>, S: 'r, { registry.build_scalar_type::<Self>(info) @@ -149,7 +147,6 @@ fn impl_scalar_struct( impl<S> #crate_name::ToInputValue<S> for #ident where S: #crate_name::ScalarValue, - for<'__b> &'__b S: #crate_name::ScalarRefValue<'__b>, { fn to_input_value(&self) -> #crate_name::InputValue<S> { #crate_name::ToInputValue::to_input_value(&self.0) @@ -159,7 +156,6 @@ fn impl_scalar_struct( impl<S> #crate_name::FromInputValue<S> for #ident where S: #crate_name::ScalarValue, - for<'__b> &'__b S: #crate_name::ScalarRefValue<'__b>, { fn from_input_value(v: &#crate_name::InputValue<S>) -> Option<#ident> { let inner: #inner_ty = #crate_name::FromInputValue::from_input_value(v)?; @@ -170,7 +166,6 @@ fn impl_scalar_struct( impl<S> #crate_name::ParseScalarValue<S> for #ident where S: #crate_name::ScalarValue, - for<'__b> &'__b S: #crate_name::ScalarRefValue<'__b>, { fn from_str<'a>( value: #crate_name::parser::ScalarToken<'a>, diff --git a/juniper_codegen/src/impl_union.rs b/juniper_codegen/src/impl_union.rs index fa3927c1..b83826b1 100644 --- a/juniper_codegen/src/impl_union.rs +++ b/juniper_codegen/src/impl_union.rs @@ -132,19 +132,7 @@ pub fn impl_union( .map(|s| quote!( #s )) .unwrap_or_else(|| { quote! { #juniper::DefaultScalarValue } }); - let mut generics = item.generics.clone(); - if attrs.scalar.is_some() { - // A custom scalar type was specified. - // Therefore, we always insert a where clause that marks the scalar as - // compatible with ScalarValueRef. - // This is done to prevent the user from having to specify this - // manually. - let where_clause = generics.where_clause.get_or_insert(syn::parse_quote!(where)); - where_clause.predicates.push( - syn::parse_quote!(for<'__b> &'__b #scalar: #juniper::ScalarRefValue<'__b>), - ); - } - + let generics = item.generics.clone(); let (impl_generics, _, where_clause) = generics.split_for_impl(); let description = match attrs.description.as_ref() { @@ -168,7 +156,6 @@ pub fn impl_union( registry: &mut #juniper::Registry<'r, #scalar> ) -> #juniper::meta::MetaType<'r, #scalar> where - for<'__b> &'__b #scalar: #juniper::ScalarRefValue<'__b>, #scalar: 'r, { let types = &[ diff --git a/juniper_codegen/src/util.rs b/juniper_codegen/src/util.rs index ae13831f..172ee33e 100644 --- a/juniper_codegen/src/util.rs +++ b/juniper_codegen/src/util.rs @@ -809,15 +809,6 @@ impl GraphQLTypeDefiniton { let mut generics = self.generics.clone(); if self.scalar.is_some() { - // A custom scalar type was specified. - // Therefore, we always insert a where clause that marks the scalar as - // compatible with ScalarValueRef. - // This is done to prevent the user from having to specify this - // manually. - let where_clause = generics.where_clause.get_or_insert(parse_quote!(where)); - where_clause.predicates.push( - parse_quote!(for<'__b> &'__b #scalar: #juniper_crate_name::ScalarRefValue<'__b>), - ); } else if self.generic_scalar { // No custom scalar specified, but always generic specified. // Therefore we inject the generic scalar. @@ -829,12 +820,6 @@ impl GraphQLTypeDefiniton { where_clause .predicates .push(parse_quote!(__S: #juniper_crate_name::ScalarValue)); - // Insert a where clause that marks the scalar as - // compatible with ScalarValueRef. - // Same as in branch above. - where_clause - .predicates - .push(parse_quote!(for<'__b> &'__b __S: #juniper_crate_name::ScalarRefValue<'__b>)); } let type_generics_tokens = if self.include_type_generics { @@ -976,7 +961,6 @@ impl GraphQLTypeDefiniton { registry: &mut #juniper_crate_name::Registry<'r, #scalar> ) -> #juniper_crate_name::meta::MetaType<'r, #scalar> where #scalar : 'r, - for<'z> &'z #scalar: #juniper_crate_name::ScalarRefValue<'z>, { let fields = vec![ #( #field_definitions ),* diff --git a/juniper_hyper/src/lib.rs b/juniper_hyper/src/lib.rs index a1e816e2..6d0a95ba 100644 --- a/juniper_hyper/src/lib.rs +++ b/juniper_hyper/src/lib.rs @@ -11,7 +11,7 @@ use hyper::{ }; use juniper::{ http::GraphQLRequest as JuniperGraphQLRequest, serde::Deserialize, DefaultScalarValue, - GraphQLType, InputValue, RootNode, ScalarRefValue, ScalarValue, + GraphQLType, InputValue, RootNode, ScalarValue, }; use serde_json::error::Error as SerdeError; use std::{error::Error, fmt, string::FromUtf8Error, sync::Arc}; @@ -25,7 +25,6 @@ pub fn graphql<CtxT, QueryT, MutationT, S>( ) -> impl Future<Item = Response<Body>, Error = hyper::Error> where S: ScalarValue + Send + Sync + 'static, - for<'b> &'b S: ScalarRefValue<'b>, CtxT: Send + Sync + 'static, QueryT: GraphQLType<S, Context = CtxT> + Send + Sync + 'static, MutationT: GraphQLType<S, Context = CtxT> + Send + Sync + 'static, @@ -111,7 +110,6 @@ fn execute_request<CtxT, QueryT, MutationT, S>( ) -> impl Future<Item = Response<Body>, Error = tokio_threadpool::BlockingError> where S: ScalarValue + Send + Sync + 'static, - for<'b> &'b S: ScalarRefValue<'b>, CtxT: Send + Sync + 'static, QueryT: GraphQLType<S, Context = CtxT> + Send + Sync + 'static, MutationT: GraphQLType<S, Context = CtxT> + Send + Sync + 'static, @@ -212,7 +210,6 @@ where impl<S> GraphQLRequest<S> where S: ScalarValue, - for<'b> &'b S: ScalarRefValue<'b>, { fn execute<'a, CtxT: 'a, QueryT, MutationT>( self, diff --git a/juniper_iron/src/lib.rs b/juniper_iron/src/lib.rs index 678226fe..591ea985 100644 --- a/juniper_iron/src/lib.rs +++ b/juniper_iron/src/lib.rs @@ -119,7 +119,7 @@ use serde_json::error::Error as SerdeError; use juniper::{ http, serde::Deserialize, DefaultScalarValue, GraphQLType, InputValue, RootNode, - ScalarRefValue, ScalarValue, + ScalarValue, }; #[derive(serde_derive::Deserialize)] @@ -146,7 +146,6 @@ where impl<S> GraphQLBatchRequest<S> where S: ScalarValue, - for<'b> &'b S: ScalarRefValue<'b>, { pub fn execute<'a, CtxT, QueryT, MutationT>( &'a self, @@ -198,7 +197,6 @@ where pub struct GraphQLHandler<'a, CtxFactory, Query, Mutation, CtxT, S = DefaultScalarValue> where S: ScalarValue, - for<'b> &'b S: ScalarRefValue<'b>, CtxFactory: Fn(&mut Request) -> IronResult<CtxT> + Send + Sync + 'static, CtxT: 'static, Query: GraphQLType<S, Context = CtxT> + Send + Sync + 'static, @@ -253,7 +251,6 @@ impl<'a, CtxFactory, Query, Mutation, CtxT, S> GraphQLHandler<'a, CtxFactory, Query, Mutation, CtxT, S> where S: ScalarValue + 'a, - for<'b> &'b S: ScalarRefValue<'b>, CtxFactory: Fn(&mut Request) -> IronResult<CtxT> + Send + Sync + 'static, CtxT: 'static, Query: GraphQLType<S, Context = CtxT, TypeInfo = ()> + Send + Sync + 'static, @@ -340,7 +337,6 @@ impl<'a, CtxFactory, Query, Mutation, CtxT, S> Handler for GraphQLHandler<'a, CtxFactory, Query, Mutation, CtxT, S> where S: ScalarValue + Sync + Send + 'static, - for<'b> &'b S: ScalarRefValue<'b>, CtxFactory: Fn(&mut Request) -> IronResult<CtxT> + Send + Sync + 'static, CtxT: 'static, Query: GraphQLType<S, Context = CtxT, TypeInfo = ()> + Send + Sync + 'static, diff --git a/juniper_rocket/src/lib.rs b/juniper_rocket/src/lib.rs index 0deff0e6..face9b74 100644 --- a/juniper_rocket/src/lib.rs +++ b/juniper_rocket/src/lib.rs @@ -54,7 +54,7 @@ use rocket::{ use juniper::{http, InputValue}; use juniper::{ - serde::Deserialize, DefaultScalarValue, FieldError, GraphQLType, RootNode, ScalarRefValue, + serde::Deserialize, DefaultScalarValue, FieldError, GraphQLType, RootNode, ScalarValue, }; @@ -88,7 +88,6 @@ where impl<S> GraphQLBatchRequest<S> where S: ScalarValue + Send + Sync, - for<'b> &'b S: ScalarRefValue<'b>, { pub fn execute<'a, CtxT, QueryT, MutationT>( &'a self, @@ -192,7 +191,6 @@ pub fn playground_source(graphql_endpoint_url: &str) -> content::Html<String> { impl<S> GraphQLRequest<S> where S: ScalarValue + Sync + Send, - for<'b> &'b S: ScalarRefValue<'b>, { /// Execute an incoming GraphQL query pub fn execute<CtxT, QueryT, MutationT>( diff --git a/juniper_warp/src/lib.rs b/juniper_warp/src/lib.rs index 55d423fd..a68cb5d8 100644 --- a/juniper_warp/src/lib.rs +++ b/juniper_warp/src/lib.rs @@ -48,7 +48,7 @@ use warp::{filters::BoxedFilter, Filter}; #[cfg(feature = "async")] use futures03::future::{FutureExt, TryFutureExt}; -use juniper::{DefaultScalarValue, InputValue, ScalarRefValue, ScalarValue}; +use juniper::{DefaultScalarValue, InputValue, ScalarValue}; #[derive(Debug, serde_derive::Deserialize, PartialEq)] #[serde(untagged)] @@ -64,7 +64,6 @@ where impl<S> GraphQLBatchRequest<S> where S: ScalarValue, - for<'b> &'b S: ScalarRefValue<'b>, { pub fn execute<'a, CtxT, QueryT, MutationT>( &'a self, @@ -210,7 +209,6 @@ pub fn make_graphql_filter<Query, Mutation, Context, S>( ) -> BoxedFilter<(warp::http::Response<Vec<u8>>,)> where S: ScalarValue + Send + Sync + 'static, - for<'b> &'b S: ScalarRefValue<'b>, Context: Send + 'static, Query: juniper::GraphQLType<S, Context = Context, TypeInfo = ()> + Send + Sync + 'static, Mutation: juniper::GraphQLType<S, Context = Context, TypeInfo = ()> + Send + Sync + 'static, @@ -283,7 +281,6 @@ pub fn make_graphql_filter_async<Query, Mutation, Context, S>( ) -> BoxedFilter<(warp::http::Response<Vec<u8>>,)> where S: ScalarValue + Send + Sync + 'static, - for<'b> &'b S: ScalarRefValue<'b>, Context: Send + Sync + 'static, Query: juniper::GraphQLTypeAsync<S, Context = Context> + Send + Sync + 'static, Query::TypeInfo: Send + Sync,