Skip to content

Commit

Permalink
update to ndc-sdk-rs-0.2.1 (#520)
Browse files Browse the repository at this point in the history
### What

We want to update ndc-sdk-rs to 0.2.1, and it introduces several
changes:

1. Error messages hasura/ndc-sdk-rs#15
2. Update ndc-spec to 0.1.5, which introduces breaking changes by adding
newtype wrappers around string types

### How

1. For errors, follow
hasura/ndc-sdk-rs#15 (comment)
2. For newtypes, go into type hell and fix the bugs by trying to put the
ndc-models newtypes in the data structures, as they are more
descriptive.
  • Loading branch information
Gil Mizrahi authored Jul 15, 2024
1 parent 58ec61f commit fe0adbe
Show file tree
Hide file tree
Showing 74 changed files with 1,013 additions and 1,092 deletions.
24 changes: 16 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ similar_names = "allow"
too_many_lines = "allow"

[workspace.dependencies]
ndc-models = { git = "https://github.com/hasura/ndc-spec.git", tag = "v0.1.4" }
ndc-sdk = { git = "https://github.com/hasura/ndc-sdk-rs.git", tag = "v0.1.4" }
ndc-test = { git = "https://github.com/hasura/ndc-spec.git", tag = "v0.1.4" }
ndc-models = { git = "https://github.com/hasura/ndc-spec.git", tag = "v0.1.5" }
ndc-sdk = { git = "https://github.com/hasura/ndc-sdk-rs.git", tag = "v0.2.1" }
ndc-test = { git = "https://github.com/hasura/ndc-spec.git", tag = "v0.1.5" }

anyhow = "1"
async-trait = "0.1"
Expand All @@ -58,6 +58,7 @@ serde = "1"
serde_json = "1"
serde_yaml = "0.9"
similar-asserts = "1"
smol_str = "0.1"
sqlformat = "0.2"
sqlx = "0.7"
tempfile = "3"
Expand Down
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

### Changed

- Support ndc-sdk-rs v0.2.1, including changes to error messages.
[#520](https://github.com/hasura/ndc-postgres/pull/520)

### Fixed

## [v0.8.0]
Expand Down
63 changes: 38 additions & 25 deletions crates/cli/src/native_operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,15 @@ async fn create(
.metadata
.native_queries
.0
.insert(name, new_native_operation);
.insert(name.into(), new_native_operation);
}
Override::No => {
// Only insert if vacant.
if let std::collections::btree_map::Entry::Vacant(entry) =
configuration.metadata.native_queries.0.entry(name.clone())
if let std::collections::btree_map::Entry::Vacant(entry) = configuration
.metadata
.native_queries
.0
.entry(name.clone().into())
{
entry.insert(new_native_operation);
} else {
Expand Down Expand Up @@ -202,36 +205,46 @@ async fn create(
.native_operations
.queries
.0
.insert(name, new_native_operation);
.insert(name.into(), new_native_operation);
}
configuration::version5::native_operations::Kind::Mutation => {
configuration
.metadata
.native_operations
.mutations
.0
.insert(name, new_native_operation);
.insert(name.into(), new_native_operation);
}
},
Override::No => {
// Only insert if vacant.
if let std::collections::btree_map::Entry::Vacant(entry) = match kind {
configuration::version5::native_operations::Kind::Query => configuration
.metadata
.native_operations
.queries
.0
.entry(name.clone()),
configuration::version5::native_operations::Kind::Mutation => configuration
.metadata
.native_operations
.mutations
.0
.entry(name.clone()),
} {
entry.insert(new_native_operation);
} else {
anyhow::bail!("A Native Operation with the name '{name}' already exists. To override, use the --override flag.");
match kind {
configuration::version5::native_operations::Kind::Query => {
if let std::collections::btree_map::Entry::Vacant(entry) = configuration
.metadata
.native_operations
.queries
.0
.entry(name.clone().into())
{
entry.insert(new_native_operation);
} else {
anyhow::bail!("A Native Operation with the name '{name}' already exists. To override, use the --override flag.");
}
}
configuration::version5::native_operations::Kind::Mutation => {
if let std::collections::btree_map::Entry::Vacant(entry) = configuration
.metadata
.native_operations
.mutations
.0
.entry(name.clone().into())
{
entry.insert(new_native_operation);
} else {
anyhow::bail!("A Native Operation with the name '{name}' already exists. To override, use the --override flag.");
}
}
}
}
}
Expand Down Expand Up @@ -270,7 +283,7 @@ async fn delete(
))?,
configuration::ParsedConfiguration::Version4(ref mut configuration) => {
// Delete if exists and is of the same type, error if not.
match configuration.metadata.native_queries.0.entry(name.clone()) {
match configuration.metadata.native_queries.0.entry(name.into()) {
std::collections::btree_map::Entry::Occupied(entry) => {
let value = entry.get();
if value.is_procedure {
Expand Down Expand Up @@ -307,7 +320,7 @@ async fn delete(
.native_operations
.mutations
.0
.entry(name.clone())
.entry(name.into())
{
std::collections::btree_map::Entry::Occupied(entry) => {
entry.remove_entry();
Expand All @@ -323,7 +336,7 @@ async fn delete(
.native_operations
.queries
.0
.entry(name.clone())
.entry(name.into())
{
std::collections::btree_map::Entry::Occupied(entry) => {
entry.remove_entry();
Expand Down
2 changes: 2 additions & 0 deletions crates/configuration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ license.workspace = true
workspace = true

[dependencies]
ndc-models = { workspace = true }
query-engine-metadata = { path = "../query-engine/metadata" }
query-engine-sql = { path = "../query-engine/sql" }

Expand All @@ -18,6 +19,7 @@ prometheus = {workspace = true }
schemars = { workspace = true, features = ["smol_str", "preserve_order"] }
serde = { workspace = true }
serde_json = { workspace = true, features = ["raw_value"] }
smol_str = { workspace = true }
sqlx = { workspace = true, features = ["json", "postgres", "runtime-tokio-rustls"] }
thiserror = { workspace = true }
tokio = { workspace = true, features = ["full"] }
Expand Down
Loading

0 comments on commit fe0adbe

Please sign in to comment.