hive_router_plan_executor/executors/
common.rs1use std::{collections::HashMap, sync::Arc};
2
3use async_trait::async_trait;
4use bytes::Bytes;
5use http::HeaderMap;
6use sonic_rs::Value;
7
8#[async_trait]
9pub trait SubgraphExecutor {
10 async fn execute<'a>(
11 &self,
12 execution_request: HttpExecutionRequest<'a>,
13 ) -> HttpExecutionResponse;
14 fn to_boxed_arc<'a>(self) -> Arc<Box<dyn SubgraphExecutor + Send + Sync + 'a>>
15 where
16 Self: Sized + Send + Sync + 'a,
17 {
18 Arc::new(Box::new(self))
19 }
20}
21
22pub type SubgraphExecutorType = dyn crate::executors::common::SubgraphExecutor + Send + Sync;
23
24pub type SubgraphExecutorBoxedArc = Arc<Box<SubgraphExecutorType>>;
25
26pub type SubgraphRequestExtensions = HashMap<String, Value>;
27
28pub struct HttpExecutionRequest<'a> {
29 pub query: &'a str,
30 pub dedupe: bool,
31 pub operation_name: Option<&'a str>,
32 pub variables: Option<HashMap<&'a str, &'a sonic_rs::Value>>,
34 pub headers: HeaderMap,
35 pub representations: Option<Vec<u8>>,
36 pub extensions: Option<SubgraphRequestExtensions>,
37}
38
39impl HttpExecutionRequest<'_> {
40 pub fn add_request_extensions_field(&mut self, key: String, value: Value) {
41 self.extensions
42 .get_or_insert_with(HashMap::new)
43 .insert(key, value);
44 }
45}
46
47pub struct HttpExecutionResponse {
48 pub body: Bytes,
49 pub headers: HeaderMap,
50}