Skip to content

Commit

Permalink
Implemented OutputType for tokio Mutex
Browse files Browse the repository at this point in the history
  • Loading branch information
boardmaster357 committed Apr 28, 2022
1 parent d70daee commit d0b9c94
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
4 changes: 3 additions & 1 deletion src/types/external/tokio/sync/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
#[cfg(feature = "tokio-rw-lock")]
#[cfg(feature = "tokio-sync")]
mod rw_lock;
#[cfg(feature = "tokio-sync")]
mod mutex;
26 changes: 26 additions & 0 deletions src/types/external/tokio/sync/mutex.rs
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit d0b9c94

Please sign in to comment.