From bde5b83eafff83b35f8c28035ed36e7d39294115 Mon Sep 17 00:00:00 2001
From: tyranron <tyranron@gmail.com>
Date: Wed, 11 May 2022 19:12:24 +0300
Subject: [PATCH] Upd

---
 juniper/src/executor/mod.rs |  2 ++
 juniper/src/resolve/mod.rs  | 59 ++++++++++++++++---------------------
 juniper/src/schema/meta.rs  |  4 +++
 juniper/src/types/ref.rs    | 15 ++++++++++
 juniper/src/types/str.rs    | 25 ++++++++--------
 5 files changed, 59 insertions(+), 46 deletions(-)

diff --git a/juniper/src/executor/mod.rs b/juniper/src/executor/mod.rs
index d749fc4a..3969befb 100644
--- a/juniper/src/executor/mod.rs
+++ b/juniper/src/executor/mod.rs
@@ -1295,6 +1295,7 @@ impl<'r, S: 'r> Registry<'r, S> {
         ScalarMeta::new::<T>(Cow::Owned(name.to_string()))
     }
 
+    /*
     /// Builds a [`ScalarMeta`] information for the specified [`graphql::Type`].
     ///
     /// [`graphql::Type`]: resolve::Type
@@ -1309,6 +1310,7 @@ impl<'r, S: 'r> Registry<'r, S> {
         // TODO: Allow using references.
         ScalarMeta::new_new::<T, _>(T::type_name(info).to_owned())
     }
+    */
 
     /// Creates a [`ListMeta`] type.
     ///
diff --git a/juniper/src/resolve/mod.rs b/juniper/src/resolve/mod.rs
index dd23fd4d..98bc3fb1 100644
--- a/juniper/src/resolve/mod.rs
+++ b/juniper/src/resolve/mod.rs
@@ -79,39 +79,32 @@ pub trait FieldAsync<Info: ?Sized, Ctx: ?Sized, S = DefaultScalarValue> {
     ) -> BoxFuture<'r, ExecutionResult<S>>;
 }
 
-pub trait InputValue<'inp, S: 'inp>: TryFrom<&'inp graphql::InputValue<S>> {
-    fn try_from_implicit_null() -> Result<Self, Self::Error> {
-        Self::try_from(&graphql::InputValue::<S>::Null)
-    }
-}
-
-pub trait InputValueOwned<S>: for<'inp> InputValue<'inp, S> {}
-
-impl<T, S> InputValueOwned<S> for T where T: for<'inp> InputValue<'inp, S> {}
-
-pub trait ValidateInputValue<S>: Sized {
-    fn validate_input_value<'inp>(
-        v: &'inp graphql::InputValue<S>,
-    ) -> Result<(), crate::FieldError<S>>
-    where
-        Self: TryFrom<&'inp graphql::InputValue<S>>,
-        <Self as TryFrom<&'inp graphql::InputValue<S>>>::Error: crate::IntoFieldError<S>;
-}
-
-impl<T, S> ValidateInputValue<S> for T {
-    fn validate_input_value<'inp>(
-        v: &'inp graphql::InputValue<S>,
-    ) -> Result<(), crate::FieldError<S>>
-    where
-        Self: TryFrom<&'inp graphql::InputValue<S>>,
-        <Self as TryFrom<&'inp graphql::InputValue<S>>>::Error: crate::IntoFieldError<S>,
-    {
-        Self::try_from(v)
-            .map(drop)
-            .map_err(crate::IntoFieldError::<S>::into_field_error)
-    }
-}
-
 pub trait ScalarToken<S = DefaultScalarValue> {
     fn parse_scalar_token(token: parser::ScalarToken<'_>) -> Result<S, ParseError<'_>>;
 }
+
+pub trait InputValue<'input, S: 'input = DefaultScalarValue>: Sized {
+    type Error;
+
+    fn try_from_input_value(v: &'input graphql::InputValue<S>) -> Result<Self, Self::Error>;
+
+    fn try_from_implicit_null() -> Result<Self, Self::Error> {
+        Self::try_from_input_value(&graphql::InputValue::<S>::Null)
+    }
+}
+
+pub trait InputValueOwned<S = DefaultScalarValue>: for<'i> InputValue<'i, S> {}
+
+impl<T, S> InputValueOwned<S> for T where T: for<'i> InputValue<'i, S> {}
+
+pub trait InputValueAsRef<S = DefaultScalarValue> {
+    type Error;
+
+    fn try_from_input_value(v: &graphql::InputValue<S>) -> Result<&Self, Self::Error>;
+
+    fn try_from_implicit_null() -> Result<&'static Self, Self::Error>
+    where S: 'static
+    {
+        Self::try_from_input_value(&graphql::InputValue::<S>::Null)
+    }
+}
diff --git a/juniper/src/schema/meta.rs b/juniper/src/schema/meta.rs
index f80afce3..fd9ff96e 100644
--- a/juniper/src/schema/meta.rs
+++ b/juniper/src/schema/meta.rs
@@ -449,6 +449,7 @@ impl<'a, S> ScalarMeta<'a, S> {
         }
     }
 
+    /*
     /// Builds a new [`ScalarMeta`] information with the specified `name`.
     // TODO: Use `impl Into<Cow<'a, str>>` argument once feature
     //       `explicit_generic_args_with_impl_trait` hits stable:
@@ -469,6 +470,7 @@ impl<'a, S> ScalarMeta<'a, S> {
             parse_fn: <T as resolve::ScalarToken<S>>::parse_scalar_token,
         }
     }
+    */
 
     /// Sets the `description` of this [`ScalarMeta`] type.
     ///
@@ -822,6 +824,7 @@ where
         .map_err(T::Error::into_field_error)
 }
 
