use crate::r#type::{GQLInputValue, GQLOutputValue, GQLType}; use crate::{ContextSelectionSet, Result}; use graphql_parser::query::Value; use std::borrow::Cow; pub trait Scalar: Sized + Send { fn type_name() -> &'static str; fn parse(value: Value) -> Result; fn parse_from_json(value: serde_json::Value) -> Result; fn to_json(&self) -> Result; } impl GQLType for T { fn type_name() -> Cow<'static, str> { Cow::Borrowed(T::type_name()) } } impl GQLInputValue for T { fn parse(value: Value) -> Result { T::parse(value) } fn parse_from_json(value: serde_json::Value) -> Result { T::parse_from_json(value) } } #[async_trait::async_trait] impl GQLOutputValue for T { async fn resolve(&self, _: &ContextSelectionSet<'_>) -> Result { T::to_json(self) } }