Skip to content

Commit

Permalink
[WIP] add empty arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
codingkarthik committed Sep 20, 2024
1 parent ba7d90c commit 0f9ea8b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 35 deletions.
6 changes: 3 additions & 3 deletions crates/ndc-sqlserver/src/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use std::sync::Arc;
use async_trait::async_trait;
use configuration::environment::Environment;
use ndc_sdk::connector;
use ndc_sdk::connector::{Connector, ConnectorSetup, Result};
use ndc_sdk::json_response::JsonResponse;
use ndc_sdk::models;
use tokio::fs;
Expand Down Expand Up @@ -43,7 +44,7 @@ impl<Env: Environment + Send + Sync> connector::ConnectorSetup for SQLServerSetu
async fn parse_configuration(

Check warning on line 44 in crates/ndc-sqlserver/src/connector.rs

View workflow job for this annotation

GitHub Actions / cargo fmt

Diff in /home/runner/work/ndc-sqlserver/ndc-sqlserver/crates/ndc-sqlserver/src/connector.rs
&self,
configuration_dir: impl AsRef<Path> + Send,
) -> Result<<Self::Connector as connector::Connector>::Configuration, connector::ParseError>
) -> Result<<Self::Connector as connector::Connector>::Configuration>
{
let configuration_file = configuration_dir
.as_ref()
Expand All @@ -52,8 +53,7 @@ impl<Env: Environment + Send + Sync> connector::ConnectorSetup for SQLServerSetu
fs::read_to_string(&configuration_file)
.await
.map_err(|err| {
connector::ParseError::Other(
format!("{}: {}", &configuration_file.display(), err).into(),
connector::ParseError::CouldNotFindConfiguration(configuration_file
)
})?;
let configuration: configuration::RawConfiguration =
Expand Down
20 changes: 1 addition & 19 deletions crates/ndc-sqlserver/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,26 +70,8 @@ fn plan_query(
async fn execute_query(
state: &configuration::State,
plan: sql::execution_plan::QueryExecutionPlan,
) -> Result<JsonResponse<models::QueryResponse>, connector::QueryError> {
) -> Result<JsonResponse<models::QueryResponse>, query_engine_execution::error::Error> {
query::mssql_execute_query_plan(&state.mssql_pool, &state.metrics, plan)
.await
.map(JsonResponse::Serialized)
.map_err(|err| match err {
error::Error::Query(err) => {
tracing::error!("{}", err);
connector::QueryError::Other(err.into())
}
error::Error::ConnectionPool(err) => {
tracing::error!("{}", err);
connector::QueryError::Other(err.into())
}
error::Error::TiberiusError(err) => {
tracing::error!("{}", err);
connector::QueryError::Other(err.into())
}
error::Error::Mutation(err) => {
tracing::error!("{}", err);
connector::QueryError::Other(err.into())
}
})
}
37 changes: 24 additions & 13 deletions crates/ndc-sqlserver/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ enum SchemaError {

Check warning on line 24 in crates/ndc-sqlserver/src/schema.rs

View workflow job for this annotation

GitHub Actions / cargo fmt

Diff in /home/runner/work/ndc-sqlserver/ndc-sqlserver/crates/ndc-sqlserver/src/schema.rs
fn scalar_type_to_type(type_name: String, nullability: &metadata::Nullable) -> models::Type {
match nullability {
metadata::Nullable::NonNullable => models::Type::Named { name: type_name },
metadata::Nullable::NonNullable => models::Type::Named { name: type_name.into() },
metadata::Nullable::Nullable => models::Type::Nullable {
underlying_type: Box::new(models::Type::Named { name: type_name }),
underlying_type: Box::new(models::Type::Named { name: type_name.into() }),
},
}
}
Expand All @@ -42,7 +42,7 @@ fn column_to_type(column: &metadata::ColumnInfo) -> models::Type {
fn get_native_queries_schema(
native_queries: &query_engine_metadata::metadata::NativeQueries,
object_types: &mut BTreeMap<String, models::ObjectType>,
) -> Result<Vec<models::CollectionInfo>, connector::SchemaError> {
) -> Vec<models::CollectionInfo> {
let mut read_only_native_queries = Vec::new();

native_queries.0.iter().for_each(|(name, info)| {
Expand All @@ -54,36 +54,37 @@ fn get_native_queries_schema(
models::ObjectField {
description: column.description.clone(),
r#type: column_to_type(column),
arguments: BTreeMap::new(),
},
)
})),
};
object_types.insert(name.clone(), native_query_object_type);

let native_query_collection_info = models::CollectionInfo {
name: name.clone(),
name: name.as_str().into(),
description: info.description.clone(),
arguments: info
.arguments
.iter()
.map(|(name, column_info)| {
(
name.clone(),
name.as_str().into(),
models::ArgumentInfo {
description: column_info.description.clone(),
argument_type: column_to_type(column_info),
},
)
})
.collect(),
collection_type: name.clone(),
collection_type: name.as_str().into(),
uniqueness_constraints: BTreeMap::new(),
foreign_keys: BTreeMap::new(),
};
read_only_native_queries.push(native_query_collection_info);
});

Ok(read_only_native_queries)
read_only_native_queries
}

/// Build a `ProcedureInfo` type from the given parameters.
Expand Down Expand Up @@ -122,8 +123,9 @@ fn make_procedure_type(
models::ObjectField {
description: Some("The number of rows affected by the mutation".to_string()),
r#type: models::Type::Named {
name: "int".to_string(),
name: "int".into(),
},
arguments: BTreeMap::new(),
},
);

