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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
use graphql_client::GraphQLQuery;

use crate::{BoxedSubscription, QueryResult};

/// Component links query for returning linked components for sources, transforms, and sinks
#[derive(GraphQLQuery, Debug, Copy, Clone)]
#[graphql(
    schema_path = "graphql/schema.json",
    query_path = "tests/queries/component_links.graphql",
    response_derives = "Debug"
)]
pub struct ComponentLinksQuery;

/// Errors total subscription
#[derive(GraphQLQuery, Debug, Copy, Clone)]
#[graphql(
    schema_path = "graphql/schema.json",
    query_path = "tests/subscriptions/errors_total.graphql",
    response_derives = "Debug"
)]
pub struct ErrorsTotalSubscription;

/// File source metrics query
#[derive(GraphQLQuery, Debug, Copy, Clone)]
#[graphql(
    schema_path = "graphql/schema.json",
    query_path = "tests/queries/file_source_metrics.graphql",
    response_derives = "Debug"
)]
pub struct FileSourceMetricsQuery;

/// Component by id query
#[derive(GraphQLQuery, Debug, Copy, Clone)]
#[graphql(
    schema_path = "graphql/schema.json",
    query_path = "tests/queries/component_by_component_key.graphql",
    response_derives = "Debug"
)]
pub struct ComponentByComponentKeyQuery;

/// Component by id query
#[derive(GraphQLQuery, Debug, Copy, Clone)]
#[graphql(
    schema_path = "graphql/schema.json",
    query_path = "tests/queries/components_connection.graphql",
    response_derives = "Debug"
)]
pub struct ComponentsConnectionQuery;

pub trait TestQueryExt {
    async fn component_links_query(
        &self,
        after: Option<String>,
        before: Option<String>,
        first: Option<i64>,
        last: Option<i64>,
    ) -> crate::QueryResult<ComponentLinksQuery>;
    async fn file_source_metrics_query(
        &self,
        after: Option<String>,
        before: Option<String>,
        first: Option<i64>,
        last: Option<i64>,
    ) -> crate::QueryResult<FileSourceMetricsQuery>;
    async fn component_by_component_key_query(
        &self,
        component_id: &str,
    ) -> crate::QueryResult<ComponentByComponentKeyQuery>;
    async fn components_connection_query(
        &self,
        after: Option<String>,
        before: Option<String>,
        first: Option<i64>,
        last: Option<i64>,
    ) -> crate::QueryResult<ComponentsConnectionQuery>;
}

impl TestQueryExt for crate::Client {
    async fn component_links_query(
        &self,
        after: Option<String>,
        before: Option<String>,
        first: Option<i64>,
        last: Option<i64>,
    ) -> QueryResult<ComponentLinksQuery> {
        let request_body = ComponentLinksQuery::build_query(component_links_query::Variables {
            after,
            before,
            first,
            last,
        });
        self.query::<ComponentLinksQuery>(&request_body).await
    }

    async fn file_source_metrics_query(
        &self,
        after: Option<String>,
        before: Option<String>,
        first: Option<i64>,
        last: Option<i64>,
    ) -> QueryResult<FileSourceMetricsQuery> {
        let request_body =
            FileSourceMetricsQuery::build_query(file_source_metrics_query::Variables {
                after,
                before,
                first,
                last,
            });
        self.query::<FileSourceMetricsQuery>(&request_body).await
    }

    async fn component_by_component_key_query(
        &self,
        component_id: &str,
    ) -> QueryResult<ComponentByComponentKeyQuery> {
        let request_body = ComponentByComponentKeyQuery::build_query(
            component_by_component_key_query::Variables {
                component_id: component_id.to_string(),
            },
        );
        self.query::<ComponentByComponentKeyQuery>(&request_body)
            .await
    }

    async fn components_connection_query(
        &self,
        after: Option<String>,
        before: Option<String>,
        first: Option<i64>,
        last: Option<i64>,
    ) -> QueryResult<ComponentsConnectionQuery> {
        let request_body =
            ComponentsConnectionQuery::build_query(components_connection_query::Variables {
                after,
                before,
                first,
                last,
            });
        self.query::<ComponentsConnectionQuery>(&request_body).await
    }
}

pub trait TestSubscriptionExt {
    fn errors_total_subscription(
        &self,
        interval: i64,
    ) -> crate::BoxedSubscription<ErrorsTotalSubscription>;
}

impl TestSubscriptionExt for crate::SubscriptionClient {
    fn errors_total_subscription(
        &self,
        interval: i64,
    ) -> BoxedSubscription<ErrorsTotalSubscription> {
        let request_body =
            ErrorsTotalSubscription::build_query(errors_total_subscription::Variables { interval });

        self.start::<ErrorsTotalSubscription>(&request_body)
    }
}