Implemented OutputType for tokio Mutex
This commit is contained in:
parent
53993f7a13
commit
7e12c01f0b
|
@ -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" }
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
#[cfg(feature = "tokio-rw-lock")]
|
||||
#[cfg(feature = "tokio-sync")]
|
||||
mod rw_lock;
|
||||
#[cfg(feature = "tokio-sync")]
|
||||
mod mutex;
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue