Skip to content

Commit

Permalink
rename data_connector_type_mappings stage to object_types (hasura…
Browse files Browse the repository at this point in the history
…#533)

<!-- Thank you for submitting this PR! :) -->

## Description

We named this stage after the least interesting thing about it, this
resolves that.

`data_connector_type_mappings` -> `object_types`.

Functional no-op.

V3_GIT_ORIGIN_REV_ID: 67c94356cc7207e94eb3b696abbd32efe31551ac
  • Loading branch information
danieljharvey authored and hasura-bot committed May 1, 2024
1 parent ba5d0e3 commit 4f2a29b
Show file tree
Hide file tree
Showing 16 changed files with 74 additions and 97 deletions.
6 changes: 3 additions & 3 deletions v3/crates/engine/src/metadata/resolved.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ pub use stages::boolean_expressions::{
};
pub use stages::command_permissions::CommandWithPermissions;
pub use stages::commands::Command;
pub use stages::data_connector_type_mappings::{
FieldMapping, ObjectTypeRepresentation, ResolvedObjectApolloFederationConfig, TypeMapping,
};
pub use stages::data_connectors::DataConnectorLink;
pub use stages::model_permissions::{FilterPermission, ModelPredicate, ModelWithPermissions};
pub use stages::models::{
Model, ModelOrderByExpression, ModelSource, SelectManyGraphQlDefinition,
SelectUniqueGraphQlDefinition,
};
pub use stages::object_types::{
FieldMapping, ObjectTypeRepresentation, ResolvedObjectApolloFederationConfig, TypeMapping,
};
pub use stages::relationships::{
relationship_execution_category, ObjectTypeWithRelationships, Relationship,
RelationshipCapabilities, RelationshipCommandMapping, RelationshipExecutionCategory,
Expand Down
14 changes: 6 additions & 8 deletions v3/crates/engine/src/metadata/resolved/helpers/argument.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use crate::metadata::resolved::helpers::types::{
TypeRepresentation,
};
use crate::metadata::resolved::stages::{
boolean_expressions, data_connector_scalar_types, data_connector_type_mappings,
model_permissions, relationships, scalar_types, type_permissions,
boolean_expressions, data_connector_scalar_types, model_permissions, object_types,
relationships, scalar_types, type_permissions,
};
use crate::metadata::resolved::types::error::{
Error, TypeError, TypeMappingValidationError, TypePredicateError,
Expand Down Expand Up @@ -219,9 +219,7 @@ pub(crate) fn resolve_value_expression_for_argument(
&boolean_expression_type.data_connector_object_type,
)
.map(|type_mapping| match type_mapping {
data_connector_type_mappings::TypeMapping::Object {
field_mappings, ..
} => field_mappings,
object_types::TypeMapping::Object { field_mappings, .. } => field_mappings,
})
.ok_or(Error::DataConnectorTypeMappingValidationError {
type_name: base_type.clone(),
Expand Down Expand Up @@ -258,11 +256,11 @@ pub(crate) fn resolve_value_expression_for_argument(
pub(crate) fn resolve_model_predicate_with_type(
model_predicate: &permissions::ModelPredicate,
type_name: &Qualified<CustomTypeName>,
data_connector_field_mappings: &BTreeMap<FieldName, data_connector_type_mappings::FieldMapping>,
data_connector_field_mappings: &BTreeMap<FieldName, object_types::FieldMapping>,
data_connector_name: &Qualified<DataConnectorName>,
subgraph: &str,
data_connectors: &data_connector_scalar_types::DataConnectorsWithScalars,
fields: &IndexMap<FieldName, data_connector_type_mappings::FieldDefinition>,
fields: &IndexMap<FieldName, object_types::FieldDefinition>,
) -> Result<model_permissions::ModelPredicate, Error> {
match model_predicate {
permissions::ModelPredicate::FieldComparison(permissions::FieldComparisonPredicate {
Expand Down Expand Up @@ -418,7 +416,7 @@ fn resolve_binary_operator_for_type(
type_name: &Qualified<CustomTypeName>,
data_connector: &Qualified<DataConnectorName>,
field_name: &FieldName,
fields: &IndexMap<FieldName, data_connector_type_mappings::FieldDefinition>,
fields: &IndexMap<FieldName, object_types::FieldDefinition>,
scalars: &HashMap<&str, data_connector_scalar_types::ScalarTypeWithRepresentationInfo>,
ndc_scalar_type: &ndc_models::ScalarType,
subgraph: &str,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::metadata::resolved::stages::{commands, data_connector_type_mappings, models};
use crate::metadata::resolved::stages::{commands, models, object_types};
use ndc_models;
use open_dds::{
commands::{CommandName, DataConnectorCommand, FunctionName, ProcedureName},
Expand Down Expand Up @@ -168,7 +168,7 @@ pub fn validate_ndc(
NDCValidationError::NoSuchType(collection.collection_type.clone()),
)?;

let data_connector_type_mappings::TypeMapping::Object { field_mappings, .. } = model_source
let object_types::TypeMapping::Object { field_mappings, .. } = model_source
.type_mappings
.get(&model.data_type)
.ok_or_else(|| NDCValidationError::UnknownModelTypeMapping {
Expand Down Expand Up @@ -330,9 +330,7 @@ pub fn validate_ndc_command(
// Check if the command.output_type is available in schema.object_types
Some(command_source_ndc_type) => {
// Check if the command.output_type has typeMappings
let data_connector_type_mappings::TypeMapping::Object {
field_mappings, ..
} = command_source
let object_types::TypeMapping::Object { field_mappings, .. } = command_source
.type_mappings
.get(custom_type)
.ok_or_else(|| NDCValidationError::UnknownCommandTypeMapping {
Expand Down
14 changes: 4 additions & 10 deletions v3/crates/engine/src/metadata/resolved/helpers/type_mappings.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use crate::metadata::resolved::stages::{
data_connector_type_mappings, scalar_types, type_permissions,
};
use crate::metadata::resolved::stages::{object_types, scalar_types, type_permissions};

use crate::metadata::resolved::helpers::ndc_validation::{
get_underlying_named_type, NDCValidationError,
Expand Down Expand Up @@ -53,10 +51,7 @@ pub(crate) fn collect_type_mapping_for_source(
data_connector_name: &Qualified<DataConnectorName>,
object_types: &HashMap<Qualified<CustomTypeName>, type_permissions::ObjectTypeWithPermissions>,
scalar_types: &HashMap<Qualified<CustomTypeName>, scalar_types::ScalarTypeRepresentation>,
collected_mappings: &mut BTreeMap<
Qualified<CustomTypeName>,
data_connector_type_mappings::TypeMapping,
>,
collected_mappings: &mut BTreeMap<Qualified<CustomTypeName>, object_types::TypeMapping>,
) -> Result<(), TypeMappingCollectionError> {
match object_types.get(mapping_to_collect.type_name) {
Some(object_type_representation) => {
Expand All @@ -73,7 +68,7 @@ pub(crate) fn collect_type_mapping_for_source(
if let Some(inserted_mapping) = collected_mappings
.insert(mapping_to_collect.type_name.clone(), type_mapping.clone())
{
let data_connector_type_mappings::TypeMapping::Object {
let object_types::TypeMapping::Object {
ndc_object_type_name,
..
} = inserted_mapping;
Expand All @@ -90,8 +85,7 @@ pub(crate) fn collect_type_mapping_for_source(
}
}

let data_connector_type_mappings::TypeMapping::Object { field_mappings, .. } =
type_mapping;
let object_types::TypeMapping::Object { field_mappings, .. } = type_mapping;
// For each field in the ObjectType, if that field is using an ObjectType in its type,
// resolve the type mappings for that ObjectType too
for (field_name, field_definition) in &object_type_representation.object_type.fields {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub mod types;
use crate::metadata::resolved::stages::{
data_connector_scalar_types, data_connector_type_mappings, data_connectors, graphql_config,
scalar_types, type_permissions,
data_connector_scalar_types, data_connectors, graphql_config, object_types, scalar_types,
type_permissions,
};
use crate::metadata::resolved::types::error::{BooleanExpressionError, Error, GraphqlConfigError};

Expand Down Expand Up @@ -272,7 +272,7 @@ pub fn resolve_boolean_expression_info(
where_type_name: ast::TypeName,
subgraph: &str,
data_connectors: &data_connector_scalar_types::DataConnectorsWithScalars,
type_mappings: &data_connector_type_mappings::TypeMapping,
type_mappings: &object_types::TypeMapping,
graphql_config: &graphql_config::GraphqlConfig,
) -> Result<BooleanExpressionInfo, Error> {
let mut scalar_fields = HashMap::new();
Expand All @@ -289,7 +289,7 @@ pub fn resolve_boolean_expression_info(
})?
.scalars;

let data_connector_type_mappings::TypeMapping::Object { field_mappings, .. } = type_mappings;
let object_types::TypeMapping::Object { field_mappings, .. } = type_mappings;

let filter_graphql_config = graphql_config
.query
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::metadata::resolved::stages::{data_connector_type_mappings, data_connectors};
use crate::metadata::resolved::stages::{data_connectors, object_types};

use crate::metadata::resolved::types::subgraph::{Qualified, QualifiedTypeReference};
use std::collections::{BTreeMap, HashMap};
Expand All @@ -24,10 +24,8 @@ pub struct ObjectBooleanExpressionType {
pub data_connector_name: Qualified<DataConnectorName>,
pub data_connector_link: data_connectors::DataConnectorLink,
pub data_connector_object_type: String,
pub type_mappings: BTreeMap<
Qualified<open_dds::types::CustomTypeName>,
data_connector_type_mappings::TypeMapping,
>,
pub type_mappings:
BTreeMap<Qualified<open_dds::types::CustomTypeName>, object_types::TypeMapping>,
pub graphql: Option<BooleanExpressionInfo>,
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::metadata::resolved::stages::{data_connector_type_mappings, data_connectors};
use crate::metadata::resolved::stages::{data_connectors, object_types};
use crate::metadata::resolved::types::subgraph::{
deserialize_qualified_btreemap, serialize_qualified_btreemap, ArgumentInfo, Qualified,
QualifiedTypeReference,
Expand Down Expand Up @@ -28,8 +28,7 @@ pub struct CommandSource {
serialize_with = "serialize_qualified_btreemap",
deserialize_with = "deserialize_qualified_btreemap"
)]
pub type_mappings:
BTreeMap<Qualified<CustomTypeName>, data_connector_type_mappings::TypeMapping>,
pub type_mappings: BTreeMap<Qualified<CustomTypeName>, object_types::TypeMapping>,
pub argument_mappings: HashMap<ArgumentName, String>,
}

Expand Down
6 changes: 3 additions & 3 deletions v3/crates/engine/src/metadata/resolved/stages/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ pub mod command_permissions;
pub mod commands;
/// This is where we'll be moving explicit metadata resolve stages
pub mod data_connector_scalar_types;
pub mod data_connector_type_mappings;
pub mod data_connectors;
pub mod graphql_config;
pub mod model_permissions;
pub mod models;
pub mod object_types;
pub mod relationships;
pub mod roles;
pub mod scalar_types;
Expand All @@ -31,12 +31,12 @@ pub fn resolve(metadata: open_dds::Metadata) -> Result<Metadata, Error> {

let data_connectors = data_connectors::resolve(&metadata_accessor)?;

let data_connector_type_mappings::DataConnectorTypeMappingsOutput {
let object_types::DataConnectorTypeMappingsOutput {
graphql_types,
global_id_enabled_types,
apollo_federation_entity_enabled_types,
object_types,
} = data_connector_type_mappings::resolve(&metadata_accessor, &data_connectors)?;
} = object_types::resolve(&metadata_accessor, &data_connectors)?;

let scalar_types::ScalarTypesOutput {
scalar_types,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
mod types;
use crate::metadata::resolved::helpers::typecheck;
use crate::metadata::resolved::stages::{
boolean_expressions, data_connector_scalar_types, data_connector_type_mappings, models,
relationships,
boolean_expressions, data_connector_scalar_types, models, object_types, relationships,
};
use crate::metadata::resolved::types::permission::ValueExpression;
use indexmap::IndexMap;
Expand Down Expand Up @@ -144,7 +143,7 @@ fn resolve_model_predicate(
model: &models::Model,
subgraph: &str,
data_connectors: &data_connector_scalar_types::DataConnectorsWithScalars,
fields: &IndexMap<FieldName, data_connector_type_mappings::FieldDefinition>,
fields: &IndexMap<FieldName, object_types::FieldDefinition>,
object_types: &HashMap<Qualified<CustomTypeName>, relationships::ObjectTypeWithRelationships>,
models: &IndexMap<Qualified<ModelName>, models::Model>,
) -> Result<ModelPredicate, Error> {
Expand All @@ -160,14 +159,14 @@ fn resolve_model_predicate(
// TODO: resolve the "in" operator too (ndc_models::BinaryArrayComparisonOperator)
if let Some(model_source) = &model.source {
// Get field mappings of model data type
let data_connector_type_mappings::TypeMapping::Object { field_mappings, .. } =
model_source.type_mappings.get(&model.data_type).ok_or(
Error::TypeMappingRequired {
model_name: model.name.clone(),
type_name: model.data_type.clone(),
data_connector: model_source.data_connector.name.clone(),
},
)?;
let object_types::TypeMapping::Object { field_mappings, .. } = model_source
.type_mappings
.get(&model.data_type)
.ok_or(Error::TypeMappingRequired {
model_name: model.name.clone(),
type_name: model.data_type.clone(),
data_connector: model_source.data_connector.name.clone(),
})?;

// Determine field_mapping for the predicate field
let field_mapping = field_mappings.get(field).ok_or_else(|| {
Expand Down Expand Up @@ -239,14 +238,14 @@ fn resolve_model_predicate(
open_dds::permissions::ModelPredicate::FieldIsNull(FieldIsNullPredicate { field }) => {
if let Some(model_source) = &model.source {
// Get field mappings of model data type
let data_connector_type_mappings::TypeMapping::Object { field_mappings, .. } =
model_source.type_mappings.get(&model.data_type).ok_or(
Error::TypeMappingRequired {
model_name: model.name.clone(),
type_name: model.data_type.clone(),
data_connector: model_source.data_connector.name.clone(),
},
)?;
let object_types::TypeMapping::Object { field_mappings, .. } = model_source
.type_mappings
.get(&model.data_type)
.ok_or(Error::TypeMappingRequired {
model_name: model.name.clone(),
type_name: model.data_type.clone(),
data_connector: model_source.data_connector.name.clone(),
})?;
// Determine field_mapping for the predicate field
let field_mapping = field_mappings.get(field).ok_or_else(|| {
Error::UnknownFieldInSelectPermissionsDefinition {
Expand Down Expand Up @@ -434,7 +433,7 @@ fn resolve_binary_operator_for_model(
model_name: &Qualified<ModelName>,
data_connector: &Qualified<DataConnectorName>,
field_name: &FieldName,
fields: &IndexMap<FieldName, data_connector_type_mappings::FieldDefinition>,
fields: &IndexMap<FieldName, object_types::FieldDefinition>,
scalars: &HashMap<&str, data_connector_scalar_types::ScalarTypeWithRepresentationInfo>,
ndc_scalar_type: &ndc_models::ScalarType,
subgraph: &str,
Expand Down
20 changes: 9 additions & 11 deletions v3/crates/engine/src/metadata/resolved/stages/models/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use crate::metadata::resolved::helpers::type_mappings;
use crate::metadata::resolved::helpers::types::NdcColumnForComparison;
use crate::metadata::resolved::helpers::types::{mk_name, store_new_graphql_type};
use crate::metadata::resolved::stages::{
boolean_expressions, data_connector_scalar_types, data_connector_type_mappings,
data_connectors, graphql_config, scalar_types, type_permissions,
boolean_expressions, data_connector_scalar_types, data_connectors, graphql_config,
object_types, scalar_types, type_permissions,
};
use crate::metadata::resolved::types::subgraph::{
mk_qualified_type_reference, ArgumentInfo, Qualified,
Expand Down Expand Up @@ -179,7 +179,7 @@ fn resolve_filter_expression_type(

fn resolve_orderable_fields(
model: &ModelV1,
type_fields: &IndexMap<FieldName, data_connector_type_mappings::FieldDefinition>,
type_fields: &IndexMap<FieldName, object_types::FieldDefinition>,
) -> Result<Vec<OrderableField>, Error> {
for field in &model.orderable_fields {
// Check for unknown orderable field
Expand Down Expand Up @@ -452,16 +452,14 @@ fn resolve_model_graphql_api(
)?;
order_by_expression_type_name
.map(|order_by_type_name| {
let data_connector_type_mappings::TypeMapping::Object {
field_mappings,
..
} = model_source.type_mappings.get(&model.data_type).ok_or(
Error::TypeMappingRequired {
let object_types::TypeMapping::Object { field_mappings, .. } = model_source
.type_mappings
.get(&model.data_type)
.ok_or(Error::TypeMappingRequired {
model_name: model_name.clone(),
type_name: model.data_type.clone(),
data_connector: model_source.data_connector.name.clone(),
},
)?;
})?;

let mut order_by_fields = HashMap::new();
for (field_name, field_mapping) in field_mappings.iter() {
Expand Down Expand Up @@ -757,7 +755,7 @@ pub(crate) fn get_ndc_column_for_comparison<F: Fn() -> String>(
comparison_location: F,
) -> Result<NdcColumnForComparison, Error> {
// Get field mappings of model data type
let data_connector_type_mappings::TypeMapping::Object { field_mappings, .. } = model_source
let object_types::TypeMapping::Object { field_mappings, .. } = model_source
.type_mappings
.get(model_data_type)
.ok_or(Error::TypeMappingRequired {
Expand Down
9 changes: 3 additions & 6 deletions v3/crates/engine/src/metadata/resolved/stages/models/types.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use crate::metadata::resolved::helpers::types::NdcColumnForComparison;
use crate::metadata::resolved::stages::{
boolean_expressions, data_connector_type_mappings, data_connectors,
};
use crate::metadata::resolved::stages::{boolean_expressions, data_connectors, object_types};
use crate::metadata::resolved::types::subgraph::{
deserialize_qualified_btreemap, serialize_qualified_btreemap, ArgumentInfo, Qualified,
QualifiedTypeReference,
Expand Down Expand Up @@ -95,16 +93,15 @@ pub struct ModelSource {
serialize_with = "serialize_qualified_btreemap",
deserialize_with = "deserialize_qualified_btreemap"
)]
pub type_mappings:
BTreeMap<Qualified<CustomTypeName>, data_connector_type_mappings::TypeMapping>,
pub type_mappings: BTreeMap<Qualified<CustomTypeName>, object_types::TypeMapping>,
pub argument_mappings: HashMap<ArgumentName, String>,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
pub struct Model {
pub name: Qualified<ModelName>,
pub data_type: Qualified<CustomTypeName>,
pub type_fields: IndexMap<FieldName, data_connector_type_mappings::FieldDefinition>,
pub type_fields: IndexMap<FieldName, object_types::FieldDefinition>,
pub global_id_fields: Vec<FieldName>,
pub arguments: IndexMap<ArgumentName, ArgumentInfo>,
pub graphql_api: ModelGraphQlApi,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl DataConnectorTypeMappingsForObject {
}
}

/// output of `data_connector_type_mappings` step
/// output of `object_types` step
pub struct DataConnectorTypeMappingsOutput {
pub graphql_types: HashSet<ast::TypeName>,
pub global_id_enabled_types: HashMap<Qualified<CustomTypeName>, Vec<Qualified<ModelName>>>,
Expand Down
Loading

0 comments on commit 4f2a29b

Please sign in to comment.