Skip to content

Commit

Permalink
update to latest ndc sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
BenoitRanque committed Sep 27, 2024
1 parent c966b27 commit 487b073
Show file tree
Hide file tree
Showing 30 changed files with 782 additions and 304 deletions.
30 changes: 26 additions & 4 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion crates/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ async-trait = "0.1.78"
glob-match = "0.2.1"
graphql_client = "0.14.0"
graphql-parser = "0.4.0"
ndc-models = { git = "http://github.com/hasura/ndc-spec.git", tag = "v0.1.4" }
ndc-models = { git = "http://github.com/hasura/ndc-spec.git", tag = "v0.1.6" }
reqwest = { version = "0.12.7", features = [
"json",
"rustls-tls",
Expand Down
31 changes: 31 additions & 0 deletions crates/common/src/capabilities.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use ndc_models as models;

pub fn capabilities() -> models::Capabilities {
models::Capabilities {
query: models::QueryCapabilities {
aggregates: None,
variables: Some(models::LeafCapability {}),
explain: Some(models::LeafCapability {}),
nested_fields: models::NestedFieldCapabilities {
aggregates: None,
filter_by: None,
order_by: None,
},
exists: models::ExistsCapabilities {
nested_collections: None,
},
},
mutation: models::MutationCapabilities {
transactional: None,
explain: Some(models::LeafCapability {}),
},
relationships: None,
}
}

pub fn capabilities_response() -> models::CapabilitiesResponse {
models::CapabilitiesResponse {
version: models::VERSION.into(),
capabilities: capabilities(),
}
}
24 changes: 0 additions & 24 deletions crates/common/src/capabilities_response.rs

This file was deleted.

23 changes: 13 additions & 10 deletions crates/common/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use config_file::{RequestConfigFile, ResponseConfigFile};
use ndc_models::{ArgumentName, FieldName, FunctionName, ProcedureName, ScalarTypeName, TypeName};
use schema::SchemaDefinition;
use std::collections::BTreeMap;
pub mod config_file;
Expand All @@ -20,14 +21,14 @@ pub struct ConnectionConfig {

#[derive(Debug, Clone)]
pub struct RequestConfig {
pub headers_argument: String,
pub headers_type_name: String,
pub headers_argument: ArgumentName,
pub headers_type_name: ScalarTypeName,
pub forward_headers: Vec<String>,
}
#[derive(Debug, Clone)]
pub struct ResponseConfig {
pub headers_field: String,
pub response_field: String,
pub headers_field: FieldName,
pub response_field: FieldName,
pub type_name_prefix: String,
pub type_name_suffix: String,
pub forward_headers: Vec<String>,
Expand All @@ -36,8 +37,8 @@ pub struct ResponseConfig {
impl Default for RequestConfig {
fn default() -> Self {
Self {
headers_argument: "_headers".to_owned(),
headers_type_name: "_HeaderMap".to_owned(),
headers_argument: "_headers".to_owned().into(),
headers_type_name: "_HeaderMap".to_owned().into(),
forward_headers: vec![],
}
}
Expand All @@ -46,8 +47,8 @@ impl Default for RequestConfig {
impl Default for ResponseConfig {
fn default() -> Self {
Self {
headers_field: "headers".to_owned(),
response_field: "response".to_owned(),
headers_field: "headers".to_owned().into(),
response_field: "response".to_owned().into(),
type_name_prefix: "_".to_owned(),
type_name_suffix: "Response".to_owned(),
forward_headers: vec![],
Expand Down Expand Up @@ -89,16 +90,18 @@ impl From<ResponseConfigFile> for ResponseConfig {
}

impl ResponseConfig {
pub fn query_response_type_name(&self, query: &str) -> String {
pub fn query_response_type_name(&self, query: &FunctionName) -> TypeName {
format!(
"{}{}Query{}",
self.type_name_prefix, query, self.type_name_suffix
)
.into()
}
pub fn mutation_response_type_name(&self, mutation: &str) -> String {
pub fn mutation_response_type_name(&self, mutation: &ProcedureName) -> TypeName {
format!(
"{}{}Mutation{}",
self.type_name_prefix, mutation, self.type_name_suffix
)
.into()
}
}
79 changes: 43 additions & 36 deletions crates/common/src/config/config_file.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use ndc_models::{ArgumentName, FieldName, ScalarTypeName};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
Expand All @@ -10,14 +11,16 @@ pub const CONFIG_SCHEMA_FILE_NAME: &str = "configuration.schema.json";
pub struct ServerConfigFile {
#[serde(rename = "$schema")]
pub json_schema: String,
/// Connection Configuration for introspection
/// Connection Configuration for introspection.
pub introspection: ConnectionConfigFile,
/// Connection configuration for query execution
/// Connection configuration for query execution.
pub execution: ConnectionConfigFile,
/// Optional configuration for requests
pub request: RequestConfigFile,
/// Optional configuration for responses
pub response: ResponseConfigFile,
/// Optional configuration for requests.
#[serde(skip_serializing_if = "Option::is_none", default)]
pub request: Option<RequestConfigFile>,
/// Optional configuration for responses.
#[serde(skip_serializing_if = "Option::is_none", default)]
pub response: Option<ResponseConfigFile>,
}

impl Default for ServerConfigFile {
Expand All @@ -26,15 +29,17 @@ impl Default for ServerConfigFile {
json_schema: CONFIG_SCHEMA_FILE_NAME.to_owned(),
execution: ConnectionConfigFile::default(),
introspection: ConnectionConfigFile::default(),
request: RequestConfigFile::default(),
response: ResponseConfigFile::default(),
request: None,
response: None,
}
}
}

#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct ConnectionConfigFile {
/// Target GraphQL endpoint URL
pub endpoint: ConfigValue,
/// Static headers to include with each request
#[serde(skip_serializing_if = "BTreeMap::is_empty", default)]
pub headers: BTreeMap<String, ConfigValue>,
}
Expand All @@ -51,56 +56,58 @@ impl Default for ConnectionConfigFile {
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "camelCase")]
pub struct RequestConfigFile {
/// Name of the headers argument
/// Must not conflict with any arguments of root fields in the target schema
/// Defaults to "_headers", set to a different value if there is a conflict
/// Name of the headers argument.
/// Must not conflict with any arguments of root fields in the target schema.
/// Defaults to "_headers", set to a different value if there is a conflict.
#[serde(skip_serializing_if = "Option::is_none", default)]
pub headers_argument: Option<String>,
/// Name of the headers argument type
/// Must not conflict with other types in the target schema
/// Defaults to "_HeaderMap", set to a different value if there is a conflict
pub headers_argument: Option<ArgumentName>,
/// Name of the headers argument type.
/// Must not conflict with other types in the target schema.
/// Defaults to "_HeaderMap", set to a different value if there is a conflict.
#[serde(skip_serializing_if = "Option::is_none", default)]
pub headers_type_name: Option<String>,
/// List of headers to from the request
/// Defaults to [], AKA no headers/disabled
/// Supports glob patterns eg. "X-Hasura-*"
/// Enabling this requires additional configuration on the ddn side, see docs for more
pub headers_type_name: Option<ScalarTypeName>,
/// List of headers to forward from the request.
/// Defaults to [], AKA no headers/disabled.
/// Supports glob patterns eg. "X-Hasura-*".
/// Enabling this requires additional configuration on the ddn side, see docs for more.
#[serde(skip_serializing_if = "Option::is_none", default)]
pub forward_headers: Option<Vec<String>>,
}
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "camelCase")]
pub struct ResponseConfigFile {
/// Name of the headers field in the response type
/// Defaults to "headers"
/// Name of the headers field in the response type.
/// Defaults to "headers".
#[serde(skip_serializing_if = "Option::is_none", default)]
pub headers_field: Option<String>,
/// Name of the response field in the response type
/// Defaults to "response"
pub headers_field: Option<FieldName>,
/// Name of the response field in the response type.
/// Defaults to "response".
#[serde(skip_serializing_if = "Option::is_none", default)]
pub response_field: Option<String>,
/// Prefix for response type names
/// Defaults to "_"
/// Generated response type names must be unique once prefix and suffix are applied
pub response_field: Option<FieldName>,
/// Prefix for response type names.
/// Defaults to "_".
/// Generated response type names must be unique once prefix and suffix are applied.
#[serde(skip_serializing_if = "Option::is_none", default)]
pub type_name_prefix: Option<String>,
/// Suffix for response type names
/// Defaults to "Response"
/// Generated response type names must be unique once prefix and suffix are applied
/// Suffix for response type names.
/// Defaults to "Response".
/// Generated response type names must be unique once prefix and suffix are applied.
#[serde(skip_serializing_if = "Option::is_none", default)]
pub type_name_suffix: Option<String>,
/// List of headers to from the response
/// Defaults to [], AKA no headers/disabled
/// Supports glob patterns eg. "X-Hasura-*"
/// Enabling this requires additional configuration on the ddn side, see docs for more
/// List of headers to forward from the response.
/// Defaults to [], AKA no headers/disabled.
/// Supports glob patterns eg. "X-Hasura-*".
/// Enabling this requires additional configuration on the ddn side, see docs for more.
#[serde(skip_serializing_if = "Option::is_none", default)]
pub forward_headers: Option<Vec<String>>,
}

#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub enum ConfigValue {
/// A static string value
#[serde(rename = "value")]
Value(String),
/// A reference to an environment variable, from which the value will be read at runtime
#[serde(rename = "valueFromEnv")]
ValueFromEnv(String),
}
Expand Down
Loading

0 comments on commit 487b073

Please sign in to comment.