Coverage Report

Created: 2025-02-21 07:11

/rust/registry/src/index.crates.io-6f17d22bba15001f/async-graphql-7.0.15/src/executor.rs
Line
Count
Source (jump to first uncovered line)
1
#[cfg(not(feature = "boxed-trait"))]
2
use std::future::Future;
3
use std::sync::Arc;
4
5
use futures_util::stream::{BoxStream, FuturesOrdered, StreamExt};
6
7
use crate::{BatchRequest, BatchResponse, Data, Request, Response};
8
9
/// Represents a GraphQL executor
10
#[cfg_attr(feature = "boxed-trait", async_trait::async_trait)]
11
pub trait Executor: Unpin + Clone + Send + Sync + 'static {
12
    /// Execute a GraphQL query.
13
    #[cfg(feature = "boxed-trait")]
14
    async fn execute(&self, request: Request) -> Response;
15
16
    /// Execute a GraphQL query.
17
    #[cfg(not(feature = "boxed-trait"))]
18
    fn execute(&self, request: Request) -> impl Future<Output = Response> + Send;
19
20
    /// Execute a GraphQL batch query.
21
    #[cfg(feature = "boxed-trait")]
22
    async fn execute_batch(&self, batch_request: BatchRequest) -> BatchResponse {
23
        match batch_request {
24
            BatchRequest::Single(request) => BatchResponse::Single(self.execute(request).await),
25
            BatchRequest::Batch(requests) => BatchResponse::Batch(
26
                FuturesOrdered::from_iter(
27
                    requests.into_iter().map(|request| self.execute(request)),
28
                )
29
                .collect()
30
                .await,
31
            ),
32
        }
33
    }
34
35
    /// Execute a GraphQL batch query.
36
    #[cfg(not(feature = "boxed-trait"))]
37
0
    fn execute_batch(
38
0
        &self,
39
0
        batch_request: BatchRequest,
40
0
    ) -> impl Future<Output = BatchResponse> + Send {
41
0
        async {
42
0
            match batch_request {
43
0
                BatchRequest::Single(request) => BatchResponse::Single(self.execute(request).await),
44
0
                BatchRequest::Batch(requests) => BatchResponse::Batch(
45
0
                    FuturesOrdered::from_iter(
46
0
                        requests.into_iter().map(|request| self.execute(request)),
47
0
                    )
48
0
                    .collect()
49
0
                    .await,
50
                ),
51
            }
52
0
        }
53
0
    }
54
55
    /// Execute a GraphQL subscription with session data.
56
    fn execute_stream(
57
        &self,
58
        request: Request,
59
        session_data: Option<Arc<Data>>,
60
    ) -> BoxStream<'static, Response>;
61
}