Upd
This commit is contained in:
parent
72cd4be715
commit
bde5b83eaf
5 changed files with 59 additions and 46 deletions
|
@ -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.
|
||||
///
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
*/
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 {}
|
||||
|
|
Loading…
Reference in a new issue