Pave way to parse ?Sized
types from InputValue
This commit is contained in:
parent
e381602d5a
commit
5a3bd6c8a9
7 changed files with 175 additions and 39 deletions
|
@ -6,6 +6,12 @@ use crate::{
|
||||||
Selection,
|
Selection,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[doc(inline)]
|
||||||
|
pub use crate::types::{
|
||||||
|
arc::TryFromInputValue as InputValueAsArc, r#box::TryFromInputValue as InputValueAsBox,
|
||||||
|
r#ref::TryFromInputValue as InputValueAsRef, rc::TryFromInputValue as InputValueAsRc,
|
||||||
|
};
|
||||||
|
|
||||||
pub trait Type<Info: ?Sized, S = DefaultScalarValue> {
|
pub trait Type<Info: ?Sized, S = DefaultScalarValue> {
|
||||||
fn meta<'r>(registry: &mut Registry<'r, S>, info: &Info) -> MetaType<'r, S>
|
fn meta<'r>(registry: &mut Registry<'r, S>, info: &Info) -> MetaType<'r, S>
|
||||||
where
|
where
|
||||||
|
@ -95,26 +101,3 @@ pub trait InputValue<'input, S: 'input = DefaultScalarValue>: Sized {
|
||||||
pub trait InputValueOwned<S = DefaultScalarValue>: for<'i> InputValue<'i, S> {}
|
pub trait InputValueOwned<S = DefaultScalarValue>: for<'i> InputValue<'i, S> {}
|
||||||
|
|
||||||
impl<T, S> InputValueOwned<S> for T where T: 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: IntoFieldError<S>;
|
|
||||||
|
|
||||||
fn try_from_input_value(v: &graphql::InputValue<S>) -> Result<&Self, Self::Error>;
|
|
||||||
|
|
||||||
fn try_from_implicit_null<'a>() -> Result<&'a Self, Self::Error>
|
|
||||||
where
|
|
||||||
S: 'a,
|
|
||||||
{
|
|
||||||
Self::try_from_input_value(&graphql::InputValue::<S>::Null)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
impl<T, S> InputValueAsRef<S> for T where T: InputValueOwned<S> {
|
|
||||||
type Error = <T as InputValueOwned<S>>::Error;
|
|
||||||
|
|
||||||
fn try_from_input_value(v: &graphql::InputValue<S>) -> Result<&Self, Self::Error> {
|
|
||||||
<T as InputValueOwned<S>>::try_from_input_value(v).as_ref()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
|
@ -6,7 +6,8 @@ use crate::{
|
||||||
graphql,
|
graphql,
|
||||||
meta::MetaType,
|
meta::MetaType,
|
||||||
parser::{ParseError, ScalarToken},
|
parser::{ParseError, ScalarToken},
|
||||||
resolve, Arguments, BoxFuture, ExecutionResult, Executor, Registry, Selection,
|
resolve, Arguments, BoxFuture, DefaultScalarValue, ExecutionResult, Executor, IntoFieldError,
|
||||||
|
Registry, Selection,
|
||||||
};
|
};
|
||||||
|
|
||||||
impl<T, Info, S> resolve::Type<Info, S> for Arc<T>
|
impl<T, Info, S> resolve::Type<Info, S> for Arc<T>
|
||||||
|
@ -151,6 +152,48 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'inp, T, S> resolve::InputValue<'inp, S> for Arc<T>
|
||||||
|
where
|
||||||
|
T: resolve::InputValueAsArc<'inp, S> + ?Sized,
|
||||||
|
S: 'inp,
|
||||||
|
{
|
||||||
|
type Error = <T as resolve::InputValueAsArc<'inp, S>>::Error;
|
||||||
|
|
||||||
|
fn try_from_input_value(v: &'inp graphql::InputValue<S>) -> Result<Self, Self::Error> {
|
||||||
|
<T as resolve::InputValueAsArc<'inp, S>>::try_from_input_value(v)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn try_from_implicit_null() -> Result<Self, Self::Error> {
|
||||||
|
<T as resolve::InputValueAsArc<'inp, S>>::try_from_implicit_null()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait TryFromInputValue<'input, S: 'input = DefaultScalarValue> {
|
||||||
|
type Error: IntoFieldError<S>;
|
||||||
|
|
||||||
|
fn try_from_input_value(v: &'input graphql::InputValue<S>) -> Result<Arc<Self>, Self::Error>;
|
||||||
|
|
||||||
|
fn try_from_implicit_null() -> Result<Arc<Self>, Self::Error> {
|
||||||
|
Self::try_from_input_value(&graphql::InputValue::<S>::Null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'inp, T, S> TryFromInputValue<'inp, S> for T
|
||||||
|
where
|
||||||
|
T: resolve::InputValue<'inp, S>,
|
||||||
|
S: 'inp,
|
||||||
|
{
|
||||||
|
type Error = <T as resolve::InputValue<'inp, S>>::Error;
|
||||||
|
|
||||||
|
fn try_from_input_value(v: &'inp graphql::InputValue<S>) -> Result<Arc<Self>, Self::Error> {
|
||||||
|
<T as resolve::InputValue<'inp, S>>::try_from_input_value(v).map(Arc::new)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn try_from_implicit_null() -> Result<Arc<Self>, Self::Error> {
|
||||||
|
<T as resolve::InputValue<'inp, S>>::try_from_implicit_null().map(Arc::new)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T, S> graphql::InputType<S> for Arc<T>
|
impl<T, S> graphql::InputType<S> for Arc<T>
|
||||||
where
|
where
|
||||||
T: graphql::InputType<S> + ?Sized,
|
T: graphql::InputType<S> + ?Sized,
|
||||||
|
|
|
@ -4,7 +4,8 @@ use crate::{
|
||||||
graphql,
|
graphql,
|
||||||
meta::MetaType,
|
meta::MetaType,
|
||||||
parser::{ParseError, ScalarToken},
|
parser::{ParseError, ScalarToken},
|
||||||
resolve, Arguments, BoxFuture, ExecutionResult, Executor, Registry, Selection,
|
resolve, Arguments, BoxFuture, DefaultScalarValue, ExecutionResult, Executor, IntoFieldError,
|
||||||
|
Registry, Selection,
|
||||||
};
|
};
|
||||||
|
|
||||||
impl<T, Info, S> resolve::Type<Info, S> for Box<T>
|
impl<T, Info, S> resolve::Type<Info, S> for Box<T>
|
||||||
|
@ -149,19 +150,45 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: how to parse unsized?
|
impl<'inp, T, S> resolve::InputValue<'inp, S> for Box<T>
|
||||||
impl<'inp, T, S: 'inp> resolve::InputValue<'inp, S> for Box<T>
|
|
||||||
where
|
where
|
||||||
T: resolve::InputValue<'inp, S>,
|
T: resolve::InputValueAsBox<'inp, S> + ?Sized,
|
||||||
|
S: 'inp,
|
||||||
{
|
{
|
||||||
type Error = <T as resolve::InputValue<'inp, S>>::Error;
|
type Error = <T as resolve::InputValueAsBox<'inp, S>>::Error;
|
||||||
|
|
||||||
fn try_from_input_value(v: &'inp graphql::InputValue<S>) -> Result<Self, Self::Error> {
|
fn try_from_input_value(v: &'inp graphql::InputValue<S>) -> Result<Self, Self::Error> {
|
||||||
<T as resolve::InputValue<'inp, S>>::try_from_input_value(v).map(Self::new)
|
<T as resolve::InputValueAsBox<'inp, S>>::try_from_input_value(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn try_from_implicit_null() -> Result<Self, Self::Error> {
|
fn try_from_implicit_null() -> Result<Self, Self::Error> {
|
||||||
<T as resolve::InputValue<'inp, S>>::try_from_implicit_null().map(Self::new)
|
<T as resolve::InputValueAsBox<'inp, S>>::try_from_implicit_null()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait TryFromInputValue<'input, S: 'input = DefaultScalarValue> {
|
||||||
|
type Error: IntoFieldError<S>;
|
||||||
|
|
||||||
|
fn try_from_input_value(v: &'input graphql::InputValue<S>) -> Result<Box<Self>, Self::Error>;
|
||||||
|
|
||||||
|
fn try_from_implicit_null() -> Result<Box<Self>, Self::Error> {
|
||||||
|
Self::try_from_input_value(&graphql::InputValue::<S>::Null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'inp, T, S> TryFromInputValue<'inp, S> for T
|
||||||
|
where
|
||||||
|
T: resolve::InputValue<'inp, S>,
|
||||||
|
S: 'inp,
|
||||||
|
{
|
||||||
|
type Error = <T as resolve::InputValue<'inp, S>>::Error;
|
||||||
|
|
||||||
|
fn try_from_input_value(v: &'inp graphql::InputValue<S>) -> Result<Box<Self>, Self::Error> {
|
||||||
|
<T as resolve::InputValue<'inp, S>>::try_from_input_value(v).map(Box::new)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn try_from_implicit_null() -> Result<Box<Self>, Self::Error> {
|
||||||
|
<T as resolve::InputValue<'inp, S>>::try_from_implicit_null().map(Box::new)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
mod arc;
|
pub mod arc;
|
||||||
mod array;
|
mod array;
|
||||||
mod r#box;
|
pub mod r#box;
|
||||||
pub mod iter;
|
pub mod iter;
|
||||||
mod nullable;
|
mod nullable;
|
||||||
mod option;
|
mod option;
|
||||||
mod rc;
|
pub mod rc;
|
||||||
mod r#ref;
|
pub mod r#ref;
|
||||||
mod ref_mut;
|
mod ref_mut;
|
||||||
mod slice;
|
mod slice;
|
||||||
mod r#str;
|
mod r#str;
|
||||||
|
|
|
@ -6,7 +6,8 @@ use crate::{
|
||||||
graphql,
|
graphql,
|
||||||
meta::MetaType,
|
meta::MetaType,
|
||||||
parser::{ParseError, ScalarToken},
|
parser::{ParseError, ScalarToken},
|
||||||
resolve, Arguments, BoxFuture, ExecutionResult, Executor, Registry, Selection,
|
resolve, Arguments, BoxFuture, DefaultScalarValue, ExecutionResult, Executor, IntoFieldError,
|
||||||
|
Registry, Selection,
|
||||||
};
|
};
|
||||||
|
|
||||||
impl<T, Info, S> resolve::Type<Info, S> for Rc<T>
|
impl<T, Info, S> resolve::Type<Info, S> for Rc<T>
|
||||||
|
@ -151,6 +152,48 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'inp, T, S> resolve::InputValue<'inp, S> for Rc<T>
|
||||||
|
where
|
||||||
|
T: resolve::InputValueAsRc<'inp, S> + ?Sized,
|
||||||
|
S: 'inp,
|
||||||
|
{
|
||||||
|
type Error = <T as resolve::InputValueAsRc<'inp, S>>::Error;
|
||||||
|
|
||||||
|
fn try_from_input_value(v: &'inp graphql::InputValue<S>) -> Result<Self, Self::Error> {
|
||||||
|
<T as resolve::InputValueAsRc<'inp, S>>::try_from_input_value(v)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn try_from_implicit_null() -> Result<Self, Self::Error> {
|
||||||
|
<T as resolve::InputValueAsRc<'inp, S>>::try_from_implicit_null()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait TryFromInputValue<'input, S: 'input = DefaultScalarValue> {
|
||||||
|
type Error: IntoFieldError<S>;
|
||||||
|
|
||||||
|
fn try_from_input_value(v: &'input graphql::InputValue<S>) -> Result<Rc<Self>, Self::Error>;
|
||||||
|
|
||||||
|
fn try_from_implicit_null() -> Result<Rc<Self>, Self::Error> {
|
||||||
|
Self::try_from_input_value(&graphql::InputValue::<S>::Null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'inp, T, S> TryFromInputValue<'inp, S> for T
|
||||||
|
where
|
||||||
|
T: resolve::InputValue<'inp, S>,
|
||||||
|
S: 'inp,
|
||||||
|
{
|
||||||
|
type Error = <T as resolve::InputValue<'inp, S>>::Error;
|
||||||
|
|
||||||
|
fn try_from_input_value(v: &'inp graphql::InputValue<S>) -> Result<Rc<Self>, Self::Error> {
|
||||||
|
<T as resolve::InputValue<'inp, S>>::try_from_input_value(v).map(Rc::new)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn try_from_implicit_null() -> Result<Rc<Self>, Self::Error> {
|
||||||
|
<T as resolve::InputValue<'inp, S>>::try_from_implicit_null().map(Rc::new)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T, S> graphql::InputType<S> for Rc<T>
|
impl<T, S> graphql::InputType<S> for Rc<T>
|
||||||
where
|
where
|
||||||
T: graphql::InputType<S> + ?Sized,
|
T: graphql::InputType<S> + ?Sized,
|
||||||
|
|
|
@ -6,7 +6,8 @@ use crate::{
|
||||||
graphql,
|
graphql,
|
||||||
meta::MetaType,
|
meta::MetaType,
|
||||||
parser::{ParseError, ScalarToken},
|
parser::{ParseError, ScalarToken},
|
||||||
resolve, Arguments, BoxFuture, ExecutionResult, Executor, Registry, Selection,
|
resolve, Arguments, BoxFuture, DefaultScalarValue, ExecutionResult, Executor, IntoFieldError,
|
||||||
|
Registry, Selection,
|
||||||
};
|
};
|
||||||
|
|
||||||
impl<'me, T, Info, S> resolve::Type<Info, S> for &'me T
|
impl<'me, T, Info, S> resolve::Type<Info, S> for &'me T
|
||||||
|
@ -166,6 +167,19 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait TryFromInputValue<S = DefaultScalarValue> {
|
||||||
|
type Error: IntoFieldError<S>;
|
||||||
|
|
||||||
|
fn try_from_input_value(v: &graphql::InputValue<S>) -> Result<&Self, Self::Error>;
|
||||||
|
|
||||||
|
fn try_from_implicit_null<'a>() -> Result<&'a Self, Self::Error>
|
||||||
|
where
|
||||||
|
S: 'a,
|
||||||
|
{
|
||||||
|
Self::try_from_input_value(&graphql::InputValue::<S>::Null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'me, T, S> graphql::InputType<S> for &'me T
|
impl<'me, T, S> graphql::InputType<S> for &'me T
|
||||||
where
|
where
|
||||||
T: graphql::InputType<S> + ?Sized,
|
T: graphql::InputType<S> + ?Sized,
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
//!
|
//!
|
||||||
//! [`str`]: primitive@std::str
|
//! [`str`]: primitive@std::str
|
||||||
|
|
||||||
|
use std::{sync::Arc, rc::Rc};
|
||||||
|
|
||||||
use futures::future;
|
use futures::future;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -65,14 +67,14 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'me, S: ScalarValue> resolve::ScalarToken<S> for str {
|
impl<S: ScalarValue> resolve::ScalarToken<S> for str {
|
||||||
fn parse_scalar_token(token: ScalarToken<'_>) -> Result<S, ParseError<'_>> {
|
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)
|
<String as crate::ParseScalarValue<S>>::from_str(token)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'me, S: ScalarValue> resolve::InputValueAsRef<S> for str {
|
impl<S: ScalarValue> resolve::InputValueAsRef<S> for str {
|
||||||
type Error = String;
|
type Error = String;
|
||||||
|
|
||||||
fn try_from_input_value(v: &graphql::InputValue<S>) -> Result<&Self, Self::Error> {
|
fn try_from_input_value(v: &graphql::InputValue<S>) -> Result<&Self, Self::Error> {
|
||||||
|
@ -81,6 +83,30 @@ impl<'me, S: ScalarValue> resolve::InputValueAsRef<S> for str {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'inp, S: ScalarValue> resolve::InputValueAsBox<'inp, S> for str {
|
||||||
|
type Error = String;
|
||||||
|
|
||||||
|
fn try_from_input_value(v: &'inp graphql::InputValue<S>) -> Result<Box<Self>, Self::Error> {
|
||||||
|
<str as resolve::InputValueAsRef<S>>::try_from_input_value(v).map(Into::into)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'inp, S: ScalarValue> resolve::InputValueAsArc<'inp, S> for str {
|
||||||
|
type Error = String;
|
||||||
|
|
||||||
|
fn try_from_input_value(v: &'inp graphql::InputValue<S>) -> Result<Arc<Self>, Self::Error> {
|
||||||
|
<str as resolve::InputValueAsRef<S>>::try_from_input_value(v).map(Into::into)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'inp, S: ScalarValue> resolve::InputValueAsRc<'inp, S> for str {
|
||||||
|
type Error = String;
|
||||||
|
|
||||||
|
fn try_from_input_value(v: &'inp graphql::InputValue<S>) -> Result<Rc<Self>, Self::Error> {
|
||||||
|
<str as resolve::InputValueAsRef<S>>::try_from_input_value(v).map(Into::into)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<S> graphql::InputType<S> for str {
|
impl<S> graphql::InputType<S> for str {
|
||||||
fn assert_input_type() {}
|
fn assert_input_type() {}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue