Implemented OutputType for tokio RwLock
This commit is contained in:
parent
1ba5113cd5
commit
53993f7a13
|
@ -24,6 +24,7 @@ decimal = ["rust_decimal"]
|
||||||
cbor = ["serde_cbor"]
|
cbor = ["serde_cbor"]
|
||||||
chrono-duration = ["chrono", "iso8601-duration"]
|
chrono-duration = ["chrono", "iso8601-duration"]
|
||||||
password-strength-validator = ["zxcvbn"]
|
password-strength-validator = ["zxcvbn"]
|
||||||
|
tokio-rw-lock = ["tokio"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
async-graphql-derive = { path = "derive", version = "3.0.38" }
|
async-graphql-derive = { path = "derive", version = "3.0.38" }
|
||||||
|
@ -66,6 +67,7 @@ rust_decimal = { version = "1.14.3", optional = true }
|
||||||
url = { version = "2.2.1", optional = true }
|
url = { version = "2.2.1", optional = true }
|
||||||
smol_str = { version = "0.1.21", optional = true }
|
smol_str = { version = "0.1.21", optional = true }
|
||||||
time = { version = "0.3.5", optional = true, features = ["parsing", "formatting", "macros"] }
|
time = { version = "0.3.5", optional = true, features = ["parsing", "formatting", "macros"] }
|
||||||
|
tokio = { version = "1.17.0", features = ["sync"], optional = true }
|
||||||
|
|
||||||
# Non-feature optional dependencies
|
# Non-feature optional dependencies
|
||||||
blocking = { version = "1.0.2", optional = true }
|
blocking = { version = "1.0.2", optional = true }
|
||||||
|
|
1
src/types/external/mod.rs
vendored
1
src/types/external/mod.rs
vendored
|
@ -11,6 +11,7 @@ mod list;
|
||||||
mod non_zero_integers;
|
mod non_zero_integers;
|
||||||
mod optional;
|
mod optional;
|
||||||
mod string;
|
mod string;
|
||||||
|
mod tokio;
|
||||||
|
|
||||||
#[cfg(feature = "bson")]
|
#[cfg(feature = "bson")]
|
||||||
mod bson;
|
mod bson;
|
||||||
|
|
1
src/types/external/tokio/mod.rs
vendored
Normal file
1
src/types/external/tokio/mod.rs
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
pub mod sync;
|
2
src/types/external/tokio/sync/mod.rs
vendored
Normal file
2
src/types/external/tokio/sync/mod.rs
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
#[cfg(feature = "tokio-rw-lock")]
|
||||||
|
mod rw_lock;
|
26
src/types/external/tokio/sync/rw_lock.rs
vendored
Normal file
26
src/types/external/tokio/sync/rw_lock.rs
vendored
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
use tokio::sync::RwLock;
|
||||||
|
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 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
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user