vector_api_client/test/
mod.rs1use graphql_client::GraphQLQuery;
2
3use crate::{BoxedSubscription, QueryResult};
4
5#[derive(GraphQLQuery, Debug, Copy, Clone)]
7#[graphql(
8 schema_path = "graphql/schema.json",
9 query_path = "tests/queries/component_links.graphql",
10 response_derives = "Debug"
11)]
12pub struct ComponentLinksQuery;
13
14#[derive(GraphQLQuery, Debug, Copy, Clone)]
16#[graphql(
17 schema_path = "graphql/schema.json",
18 query_path = "tests/subscriptions/errors_total.graphql",
19 response_derives = "Debug"
20)]
21pub struct ErrorsTotalSubscription;
22
23#[derive(GraphQLQuery, Debug, Copy, Clone)]
25#[graphql(
26 schema_path = "graphql/schema.json",
27 query_path = "tests/queries/file_source_metrics.graphql",
28 response_derives = "Debug"
29)]
30pub struct FileSourceMetricsQuery;
31
32#[derive(GraphQLQuery, Debug, Copy, Clone)]
34#[graphql(
35 schema_path = "graphql/schema.json",
36 query_path = "tests/queries/component_by_component_key.graphql",
37 response_derives = "Debug"
38)]
39pub struct ComponentByComponentKeyQuery;
40
41#[derive(GraphQLQuery, Debug, Copy, Clone)]
43#[graphql(
44 schema_path = "graphql/schema.json",
45 query_path = "tests/queries/components_connection.graphql",
46 response_derives = "Debug"
47)]
48pub struct ComponentsConnectionQuery;
49
50pub trait TestQueryExt {
51 async fn component_links_query(
52 &self,
53 after: Option<String>,
54 before: Option<String>,
55 first: Option<i64>,
56 last: Option<i64>,
57 ) -> crate::QueryResult<ComponentLinksQuery>;
58 async fn file_source_metrics_query(
59 &self,
60 after: Option<String>,
61 before: Option<String>,
62 first: Option<i64>,
63 last: Option<i64>,
64 ) -> crate::QueryResult<FileSourceMetricsQuery>;
65 async fn component_by_component_key_query(
66 &self,
67 component_id: &str,
68 ) -> crate::QueryResult<ComponentByComponentKeyQuery>;
69 async fn components_connection_query(
70 &self,
71 after: Option<String>,
72 before: Option<String>,
73 first: Option<i64>,
74 last: Option<i64>,
75 ) -> crate::QueryResult<ComponentsConnectionQuery>;
76}
77
78impl TestQueryExt for crate::Client {
79 async fn component_links_query(
80 &self,
81 after: Option<String>,
82 before: Option<String>,
83 first: Option<i64>,
84 last: Option<i64>,
85 ) -> QueryResult<ComponentLinksQuery> {
86 let request_body = ComponentLinksQuery::build_query(component_links_query::Variables {
87 after,
88 before,
89 first,
90 last,
91 });
92 self.query::<ComponentLinksQuery>(&request_body).await
93 }
94
95 async fn file_source_metrics_query(
96 &self,
97 after: Option<String>,
98 before: Option<String>,
99 first: Option<i64>,
100 last: Option<i64>,
101 ) -> QueryResult<FileSourceMetricsQuery> {
102 let request_body =
103 FileSourceMetricsQuery::build_query(file_source_metrics_query::Variables {
104 after,
105 before,
106 first,
107 last,
108 });
109 self.query::<FileSourceMetricsQuery>(&request_body).await
110 }
111
112 async fn component_by_component_key_query(
113 &self,
114 component_id: &str,
115 ) -> QueryResult<ComponentByComponentKeyQuery> {
116 let request_body = ComponentByComponentKeyQuery::build_query(
117 component_by_component_key_query::Variables {
118 component_id: component_id.to_string(),
119 },
120 );
121 self.query::<ComponentByComponentKeyQuery>(&request_body)
122 .await
123 }
124
125 async fn components_connection_query(
126 &self,
127 after: Option<String>,
128 before: Option<String>,
129 first: Option<i64>,
130 last: Option<i64>,
131 ) -> QueryResult<ComponentsConnectionQuery> {
132 let request_body =
133 ComponentsConnectionQuery::build_query(components_connection_query::Variables {
134 after,
135 before,
136 first,
137 last,
138 });
139 self.query::<ComponentsConnectionQuery>(&request_body).await
140 }
141}
142
143pub trait TestSubscriptionExt {
144 fn errors_total_subscription(
145 &self,
146 interval: i64,
147 ) -> crate::BoxedSubscription<ErrorsTotalSubscription>;
148}
149
150impl TestSubscriptionExt for crate::SubscriptionClient {
151 fn errors_total_subscription(
152 &self,
153 interval: i64,
154 ) -> BoxedSubscription<ErrorsTotalSubscription> {
155 let request_body =
156 ErrorsTotalSubscription::build_query(errors_total_subscription::Variables { interval });
157
158 self.start::<ErrorsTotalSubscription>(&request_body)
159 }
160}