From be010e812365ae35de545dbc77f9ef3907d907b1 Mon Sep 17 00:00:00 2001 From: tyranron Date: Thu, 9 Jun 2022 16:16:30 +0200 Subject: [PATCH] Re-impl renewed traits machinery for container types --- juniper/src/executor/mod.rs | 9 +-- juniper/src/resolve/mod.rs | 6 +- juniper/src/types/arc.rs | 12 ++-- juniper/src/types/box.rs | 12 ++-- juniper/src/types/nullable.rs | 113 +++++++++++++++++++--------------- juniper/src/types/option.rs | 108 ++++++++++++++++++-------------- juniper/src/types/rc.rs | 12 ++-- juniper/src/types/ref.rs | 12 ++-- juniper/src/types/ref_mut.rs | 12 ++-- 9 files changed, 164 insertions(+), 132 deletions(-) diff --git a/juniper/src/executor/mod.rs b/juniper/src/executor/mod.rs index 7603acb1..3c6fd907 100644 --- a/juniper/src/executor/mod.rs +++ b/juniper/src/executor/mod.rs @@ -1369,12 +1369,13 @@ impl<'r, S: 'r> Registry<'r, S> { /// [`graphql::Type`]. /// /// [`graphql::Type`]: resolve::Type - pub fn build_nullable_type_new(&mut self, info: &Info) -> NullableMeta<'r> + pub fn build_nullable_type_reworked(&mut self, type_info: &TI) -> NullableMeta<'r> where - T: resolve::Type + ?Sized, - Info: ?Sized, + T: resolve::Type + ?Sized, + BH: ?Sized, + TI: ?Sized, { - NullableMeta::new(T::meta(self, info).as_type()) + NullableMeta::new(T::meta(self, type_info).as_type()) } /// Creates an [`ObjectMeta`] type with the given `fields`. diff --git a/juniper/src/resolve/mod.rs b/juniper/src/resolve/mod.rs index 206cf950..868ce500 100644 --- a/juniper/src/resolve/mod.rs +++ b/juniper/src/resolve/mod.rs @@ -162,7 +162,7 @@ pub trait InputValue<'input, ScalarValue: 'input, Behavior: ?Sized = behavior::S ) -> Result; fn try_from_implicit_null() -> Result { - Self::try_from_input_value(&graphql::InputValue::::Null) + Self::try_from_input_value(&graphql::InputValue::Null) } } @@ -182,7 +182,7 @@ pub trait InputValueAs<'input, Wrapper, ScalarValue: 'input, Behavior: ?Sized = ) -> Result; fn try_from_implicit_null() -> Result { - Self::try_from_input_value(&graphql::InputValue::::Null) + Self::try_from_input_value(&graphql::InputValue::Null) } } @@ -195,7 +195,7 @@ pub trait InputValueAsRef { where ScalarValue: 'a, { - Self::try_from_input_value(&graphql::InputValue::::Null) + Self::try_from_input_value(&graphql::InputValue::Null) } } diff --git a/juniper/src/types/arc.rs b/juniper/src/types/arc.rs index 7000e445..ef733799 100644 --- a/juniper/src/types/arc.rs +++ b/juniper/src/types/arc.rs @@ -15,11 +15,11 @@ where TI: ?Sized, BH: ?Sized, { - fn meta<'r>(registry: &mut Registry<'r, SV>, info: &TI) -> MetaType<'r, SV> + fn meta<'r>(registry: &mut Registry<'r, SV>, type_info: &TI) -> MetaType<'r, SV> where SV: 'r, { - T::meta(registry, info) + T::meta(registry, type_info) } } @@ -29,8 +29,8 @@ where TI: ?Sized, BH: ?Sized, { - fn type_name(info: &TI) -> &str { - T::type_name(info) + fn type_name(type_info: &TI) -> &str { + T::type_name(type_info) } } @@ -40,8 +40,8 @@ where TI: ?Sized, BH: ?Sized, { - fn concrete_type_name<'i>(&self, info: &'i TI) -> &'i str { - (**self).concrete_type_name(info) + fn concrete_type_name<'i>(&self, type_info: &'i TI) -> &'i str { + (**self).concrete_type_name(type_info) } } diff --git a/juniper/src/types/box.rs b/juniper/src/types/box.rs index c5257b5b..ec019461 100644 --- a/juniper/src/types/box.rs +++ b/juniper/src/types/box.rs @@ -13,11 +13,11 @@ where TI: ?Sized, BH: ?Sized, { - fn meta<'r>(registry: &mut Registry<'r, SV>, info: &TI) -> MetaType<'r, SV> + fn meta<'r>(registry: &mut Registry<'r, SV>, type_info: &TI) -> MetaType<'r, SV> where SV: 'r, { - T::meta(registry, info) + T::meta(registry, type_info) } } @@ -27,8 +27,8 @@ where TI: ?Sized, BH: ?Sized, { - fn type_name(info: &TI) -> &str { - T::type_name(info) + fn type_name(type_info: &TI) -> &str { + T::type_name(type_info) } } @@ -38,8 +38,8 @@ where TI: ?Sized, BH: ?Sized, { - fn concrete_type_name<'i>(&self, info: &'i TI) -> &'i str { - (**self).concrete_type_name(info) + fn concrete_type_name<'i>(&self, type_info: &'i TI) -> &'i str { + (**self).concrete_type_name(type_info) } } diff --git a/juniper/src/types/nullable.rs b/juniper/src/types/nullable.rs index b48064df..7728959c 100644 --- a/juniper/src/types/nullable.rs +++ b/juniper/src/types/nullable.rs @@ -272,82 +272,89 @@ impl Nullable<&mut T> { } } -/* -impl resolve::Type for Nullable +impl resolve::Type for Nullable where - T: resolve::Type, - Info: ?Sized, + T: resolve::Type, + TI: ?Sized, + BH: ?Sized, { - fn meta<'r>(registry: &mut Registry<'r, S>, info: &Info) -> MetaType<'r, S> + fn meta<'r>(registry: &mut Registry<'r, SV>, type_info: &TI) -> MetaType<'r, SV> where - S: 'r, + SV: 'r, { - registry.build_nullable_type_new::(info).into_meta() + registry + .build_nullable_type_reworked::(type_info) + .into_meta() } } -impl resolve::Value for Nullable +impl resolve::Value for Nullable where - T: resolve::Value, - Info: ?Sized, - Ctx: ?Sized, + T: resolve::Value, + TI: ?Sized, + CX: ?Sized, + BH: ?Sized, { fn resolve_value( &self, - selection_set: Option<&[Selection<'_, S>]>, - info: &Info, - executor: &Executor, - ) -> ExecutionResult { + selection_set: Option<&[Selection<'_, SV>]>, + type_info: &TI, + executor: &Executor, + ) -> ExecutionResult { match self { - Self::Some(v) => v.resolve_value(selection_set, info, executor), - Self::ExplicitNull | Self::ImplicitNull => Ok(graphql::Value::Null), + Self::Some(v) => v.resolve_value(selection_set, type_info, executor), + Self::ImplicitNull | Self::ExplicitNull => Ok(graphql::Value::Null), } } } -impl resolve::ValueAsync for Nullable +impl resolve::ValueAsync for Nullable where - T: resolve::ValueAsync, - Info: ?Sized, - Ctx: ?Sized, - S: Send, + T: resolve::ValueAsync, + TI: ?Sized, + CX: ?Sized, + SV: Send, + BH: ?Sized, { fn resolve_value_async<'r>( &'r self, - selection_set: Option<&'r [Selection<'_, S>]>, - info: &'r Info, - executor: &'r Executor, - ) -> BoxFuture<'r, ExecutionResult> { + selection_set: Option<&'r [Selection<'_, SV>]>, + type_info: &'r TI, + executor: &'r Executor, + ) -> BoxFuture<'r, ExecutionResult> { match self { - Self::Some(v) => v.resolve_value_async(selection_set, info, executor), - Self::ExplicitNull | Self::ImplicitNull => Box::pin(future::ok(graphql::Value::Null)), + Self::Some(v) => v.resolve_value_async(selection_set, type_info, executor), + Self::ImplicitNull | Self::ExplicitNull => Box::pin(future::ok(graphql::Value::Null)), } } } -impl resolve::ToInputValue for Nullable +impl resolve::ToInputValue for Nullable where - T: resolve::ToInputValue, + T: resolve::ToInputValue, + BH: ?Sized, { - fn to_input_value(&self) -> graphql::InputValue { + fn to_input_value(&self) -> graphql::InputValue { match self { Self::Some(v) => v.to_input_value(), - Self::ExplicitNull | Self::ImplicitNull => graphql::InputValue::Null, + Self::ImplicitNull | Self::ExplicitNull => graphql::InputValue::Null, } } } -impl<'inp, T, S: 'inp> resolve::InputValue<'inp, S> for Nullable +impl<'i, T, SV, BH> resolve::InputValue<'i, SV, BH> for Nullable where - T: resolve::InputValue<'inp, S>, + T: resolve::InputValue<'i, SV, BH>, + SV: 'i, + BH: ?Sized, { - type Error = >::Error; + type Error = T::Error; - fn try_from_input_value(v: &'inp InputValue) -> Result { + fn try_from_input_value(v: &'i graphql::InputValue) -> Result { if v.is_null() { Ok(Self::ExplicitNull) } else { - >::try_from_input_value(v).map(Self::Some) + T::try_from_input_value(v).map(Self::Some) } } @@ -356,47 +363,55 @@ where } } -impl<'i, T, Info, S: 'i> graphql::InputType<'i, Info, S> for Nullable +impl<'i, T, TI, SV, BH> graphql::InputType<'i, TI, SV, BH> for Nullable where - T: graphql::InputType<'i, Info, S>, - Info: ?Sized, + T: graphql::InputType<'i, TI, SV, BH>, + TI: ?Sized, + SV: 'i, + BH: ?Sized, { fn assert_input_type() { T::assert_input_type() } } -impl graphql::OutputType for Nullable +impl graphql::OutputType for Nullable where - T: graphql::OutputType, + T: graphql::OutputType, + TI: ?Sized, + CX: ?Sized, + BH: ?Sized, + Self: resolve::ValueAsync, { fn assert_output_type() { T::assert_output_type() } } -impl reflect::BaseType for Nullable +impl reflect::BaseType for Nullable where - T: reflect::BaseType, + T: reflect::BaseType, + BH: ?Sized, { const NAME: reflect::Type = T::NAME; } -impl reflect::BaseSubTypes for Nullable +impl reflect::BaseSubTypes for Nullable where - T: reflect::BaseSubTypes, + T: reflect::BaseSubTypes, + BH: ?Sized, { const NAMES: reflect::Types = T::NAMES; } -impl reflect::WrappedType for Nullable +impl reflect::WrappedType for Nullable where - T: reflect::WrappedType, + T: reflect::WrappedType, + BH: ?Sized, { const VALUE: reflect::WrappedValue = reflect::wrap::nullable(T::VALUE); } - */ //////////////////////////////////////////////////////////////////////////////// impl GraphQLType for Nullable diff --git a/juniper/src/types/option.rs b/juniper/src/types/option.rs index 7f3ef70d..0a83cc62 100644 --- a/juniper/src/types/option.rs +++ b/juniper/src/types/option.rs @@ -8,64 +8,70 @@ use crate::{ schema::meta::MetaType, BoxFuture, Selection, }; -/* -impl resolve::Type for Option + +impl resolve::Type for Option where - T: resolve::Type, - Info: ?Sized, + T: resolve::Type, + TI: ?Sized, + BH: ?Sized, { - fn meta<'r>(registry: &mut Registry<'r, S>, info: &Info) -> MetaType<'r, S> + fn meta<'r>(registry: &mut Registry<'r, SV>, type_info: &TI) -> MetaType<'r, SV> where - S: 'r, + SV: 'r, { - registry.build_nullable_type_new::(info).into_meta() + registry + .build_nullable_type_reworked::(type_info) + .into_meta() } } -impl resolve::Value for Option +impl resolve::Value for Option where - T: resolve::Value, - Info: ?Sized, - Ctx: ?Sized, + T: resolve::Value, + TI: ?Sized, + CX: ?Sized, + BH: ?Sized, { fn resolve_value( &self, - selection_set: Option<&[Selection<'_, S>]>, - info: &Info, - executor: &Executor, - ) -> ExecutionResult { + selection_set: Option<&[Selection<'_, SV>]>, + type_info: &TI, + executor: &Executor, + ) -> ExecutionResult { match self { - Some(v) => v.resolve_value(selection_set, info, executor), + Some(v) => v.resolve_value(selection_set, type_info, executor), None => Ok(graphql::Value::Null), } } } -impl resolve::ValueAsync for Option +impl resolve::ValueAsync for Option where - T: resolve::ValueAsync, - Info: ?Sized, - Ctx: ?Sized, - S: Send, + T: resolve::ValueAsync, + TI: ?Sized, + CX: ?Sized, + SV: Send, + BH: ?Sized, { fn resolve_value_async<'r>( &'r self, - selection_set: Option<&'r [Selection<'_, S>]>, - info: &'r Info, - executor: &'r Executor, - ) -> BoxFuture<'r, ExecutionResult> { + selection_set: Option<&'r [Selection<'_, SV>]>, + type_info: &'r TI, + executor: &'r Executor, + ) -> BoxFuture<'r, ExecutionResult> { match self { - Some(v) => v.resolve_value_async(selection_set, info, executor), + Some(v) => v.resolve_value_async(selection_set, type_info, executor), None => Box::pin(future::ok(graphql::Value::Null)), } } } -impl resolve::ToInputValue for Option +impl resolve::ToInputValue for Option where - T: resolve::ToInputValue, + T: resolve::ToInputValue, + BH: ?Sized, { - fn to_input_value(&self) -> graphql::InputValue { + fn to_input_value(&self) -> graphql::InputValue { match self { Some(v) => v.to_input_value(), None => graphql::InputValue::Null, @@ -73,58 +79,68 @@ where } } -impl<'inp, T, S: 'inp> resolve::InputValue<'inp, S> for Option +impl<'i, T, SV, BH> resolve::InputValue<'i, SV, BH> for Option where - T: resolve::InputValue<'inp, S>, + T: resolve::InputValue<'i, SV, BH>, + SV: 'i, + BH: ?Sized, { - type Error = >::Error; + type Error = T::Error; - fn try_from_input_value(v: &'inp graphql::InputValue) -> Result { + fn try_from_input_value(v: &'i graphql::InputValue) -> Result { if v.is_null() { Ok(None) } else { - >::try_from_input_value(v).map(Some) + T::try_from_input_value(v).map(Some) } } } -impl<'i, T, Info, S: 'i> graphql::InputType<'i, Info, S> for Option +impl<'i, T, TI, SV, BH> graphql::InputType<'i, TI, SV, BH> for Option where - T: graphql::InputType<'i, Info, S>, - Info: ?Sized, + T: graphql::InputType<'i, TI, SV, BH>, + TI: ?Sized, + SV: 'i, + BH: ?Sized, { fn assert_input_type() { T::assert_input_type() } } -impl graphql::OutputType for Option +impl graphql::OutputType for Option where - T: graphql::OutputType, + T: graphql::OutputType, + TI: ?Sized, + CX: ?Sized, + BH: ?Sized, + Self: resolve::ValueAsync, { fn assert_output_type() { T::assert_output_type() } } -impl reflect::BaseType for Option +impl reflect::BaseType for Option where - T: reflect::BaseType, + T: reflect::BaseType, + BH: ?Sized, { const NAME: reflect::Type = T::NAME; } -impl reflect::BaseSubTypes for Option +impl reflect::BaseSubTypes for Option where - T: reflect::BaseSubTypes, + T: reflect::BaseSubTypes, + BH: ?Sized, { const NAMES: reflect::Types = T::NAMES; } -impl reflect::WrappedType for Option +impl reflect::WrappedType for Option where - T: reflect::WrappedType, + T: reflect::WrappedType, + BH: ?Sized, { const VALUE: reflect::WrappedValue = reflect::wrap::nullable(T::VALUE); } -*/ diff --git a/juniper/src/types/rc.rs b/juniper/src/types/rc.rs index 53a3248f..950ec042 100644 --- a/juniper/src/types/rc.rs +++ b/juniper/src/types/rc.rs @@ -15,11 +15,11 @@ where TI: ?Sized, BH: ?Sized, { - fn meta<'r>(registry: &mut Registry<'r, SV>, info: &TI) -> MetaType<'r, SV> + fn meta<'r>(registry: &mut Registry<'r, SV>, type_info: &TI) -> MetaType<'r, SV> where SV: 'r, { - T::meta(registry, info) + T::meta(registry, type_info) } } @@ -29,8 +29,8 @@ where TI: ?Sized, BH: ?Sized, { - fn type_name(info: &TI) -> &str { - T::type_name(info) + fn type_name(type_info: &TI) -> &str { + T::type_name(type_info) } } @@ -40,8 +40,8 @@ where TI: ?Sized, BH: ?Sized, { - fn concrete_type_name<'i>(&self, info: &'i TI) -> &'i str { - (**self).concrete_type_name(info) + fn concrete_type_name<'i>(&self, type_info: &'i TI) -> &'i str { + (**self).concrete_type_name(type_info) } } diff --git a/juniper/src/types/ref.rs b/juniper/src/types/ref.rs index 7112c99b..9b9668fe 100644 --- a/juniper/src/types/ref.rs +++ b/juniper/src/types/ref.rs @@ -15,11 +15,11 @@ where TI: ?Sized, BH: ?Sized, { - fn meta<'r>(registry: &mut Registry<'r, SV>, info: &TI) -> MetaType<'r, SV> + fn meta<'r>(registry: &mut Registry<'r, SV>, type_info: &TI) -> MetaType<'r, SV> where SV: 'r, { - T::meta(registry, info) + T::meta(registry, type_info) } } @@ -29,8 +29,8 @@ where TI: ?Sized, BH: ?Sized, { - fn type_name(info: &TI) -> &str { - T::type_name(info) + fn type_name(type_info: &TI) -> &str { + T::type_name(type_info) } } @@ -40,8 +40,8 @@ where TI: ?Sized, BH: ?Sized, { - fn concrete_type_name<'i>(&self, info: &'i TI) -> &'i str { - (**self).concrete_type_name(info) + fn concrete_type_name<'i>(&self, type_info: &'i TI) -> &'i str { + (**self).concrete_type_name(type_info) } } diff --git a/juniper/src/types/ref_mut.rs b/juniper/src/types/ref_mut.rs index e3911abd..f24b96a5 100644 --- a/juniper/src/types/ref_mut.rs +++ b/juniper/src/types/ref_mut.rs @@ -15,11 +15,11 @@ where TI: ?Sized, BH: ?Sized, { - fn meta<'r>(registry: &mut Registry<'r, SV>, info: &TI) -> MetaType<'r, SV> + fn meta<'r>(registry: &mut Registry<'r, SV>, type_info: &TI) -> MetaType<'r, SV> where SV: 'r, { - T::meta(registry, info) + T::meta(registry, type_info) } } @@ -29,8 +29,8 @@ where TI: ?Sized, BH: ?Sized, { - fn type_name(info: &TI) -> &str { - T::type_name(info) + fn type_name(type_info: &TI) -> &str { + T::type_name(type_info) } } @@ -40,8 +40,8 @@ where TI: ?Sized, BH: ?Sized, { - fn concrete_type_name<'i>(&self, info: &'i TI) -> &'i str { - (**self).concrete_type_name(info) + fn concrete_type_name<'i>(&self, type_info: &'i TI) -> &'i str { + (**self).concrete_type_name(type_info) } }