async-graphql/src/types/external/tokio/sync/rw_lock.rs
2022-05-01 09:59:13 +08:00

26 lines
660 B
Rust

use std::borrow::Cow;
use async_graphql_parser::types::Field;
use tokio::sync::RwLock;
use crate::{registry, ContextSelectionSet, OutputType, Positioned, ServerResult, Value};
#[async_trait::async_trait]
impl<T: OutputType> OutputType for RwLock<T> {
fn type_name() -> Cow<'static, str> {
T::type_name()
}
fn create_type_info(registry: &mut registry::Registry) -> String {
<T as OutputType>::create_type_info(registry)
}
async fn resolve(
&self,
ctx: &ContextSelectionSet<'_>,
field: &Positioned<Field>,
) -> ServerResult<Value> {
self.read().await.resolve(ctx, field).await
}
}