这是indexloc提供的服务,不要输入任何密码
Skip to content

Update to use latest NDC SDK #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
321 changes: 124 additions & 197 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion crates/dc-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"

[dependencies]
axum = { version = "0.6.18", features = ["headers"] }
bytes = "1"
bytes = "^1"
dc-api-types = { path = "../dc-api-types" }
http = "^0.2"
jsonwebtoken = "8"
Expand Down
4 changes: 2 additions & 2 deletions crates/mongodb-agent-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ edition = "2021"

[dependencies]
anyhow = "1.0.71"
async-trait = "0.1"
async-trait = "^0.1"
axum = { version = "0.6", features = ["headers"] }
bytes = "1"
bytes = "^1"
configuration = { path = "../configuration" }
dc-api = { path = "../dc-api" }
dc-api-types = { path = "../dc-api-types" }
Expand Down
4 changes: 2 additions & 2 deletions crates/mongodb-connector/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"

[dependencies]
anyhow = "1"
async-trait = "0.1"
async-trait = "^0.1"
configuration = { path = "../configuration" }
dc-api = { path = "../dc-api" }
dc-api-types = { path = "../dc-api-types" }
Expand All @@ -18,7 +18,7 @@ lazy_static = "^1.4.0"
mongodb = "2.8"
mongodb-agent-common = { path = "../mongodb-agent-common" }
mongodb-support = { path = "../mongodb-support" }
ndc-sdk = { git = "https://github.com/hasura/ndc-hub.git" }
ndc-sdk = { git = "https://github.com/hasura/ndc-sdk-rs.git" }
prometheus = "*" # share version from ndc-sdk
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0", features = ["preserve_order"] }
Expand Down
11 changes: 11 additions & 0 deletions crates/mongodb-connector/src/api_type_conversions/capabilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub fn v2_to_v3_scalar_type_capabilities(

fn v2_to_v3_capabilities(capabilities: v2::ScalarTypeCapabilities) -> v3::ScalarType {
v3::ScalarType {
representation: capabilities.graphql_type.as_ref().map(graphql_type_to_representation),
aggregate_functions: capabilities
.aggregate_functions
.unwrap_or_default()
Expand Down Expand Up @@ -47,3 +48,13 @@ fn v2_to_v3_capabilities(capabilities: v2::ScalarTypeCapabilities) -> v3::Scalar
.collect(),
}
}

fn graphql_type_to_representation(graphql_type: &v2::GraphQlType) -> v3::TypeRepresentation {
match graphql_type {
v2::GraphQlType::Int => v3::TypeRepresentation::Integer,
v2::GraphQlType::Float => v3::TypeRepresentation::Number,
v2::GraphQlType::String => v3::TypeRepresentation::String,
v2::GraphQlType::Boolean => v3::TypeRepresentation::Boolean,
v2::GraphQlType::Id => v3::TypeRepresentation::String,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ mod tests {
use dc_api_test_helpers::{self as v2, source, table_relationships, target};
use mongodb_support::BsonScalarType;
use ndc_sdk::models::{
AggregateFunctionDefinition, ComparisonOperatorDefinition, OrderByElement, OrderByTarget, OrderDirection, ScalarType, Type
AggregateFunctionDefinition, ComparisonOperatorDefinition, OrderByElement, OrderByTarget, OrderDirection, ScalarType, Type, TypeRepresentation
};
use ndc_test_helpers::*;
use pretty_assertions::assert_eq;
Expand Down Expand Up @@ -1066,6 +1066,7 @@ mod tests {
(
"String".to_owned(),
ScalarType {
representation: Some(TypeRepresentation::String),
aggregate_functions: Default::default(),
comparison_operators: BTreeMap::from([
("_eq".to_owned(), ComparisonOperatorDefinition::Equal),
Expand All @@ -1083,6 +1084,7 @@ mod tests {
(
"Int".to_owned(),
ScalarType {
representation: Some(TypeRepresentation::Integer),
aggregate_functions: BTreeMap::from([
(
"avg".into(),
Expand Down
2 changes: 1 addition & 1 deletion crates/mongodb-connector/src/capabilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::api_type_conversions::v2_to_v3_scalar_type_capabilities;

pub fn mongo_capabilities_response() -> CapabilitiesResponse {
ndc_sdk::models::CapabilitiesResponse {
version: "^0.1.0".to_owned(),
version: "0.1.1".to_owned(),
capabilities: Capabilities {
query: QueryCapabilities {
aggregates: Some(LeafCapability {}),
Expand Down
22 changes: 14 additions & 8 deletions crates/mongodb-connector/src/mongo_connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ use mongodb_agent_common::{
};
use ndc_sdk::{
connector::{
Connector, ExplainError, FetchMetricsError, HealthError, InitializationError,
MutationError, ParseError, QueryError, SchemaError,
Connector, ConnectorSetup, ExplainError, FetchMetricsError, HealthError, InitializationError, MutationError, ParseError, QueryError, SchemaError
},
json_response::JsonResponse,
models::{
Expand All @@ -31,13 +30,13 @@ use crate::{capabilities::mongo_capabilities_response, mutation::handle_mutation
pub struct MongoConnector;

#[async_trait]
impl Connector for MongoConnector {
type Configuration = Configuration;
type State = MongoConfig;
impl ConnectorSetup for MongoConnector {
type Connector = MongoConnector;

async fn parse_configuration(
&self,
configuration_dir: impl AsRef<Path> + Send,
) -> Result<Self::Configuration, ParseError> {
) -> Result<Configuration, ParseError> {
let configuration = Configuration::parse_configuration(configuration_dir)
.await
.map_err(|err| ParseError::Other(err.into()))?;
Expand All @@ -46,12 +45,19 @@ impl Connector for MongoConnector {

/// Reads database connection URI from environment variable
async fn try_init_state(
configuration: &Self::Configuration,
&self,
configuration: &Configuration,
_metrics: &mut prometheus::Registry,
) -> Result<Self::State, InitializationError> {
) -> Result<MongoConfig, InitializationError> {
let state = mongodb_agent_common::state::try_init_state(configuration).await?;
Ok(state)
}
}

#[async_trait]
impl Connector for MongoConnector {
type Configuration = Configuration;
type State = MongoConfig;

fn fetch_metrics(
_configuration: &Self::Configuration,
Expand Down
2 changes: 1 addition & 1 deletion crates/ndc-test-helpers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ edition = "2021"
[dependencies]
indexmap = "2"
itertools = "^0.10"
ndc-sdk = { git = "https://github.com/hasura/ndc-hub.git" }
ndc-sdk = { git = "https://github.com/hasura/ndc-sdk-rs.git" }
serde_json = "1"