1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
use crate::{StrongBuf, Validator};

pub trait JuniperType: Validator {
    fn name() -> &'static str;
}

impl<__S, Ctx> ::juniper::GraphQLValueAsync<__S> for StrongBuf<Ctx>
where
    Ctx: JuniperType + 'static,
    Self: Sync,
    Self::TypeInfo: Sync,
    Self::Context: Sync,
    __S: ::juniper::ScalarValue + Send + Sync
{
    fn resolve_async<'a>(
        &'a self,
        info: &'a Self::TypeInfo,
        selection_set: Option<&'a [::juniper::Selection<__S>]>,
        executor: &'a ::juniper::Executor<Self::Context, __S>
    ) -> ::juniper::BoxFuture<'a, ::juniper::ExecutionResult<__S>> {
        use ::juniper::futures::future;
        let v = ::juniper::GraphQLValue::<__S>::resolve(self, info, selection_set, executor);
        Box::pin(future::ready(v))
    }
}

impl<__S, Ctx> ::juniper::GraphQLType<__S> for StrongBuf<Ctx>
where
    Ctx: JuniperType + 'static,
    __S: ::juniper::ScalarValue
{
    fn name(_: &Self::TypeInfo) -> Option<&'static str> { Some(<Ctx as JuniperType>::name()) }
    fn meta<'r>(
        info: &Self::TypeInfo,
        registry: &mut ::juniper::Registry<'r, __S>
    ) -> ::juniper::meta::MetaType<'r, __S>
    where
        __S: 'r
    {
        registry.build_scalar_type::<Self>(info).into_meta()
    }
}

impl<__S, Ctx> ::juniper::GraphQLValue<__S> for StrongBuf<Ctx>
where
    Ctx: JuniperType + 'static,
    __S: ::juniper::ScalarValue
{
    type Context = ();
    type TypeInfo = ();
    fn type_name<'__i>(&self, info: &'__i Self::TypeInfo) -> Option<&'__i str> {
        <Self as ::juniper::GraphQLType<__S>>::name(info)
    }
    fn resolve(
        &self,
        info: &(),
        selection: Option<&[::juniper::Selection<__S>]>,
        executor: &::juniper::Executor<Self::Context, __S>
    ) -> ::juniper::ExecutionResult<__S> {
        ::juniper::GraphQLValue::<__S>::resolve(self.as_str(), info, selection, executor)
    }
}

impl<__S, Ctx> ::juniper::ToInputValue<__S> for StrongBuf<Ctx>
where
    Ctx: JuniperType,
    __S: ::juniper::ScalarValue
{
    fn to_input_value(&self) -> ::juniper::InputValue<__S> {
        ::juniper::ToInputValue::<__S>::to_input_value(&self.as_str())
    }
}

impl<__S, Ctx> ::juniper::FromInputValue<__S> for StrongBuf<Ctx>
where
    Ctx: JuniperType,
    __S: ::juniper::ScalarValue
{
    fn from_input_value(v: &::juniper::InputValue<__S>) -> Option<Self> {
        let inner: String = ::juniper::FromInputValue::<__S>::from_input_value(v)?;
        Self::validate(inner).ok()
    }
}

impl<__S, Ctx> ::juniper::ParseScalarValue<__S> for StrongBuf<Ctx>
where
    Ctx: JuniperType,
    __S: ::juniper::ScalarValue
{
    fn from_str(
        value: ::juniper::parser::ScalarToken<'_>
    ) -> ::juniper::ParseScalarResult<'_, __S> {
        <String as ::juniper::ParseScalarValue<__S>>::from_str(value)
    }
}

impl<__S, Ctx> ::juniper::marker::IsOutputType<__S> for StrongBuf<Ctx>
where
    Ctx: JuniperType,
    __S: ::juniper::ScalarValue
{
}
impl<__S, Ctx> ::juniper::marker::IsInputType<__S> for StrongBuf<Ctx>
where
    Ctx: JuniperType + 'static,
    __S: ::juniper::ScalarValue
{
}