Implemented OutputType for tokio Mutex

This commit is contained in:
Robert Nelson 2022-04-27 21:59:45 -07:00
parent 53993f7a13
commit 7e12c01f0b
3 changed files with 30 additions and 2 deletions

View File

@ -24,7 +24,7 @@ decimal = ["rust_decimal"]
cbor = ["serde_cbor"]
chrono-duration = ["chrono", "iso8601-duration"]
password-strength-validator = ["zxcvbn"]
tokio-rw-lock = ["tokio"]
tokio-sync = ["tokio"]
[dependencies]
async-graphql-derive = { path = "derive", version = "3.0.38" }

View File

@ -1,2 +1,4 @@
#[cfg(feature = "tokio-rw-lock")]
#[cfg(feature = "tokio-sync")]
mod rw_lock;
#[cfg(feature = "tokio-sync")]
mod mutex;

26
src/types/external/tokio/sync/mutex.rs vendored Normal file
View File

@ -0,0 +1,26 @@
use tokio::sync::Mutex;
use std::borrow::Cow;
use async_graphql_parser::types::Field;
use crate::{registry, ContextSelectionSet, OutputType, Positioned, ServerResult, Value};
#[async_trait::async_trait]
impl<T: OutputType> OutputType for Mutex<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.lock().await.resolve(ctx, field).await
}
}