1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
use std::borrow::Cow;

use async_graphql_parser::types::Field;
use tokio::sync::Mutex;

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
    }
}