use crate::{ ContextSelectionSet, GQLInputValue, GQLOutputValue, GQLType, QueryError, Result, Value, }; use std::borrow::Cow; impl GQLType for Vec { fn type_name() -> Cow<'static, str> { Cow::Owned(format!("[{}]!", T::type_name())) } } impl GQLInputValue for Vec { fn parse(value: Value) -> Result { match value { Value::List(values) => { let mut result = Vec::new(); for value in values { result.push(GQLInputValue::parse(value)?); } Ok(result) } _ => { return Err(QueryError::ExpectedType { expect: Self::type_name(), actual: value, } .into()) } } } fn parse_from_json(value: serde_json::Value) -> Result { match value { serde_json::Value::Array(values) => { let mut result = Vec::new(); for value in values { result.push(GQLInputValue::parse_from_json(value)?); } Ok(result) } _ => { return Err(QueryError::ExpectedJsonType { expect: Self::type_name(), actual: value, } .into()) } } } } #[async_trait::async_trait] impl GQLOutputValue for Vec { async fn resolve(&self, ctx: &ContextSelectionSet<'_>) -> Result { let mut res = Vec::new(); for item in self { res.push(item.resolve(ctx).await?); } Ok(res.into()) } } impl GQLType for &[T] { fn type_name() -> Cow<'static, str> { Cow::Owned(format!("[{}]!", T::type_name())) } } #[async_trait::async_trait] impl GQLOutputValue for &[T] { async fn resolve(&self, ctx: &ContextSelectionSet<'_>) -> Result { let mut res = Vec::new(); for item in self.iter() { res.push(item.resolve(ctx).await?); } Ok(res.into()) } }