subgraph/data_sources/sql/create_query/get_key_data/
mod.rs

1use bson::Document;
2use log::{debug, trace};
3
4use crate::{
5    configuration::subgraph::{
6        data_sources::sql::DialectEnum, entities::ServiceEntityConfig, SubGraphConfig,
7    },
8    data_sources::sql::SqlDataSource,
9    resolver_type::ResolverType,
10    sql_value::SqlValue,
11};
12
13use super::JoinClauses;
14
15mod parse_query_input;
16mod parse_values_input;
17
18impl SqlDataSource {
19    /// Creates vectors of keys and values parsed from the user provided input.
20    /// They persist order.
21    /// Keys and values are assocciated with where clause and value clause.
22    pub fn get_key_data(
23        input_object: &Document,
24        entity: &ServiceEntityConfig,
25        resolver_type: &ResolverType,
26        dialect: &DialectEnum,
27        subgraph_config: &SubGraphConfig,
28        disable_eager_loading: bool,
29    ) -> Result<
30        (
31            Vec<String>,
32            Vec<SqlValue>,
33            Vec<String>,
34            Vec<SqlValue>,
35            JoinClauses,
36        ),
37        async_graphql::Error,
38    > {
39        debug!("Getting Key Data From Input");
40        trace!("{:?}", input_object);
41        let (mut where_keys, mut where_values, mut value_keys, mut values, mut join_clauses) = (
42            Vec::new(),
43            Vec::new(),
44            Vec::new(),
45            Vec::new(),
46            JoinClauses(Vec::new()),
47        );
48
49        for (key, value) in input_object.iter() {
50            if key == "values" {
51                (where_keys, where_values, value_keys, values) = SqlDataSource::parse_values_input(
52                    value,
53                    where_keys,
54                    where_values,
55                    value_keys,
56                    values,
57                    entity,
58                    resolver_type,
59                    dialect,
60                )?;
61            } else if key == "query" {
62                (where_keys, where_values, join_clauses) = SqlDataSource::parse_query_input(
63                    value,
64                    where_keys,
65                    where_values,
66                    dialect,
67                    entity,
68                    subgraph_config,
69                    disable_eager_loading,
70                )?;
71            }
72        }
73
74        trace!("Completed Parsing Input Key Data");
75        trace!("Where Keys: {:?}", where_keys);
76        trace!("Where Values: {:?}", where_values);
77        trace!("Value Keys: {:?}", value_keys);
78        trace!("Values: {:?}", values);
79        trace!("Join Clauses: {:?}", join_clauses);
80
81        Ok((where_keys, where_values, value_keys, values, join_clauses))
82    }
83}