Expand All @@ -134,6 +136,7 @@ fn make_procedure_type(
r#type: models::Type::Array {
element_type: Box::from(result_type),
},
arguments: BTreeMap::new(),
},
);

Expand Down Expand Up @@ -168,7 +171,7 @@ fn get_native_mutations_schema(
native_mutations_metadata: &query_engine_metadata::metadata::NativeMutations,
object_types: &mut BTreeMap<String, models::ObjectType>,
scalar_types: &mut BTreeMap<String, models::ScalarType>,
) -> Result<Vec<models::ProcedureInfo>, connector::SchemaError> {
) -> Result<Vec<models::ProcedureInfo>, connector::ErrorResponse> {
let mut native_mutations = Vec::new();

native_mutations_metadata.0.iter().for_each(|(name, info)| {
Expand All @@ -180,6 +183,7 @@ fn get_native_mutations_schema(
models::ObjectField {
description: column.column_info.description.clone(),
r#type: column_to_type(&column.column_info),
arguments: BTreeMap::new(),
},
)
})),
Expand Down Expand Up @@ -227,7 +231,7 @@ fn get_stored_procedure_argument(
fn get_stored_procedures_schema(
stored_procedures: &StoredProcedures,
object_types: &mut BTreeMap<String, models::ObjectType>,
) -> Result<Vec<models::ProcedureInfo>, connector::SchemaError> {
) -> Result<Vec<models::ProcedureInfo>, connector::ErrorResponse> {
let mut stored_procedures_schema = Vec::new();

for (proc_name, proc_info) in stored_procedures.0.iter() {
Expand All @@ -250,6 +254,7 @@ fn get_stored_procedures_schema(
models::ObjectField {

Check warning on line 254 in crates/ndc-sqlserver/src/schema.rs

View workflow job for this annotation

GitHub Actions / cargo fmt

Diff in /home/runner/work/ndc-sqlserver/ndc-sqlserver/crates/ndc-sqlserver/src/schema.rs
description: column.description.clone(),
r#type: column_to_type(column),
arguments: BTreeMap::new()
},
)
})),
Expand All @@ -259,7 +264,7 @@ fn get_stored_procedures_schema(
.insert(object_type_name.clone(), stored_proc_object_type)
.is_some()
{
return Err(connector::SchemaError::Other(Box::new(
return Err(connector::ErrorResponse::Other(Box::new(
SchemaError::DuplicateObject(object_type_name),
)));
};
Expand All @@ -286,7 +291,7 @@ fn get_stored_procedures_schema(
/// from the NDC specification.
pub fn get_schema(
configuration::Configuration { metadata, .. }: &configuration::Configuration,
) -> Result<models::SchemaResponse, connector::SchemaError> {
) -> Result<models::SchemaResponse, connector::ErrorResponse> {
let mut scalar_types: BTreeMap<String, models::ScalarType> =
configuration::occurring_scalar_types(metadata)
.iter()
Expand Down Expand Up @@ -403,6 +408,7 @@ pub fn get_schema(
models::ObjectField {
description: column.description.clone(),
r#type: column_to_type(column),
arguments: BTreeMap::new(),
},
)
})),
Expand All @@ -412,7 +418,7 @@ pub fn get_schema(

let mut object_types = table_types;

let native_queries = get_native_queries_schema(&metadata.native_queries, &mut object_types)?;
let native_queries = get_native_queries_schema(&metadata.native_queries, &mut object_types);

let native_mutations = get_native_mutations_schema(
&metadata.native_mutations,
Expand Down Expand Up @@ -530,20 +536,23 @@ mod tests {
r#type: models::Type::Named {

Check warning on line 536 in crates/ndc-sqlserver/src/schema.rs

View workflow job for this annotation

GitHub Actions / cargo fmt

Diff in /home/runner/work/ndc-sqlserver/ndc-sqlserver/crates/ndc-sqlserver/src/schema.rs
name: "int".to_string(),
},
arguments: BTreeMap::new()
};

let expected_object_field_name = ObjectField {
description: None,
r#type: models::Type::Named {

Check warning on line 544 in crates/ndc-sqlserver/src/schema.rs

View workflow job for this annotation

GitHub Actions / cargo fmt

Diff in /home/runner/work/ndc-sqlserver/ndc-sqlserver/crates/ndc-sqlserver/src/schema.rs
name: "varchar".to_string(),
},
arguments: BTreeMap::new()
};

let expected_object_field_affected_rows = ObjectField {
description: Some("The number of rows affected by the mutation".into()),
r#type: models::Type::Named {

Check warning on line 552 in crates/ndc-sqlserver/src/schema.rs

View workflow job for this annotation

GitHub Actions / cargo fmt

Diff in /home/runner/work/ndc-sqlserver/ndc-sqlserver/crates/ndc-sqlserver/src/schema.rs
name: "int".to_string(),
},
arguments: BTreeMap::new()
};

let expected_native_mutation_object_type = ObjectType {
Expand All @@ -561,6 +570,7 @@ mod tests {
name: "insert_user_native_mutation".into(),

Check warning on line 570 in crates/ndc-sqlserver/src/schema.rs

View workflow job for this annotation

GitHub Actions / cargo fmt

Diff in /home/runner/work/ndc-sqlserver/ndc-sqlserver/crates/ndc-sqlserver/src/schema.rs
}),
},
arguments: BTreeMap::new()
};

let expected_native_mutation_response_object_type = ObjectType {
Expand Down Expand Up @@ -725,6 +735,7 @@ mod tests {
r#type: (models::Type::Named {
name: "int".to_string(),
}),
arguments: BTreeMap::new(),
},
);

Expand Down

0 comments on commit 0f9ea8b

Please sign in to comment.