Skip to content
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

chore: bump ndc_sdk #42

Merged
merged 1 commit into from
Oct 23, 2023
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
438 changes: 342 additions & 96 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[workspace.package]
version = "0.1.0"

[workspace]
resolver = "2"
package.version = "0.1.0"
package.edition = "2021"

members = [
"crates/ndc-sqlserver",
"crates/query-engine",
Expand Down
6 changes: 3 additions & 3 deletions crates/ndc-sqlserver/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "ndc-sqlserver"
version = "0.1.0"
edition = "2021"
version.workspace = true
edition.workspace = true

default-run = "ndc-sqlserver"

Expand All @@ -14,7 +14,7 @@ name = "ndc-sqlserver"
path = "bin/main.rs"

[dependencies]
ndc-hub = { git = "https://github.com/hasura/ndc-hub.git", tag = "v0.1.0-rc.1", package = "ndc-sdk" }
ndc-sdk = { git = "https://github.com/hasura/ndc-hub.git", rev = "098b1c2", package = "ndc-sdk" }
query-engine = { path = "../query-engine" }

tokio-util = { version = "0.7.9", features = ["compat"] }
Expand Down
2 changes: 1 addition & 1 deletion crates/ndc-sqlserver/bin/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ndc_hub::default_main::default_main;
use ndc_sdk::default_main::default_main;
use ndc_sqlserver::connector::SQLServer;

#[tokio::main]
Expand Down
2 changes: 1 addition & 1 deletion crates/ndc-sqlserver/src/configuration.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Configuration and state for our connector.
use super::metrics;

use ndc_hub::connector;
use ndc_sdk::connector;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use thiserror::Error;
Expand Down
30 changes: 16 additions & 14 deletions crates/ndc-sqlserver/src/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
use tiberius::Query;

use async_trait::async_trait;
use ndc_hub::connector;
use ndc_hub::models;
use ndc_sdk::connector;
use ndc_sdk::json_response::JsonResponse;
use ndc_sdk::models;

use query_engine::phases;

Expand All @@ -33,17 +34,17 @@ impl connector::Connector for SQLServer {

/// Configure a configuration maybe?
async fn update_configuration(
args: &Self::RawConfiguration,
args: Self::RawConfiguration,
) -> Result<configuration::DeploymentConfiguration, connector::UpdateConfigurationError> {
configuration::configure(args).await
configuration::configure(&args).await
}

/// Validate the raw configuration provided by the user,
/// returning a configuration error or a validated [`Connector::Configuration`].
async fn validate_raw_configuration(
configuration: &Self::RawConfiguration,
configuration: Self::RawConfiguration,
) -> Result<Self::Configuration, connector::ValidateError> {
configuration::validate_raw_configuration(configuration).await
configuration::validate_raw_configuration(&configuration).await
}

/// Initialize the connector's in-memory state.
Expand Down Expand Up @@ -93,9 +94,9 @@ impl connector::Connector for SQLServer {
///
/// This function implements the [capabilities endpoint](https://hasura.github.io/ndc-spec/specification/capabilities.html)
/// from the NDC specification.
async fn get_capabilities() -> models::CapabilitiesResponse {
async fn get_capabilities() -> JsonResponse<models::CapabilitiesResponse> {
let empty = serde_json::to_value(()).unwrap();
models::CapabilitiesResponse {
JsonResponse::Value(models::CapabilitiesResponse {
versions: "^0.0.0".into(),
capabilities: models::Capabilities {
explain: Some(empty.clone()),
Expand All @@ -107,7 +108,7 @@ impl connector::Connector for SQLServer {
relationships: Some(empty),
mutations: None,
},
}
})
}

/// Get the connector's schema.
Expand All @@ -116,7 +117,7 @@ impl connector::Connector for SQLServer {
/// from the NDC specification.
async fn get_schema(
_configuration: &Self::Configuration,
) -> Result<models::SchemaResponse, connector::SchemaError> {
) -> Result<JsonResponse<models::SchemaResponse>, connector::SchemaError> {
todo!("get_schema")
}

Expand All @@ -128,7 +129,7 @@ impl connector::Connector for SQLServer {
_configuration: &Self::Configuration,
_state: &Self::State,
_query_request: models::QueryRequest,
) -> Result<models::ExplainResponse, connector::ExplainError> {
) -> Result<JsonResponse<models::ExplainResponse>, connector::ExplainError> {
todo!("explain!")
}

Expand All @@ -140,7 +141,7 @@ impl connector::Connector for SQLServer {
_configuration: &Self::Configuration,
_state: &Self::State,
_request: models::MutationRequest,
) -> Result<models::MutationResponse, connector::MutationError> {
) -> Result<JsonResponse<models::MutationResponse>, connector::MutationError> {
todo!("mutations are currently not implemented")
}

Expand All @@ -152,7 +153,7 @@ impl connector::Connector for SQLServer {
configuration: &Self::Configuration,
state: &Self::State,
query_request: models::QueryRequest,
) -> Result<models::QueryResponse, connector::QueryError> {
) -> Result<JsonResponse<models::QueryResponse>, connector::QueryError> {
tracing::info!("{}", serde_json::to_string(&query_request).unwrap());
tracing::info!("{:?}", query_request);

Expand Down Expand Up @@ -184,7 +185,8 @@ impl connector::Connector for SQLServer {
// assuming query succeeded, increment counter
state.metrics.query_total.inc();

Ok(result)
// TODO: return raw JSON
Ok(JsonResponse::Value(result))
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/ndc-sqlserver/src/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Metrics setup and update for our connector.

use super::configuration::InitializationError;
use ndc_hub::connector;
use ndc_sdk::connector;
use prometheus::core::{AtomicU64, GenericCounter};

#[derive(Debug, Clone)]
Expand Down
6 changes: 3 additions & 3 deletions crates/ndc-sqlserver/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub async fn run_explain(testname: &str) -> ExactExplainResponse {
}

/// Run a query against the server, get the result, and compare against the snapshot.
pub async fn get_schema() -> ndc_hub::models::SchemaResponse {
pub async fn get_schema() -> ndc_sdk::models::SchemaResponse {
make_request(|client| client.get("/schema")).await
}

Expand Down Expand Up @@ -71,13 +71,13 @@ async fn make_request<Response: for<'a> serde::Deserialize<'a>>(
let test_deployment_file = get_deployment_file();

// initialise server state with the static configuration.
let state = ndc_hub::default_main::init_server_state::<connector::SQLServer>(
let state = ndc_sdk::default_main::init_server_state::<connector::SQLServer>(
test_deployment_file.display().to_string(),
)
.await;

// create a fresh client
let router = ndc_hub::default_main::create_router(state);
let router = ndc_sdk::default_main::create_router(state, None);
let client = TestClient::new(router);

// make the request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ expression: result
[
{
"aggregates": {
"avg_artist_id": 121,
"how_many_albums": 347,
"how_many_artist_ids": 347,
"how_many_distinct_artist_ids": 204,
"min_artist_id": 1,
"max_artist_id": 275,
"min_artist_id": 1
"avg_artist_id": 121
}
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ expression: result
[
{
"aggregates": {
"avg_artist_id": 121,
"how_many_albums": 347,
"how_many_artist_ids": 347,
"how_many_distinct_artist_ids": 204,
"min_artist_id": 1,
"max_artist_id": 275,
"min_artist_id": 1
"avg_artist_id": 121
},
"rows": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,44 @@ expression: result
{
"rows": [
{
"Name": "Accept",
"Albums": {
"aggregates": {
"how_many_albums": 2
}
},
"Name": "Accept"
}
},
{
"Name": "Aerosmith",
"Albums": {
"aggregates": {
"how_many_albums": 1
}
},
"Name": "Aerosmith"
}
},
{
"Name": "Alanis Morissette",
"Albums": {
"aggregates": {
"how_many_albums": 1
}
},
"Name": "Alanis Morissette"
}
},
{
"Name": "Alice In Chains",
"Albums": {
"aggregates": {
"how_many_albums": 1
}
},
"Name": "Alice In Chains"
}
},
{
"Name": "Antônio Carlos Jobim",
"Albums": {
"aggregates": {
"how_many_albums": 2
}
},
"Name": "Antônio Carlos Jobim"
}
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,75 +6,75 @@ expression: result
{
"rows": [
{
"Name": "Accept",
"Albums": {
"aggregates": {
"how_many_albums": 2
},
"rows": [
{
"Title": "Balls to the Wall"
},
{
"Title": "Restless and Wild"
}
]
},
"Name": "Accept"
],
"aggregates": {
"how_many_albums": 2
}
}
},
{
"Name": "Aerosmith",
"Albums": {
"aggregates": {
"how_many_albums": 1
},
"rows": [
{
"Title": "Big Ones"
}
]
},
"Name": "Aerosmith"
],
"aggregates": {
"how_many_albums": 1
}
}
},
{
"Name": "Alanis Morissette",
"Albums": {
"aggregates": {
"how_many_albums": 1
},
"rows": [
{
"Title": "Jagged Little Pill"
}
]
},
"Name": "Alanis Morissette"
],
"aggregates": {
"how_many_albums": 1
}
}
},
{
"Name": "Alice In Chains",
"Albums": {
"aggregates": {
"how_many_albums": 1
},
"rows": [
{
"Title": "Facelift"
}
]
},
"Name": "Alice In Chains"
],
"aggregates": {
"how_many_albums": 1
}
}
},
{
"Name": "Antônio Carlos Jobim",
"Albums": {
"aggregates": {
"how_many_albums": 2
},
"rows": [
{
"Title": "Warner 25 Anos"
},
{
"Title": "Chill: Brazil (Disc 2)"
}
]
},
"Name": "Antônio Carlos Jobim"
],
"aggregates": {
"how_many_albums": 2
}
}
}
]
}
Expand Down
Loading