use crate::schema; use crate::{ContextSelectionSet, GQLOutputValue, GQLType, QueryError, Result, Scalar, Value}; use std::borrow::Cow; impl Scalar for String { fn type_name() -> &'static str { "String!" } fn parse(value: Value) -> Result { match value { Value::String(s) => Ok(s), _ => { return Err(QueryError::ExpectedType { expect: ::type_name(), actual: value, } .into()) } } } fn parse_from_json(value: serde_json::Value) -> Result { match value { serde_json::Value::String(s) => Ok(s), _ => { return Err(QueryError::ExpectedJsonType { expect: ::type_name(), actual: value, } .into()) } } } fn to_json(&self) -> Result { Ok(self.clone().into()) } } impl<'a> GQLType for &'a str { fn type_name() -> Cow<'static, str> { Cow::Borrowed("String!") } fn create_type_info(registry: &mut schema::Registry) -> String { registry.create_type(&Self::type_name(), |_| schema::Type::Scalar) } } #[async_trait::async_trait] impl<'a> GQLOutputValue for &'a str { async fn resolve(&self, _: &ContextSelectionSet<'_>) -> Result { Ok(self.to_string().into()) } }