+/*
 fn try_parse_fn_new<'inp, 'b: 'inp, S: 'inp, T>(v: &'b InputValue<S>) -> Result<(), FieldError<S>>
 where
     T: resolve::InputValue<'inp, S>,
@@ -829,3 +832,4 @@ where
 {
     T::try_from(v).map(drop).map_err(T::Error::into_field_error)
 }
+*/
diff --git a/juniper/src/types/ref.rs b/juniper/src/types/ref.rs
index 42204d89..78407fdb 100644
--- a/juniper/src/types/ref.rs
+++ b/juniper/src/types/ref.rs
@@ -151,6 +151,21 @@ where
     }
 }
 
+impl<'inp: 'me, 'me, T, S: 'inp> resolve::InputValue<'inp, S> for &'me T
+where
+    T: resolve::InputValueAsRef<S> + ?Sized,
+{
+    type Error = <T as resolve::InputValueAsRef<S>>::Error;
+
+    fn try_from_input_value(v: &'inp graphql::InputValue<S>) -> Result<Self, Self::Error> {
+        <T as resolve::InputValueAsRef<S>>::try_from_input_value(v)
+    }
+
+    fn try_from_implicit_null() -> Result<Self, Self::Error> {
+        <T as resolve::InputValueAsRef<S>>::try_from_implicit_null()
+    }
+}
+
 impl<'me, T, S> graphql::InputType<S> for &'me T
 where
     T: graphql::InputType<S> + ?Sized,
diff --git a/juniper/src/types/str.rs b/juniper/src/types/str.rs
index 1b62c3c2..08367508 100644
--- a/juniper/src/types/str.rs
+++ b/juniper/src/types/str.rs
@@ -19,7 +19,8 @@ impl<Info: ?Sized, S: ScalarValue> resolve::Type<Info, S> for str {
     where
         S: 'r,
     {
-        registry.build_scalar_type_new::<&Self, _>(info).into_meta()
+       // registry.build_scalar_type_new::<&Self, _>(info).into_meta()
+        unimplemented!()
     }
 }
 
@@ -68,11 +69,20 @@ where
 
 impl<'me, S: ScalarValue> resolve::ScalarToken<S> for str {
     fn parse_scalar_token(token: ScalarToken<'_>) -> Result<S, ParseError<'_>> {
-        // TODO: replace with `resolve::ScalarToken<S>`
+        // TODO: Replace with `resolve::ScalarToken<S>`
         <String as crate::ParseScalarValue<S>>::from_str(token)
     }
 }
 
+impl<'me, S: ScalarValue> resolve::InputValueAsRef<S> for str {
+    type Error = String;
+
+    fn try_from_input_value(v: &graphql::InputValue<S>) -> Result<&Self, Self::Error> {
+        v.as_string_value()
+            .ok_or_else(|| format!("Expected `String`, found: {}", v))
+    }
+}
+
 impl<S> graphql::InputType<S> for str {
     fn assert_input_type() {}
 }
@@ -84,14 +94,3 @@ impl<S> graphql::OutputType<S> for str {
 impl<S> graphql::Scalar<S> for str {
     fn assert_scalar() {}
 }
-
-impl<'inp: 'me, 'me, S: ScalarValue> TryFrom<&'inp graphql::InputValue<S>> for &'me str {
-    type Error = String;
-
-    fn try_from(v: &'inp graphql::InputValue<S>) -> Result<Self, Self::Error> {
-        v.as_string_value()
-            .ok_or_else(|| format!("Expected `String`, found: {}", v))
-    }
-}
-
-impl<'inp: 'me, 'me, S: ScalarValue> resolve::InputValue<'inp, S> for &'me str {}