diff --git a/v3/crates/metadata-resolve/src/helpers/argument.rs b/v3/crates/metadata-resolve/src/helpers/argument.rs index 3f8b17b9df8..50d6e2700da 100644 --- a/v3/crates/metadata-resolve/src/helpers/argument.rs +++ b/v3/crates/metadata-resolve/src/helpers/argument.rs @@ -273,7 +273,7 @@ pub(crate) fn resolve_value_expression_for_argument( models: &IndexMap, models_graphql::ModelWithGraphql>, data_connector_scalars: &BTreeMap< Qualified, - data_connector_scalar_types::ScalarTypeWithRepresentationInfoMap, + data_connector_scalar_types::DataConnectorScalars, >, ) -> Result { match value_expression { @@ -414,7 +414,10 @@ pub fn get_argument_kind( TypeName::Custom(type_name) => { let qualified_type_name = Qualified::new(subgraph.clone(), type_name.to_owned()); - match get_type_representation::( + match get_type_representation::< + type_permissions::ObjectTypesWithPermissions, + scalar_types::ScalarTypeRepresentation, + >( &qualified_type_name, &BTreeMap::new(), &BTreeMap::new(), diff --git a/v3/crates/metadata-resolve/src/helpers/types.rs b/v3/crates/metadata-resolve/src/helpers/types.rs index 6a34d5226d9..218b7353794 100644 --- a/v3/crates/metadata-resolve/src/helpers/types.rs +++ b/v3/crates/metadata-resolve/src/helpers/types.rs @@ -1,6 +1,6 @@ use crate::stages::{ boolean_expressions, graphql_config, object_boolean_expressions, object_relationships, - scalar_boolean_expressions, scalar_types, + scalar_boolean_expressions, }; use crate::types::error::Error; @@ -43,8 +43,8 @@ pub fn store_new_graphql_type( #[derive(Debug)] /// we do not want to store our types like this, but occasionally it is useful /// for pattern matching -pub enum TypeRepresentation<'a, ObjectType> { - Scalar(&'a scalar_types::ScalarTypeRepresentation), +pub enum TypeRepresentation<'a, ObjectType, ScalarType> { + Scalar(&'a ScalarType), Object(&'a ObjectType), /// The old expression of boolean expression types BooleanExpression(&'a object_boolean_expressions::ObjectBooleanExpressionType), @@ -56,16 +56,16 @@ pub enum TypeRepresentation<'a, ObjectType> { /// validate whether a given CustomTypeName exists within `object_types`, `scalar_types` or /// `object_boolean_expression_types` -pub fn get_type_representation<'a, ObjectType>( +pub fn get_type_representation<'a, ObjectType, ScalarType>( custom_type_name: &Qualified, object_types: &'a BTreeMap, ObjectType>, - scalar_types: &'a BTreeMap, scalar_types::ScalarTypeRepresentation>, + scalar_types: &'a BTreeMap, ScalarType>, object_boolean_expression_types: &'a BTreeMap< Qualified, object_boolean_expressions::ObjectBooleanExpressionType, >, boolean_expression_types: &'a boolean_expressions::BooleanExpressionTypes, -) -> Result, Error> { +) -> Result, Error> { object_types .get(custom_type_name) .map(|object_type_representation| TypeRepresentation::Object(object_type_representation)) diff --git a/v3/crates/metadata-resolve/src/lib.rs b/v3/crates/metadata-resolve/src/lib.rs index bf67ef772a6..9fe6460d3fd 100644 --- a/v3/crates/metadata-resolve/src/lib.rs +++ b/v3/crates/metadata-resolve/src/lib.rs @@ -64,7 +64,7 @@ pub use stages::order_by_expressions::{ }; pub use stages::plugins::LifecyclePluginConfigs; pub use stages::scalar_boolean_expressions::ResolvedScalarBooleanExpressionType; -pub use stages::scalar_types::ScalarTypeRepresentation; +pub use stages::scalar_type_representations::ScalarTypeRepresentation; pub use stages::type_permissions::{FieldPresetInfo, TypeInputPermission}; pub use stages::{ command_permissions::CommandWithPermissions, diff --git a/v3/crates/metadata-resolve/src/stages/aggregates/mod.rs b/v3/crates/metadata-resolve/src/stages/aggregates/mod.rs index edd73827eda..47a0ed8bc8e 100644 --- a/v3/crates/metadata-resolve/src/stages/aggregates/mod.rs +++ b/v3/crates/metadata-resolve/src/stages/aggregates/mod.rs @@ -8,10 +8,7 @@ use open_dds::types::{CustomTypeName, TypeName}; use crate::helpers::check_for_duplicates; use crate::helpers::types::{store_new_graphql_type, unwrap_qualified_type_name}; -use crate::stages::{ - data_connector_scalar_types::ScalarTypeWithRepresentationInfoMap, graphql_config, scalar_types, - type_permissions, -}; +use crate::stages::{data_connector_scalar_types, graphql_config, scalar_types, type_permissions}; use crate::types::subgraph::{mk_qualified_type_name, mk_qualified_type_reference}; use crate::{mk_name, Qualified, QualifiedBaseType, QualifiedTypeName, QualifiedTypeReference}; @@ -25,7 +22,7 @@ pub fn resolve( data_connectors: &data_connectors::DataConnectors, data_connector_scalars: &BTreeMap< Qualified, - ScalarTypeWithRepresentationInfoMap, + data_connector_scalar_types::DataConnectorScalars, >, object_types: &type_permissions::ObjectTypesWithPermissions, scalar_types: &BTreeMap, scalar_types::ScalarTypeRepresentation>, @@ -84,7 +81,7 @@ fn resolve_aggregate_expression( data_connectors: &data_connectors::DataConnectors, data_connector_scalars: &BTreeMap< Qualified, - ScalarTypeWithRepresentationInfoMap, + data_connector_scalar_types::DataConnectorScalars, >, object_types: &type_permissions::ObjectTypesWithPermissions, scalar_types: &BTreeMap, scalar_types::ScalarTypeRepresentation>, @@ -283,7 +280,7 @@ fn resolve_scalar_operand( data_connectors: &data_connectors::DataConnectors, data_connector_scalars: &BTreeMap< Qualified, - ScalarTypeWithRepresentationInfoMap, + data_connector_scalar_types::DataConnectorScalars, >, object_types: &type_permissions::ObjectTypesWithPermissions, scalar_types: &BTreeMap, scalar_types::ScalarTypeRepresentation>, @@ -358,7 +355,7 @@ fn resolve_aggregation_function( data_connectors: &data_connectors::DataConnectors, data_connector_scalars: &BTreeMap< Qualified, - ScalarTypeWithRepresentationInfoMap, + data_connector_scalar_types::DataConnectorScalars, >, ) -> Result { let return_type = mk_qualified_type_reference( @@ -420,7 +417,7 @@ fn resolve_aggregation_function( })?; // Check that the data connector operand scalar type actually exists on the data connector - let data_connector_scalar_type = scalars.0.get(&data_connector_fn_mappings.data_connector_scalar_type) + let data_connector_scalar_type = scalars.by_ndc_type.get(&data_connector_fn_mappings.data_connector_scalar_type) .ok_or_else(|| AggregateExpressionError::AggregateOperandDataConnectorFunctionUnknownScalarType { name: aggregate_expression_name.clone(), @@ -473,7 +470,7 @@ fn check_aggregation_function_return_type( aggregate_expression_name: &Qualified, aggregation_function_name: &AggregationFunctionName, data_connector_name: &Qualified, - data_connector_scalars: &ScalarTypeWithRepresentationInfoMap, + data_connector_scalars: &data_connector_scalar_types::DataConnectorScalars, scalar_types: &BTreeMap, scalar_types::ScalarTypeRepresentation>, object_types: &type_permissions::ObjectTypesWithPermissions, ) -> Result<(), AggregateExpressionError> { @@ -497,7 +494,7 @@ fn check_aggregation_function_return_type( )?; let validate_scalar_representation = || -> Result<(), AggregateExpressionError> { - let type_name = data_connector_scalars.0.get(ndc_named_return_type.as_str()) + let type_name = data_connector_scalars.by_ndc_type.get(ndc_named_return_type.as_str()) .ok_or_else(|| mk_error(format!("The data connector's return type ({ndc_named_return_type}) isn't a scalar type").as_str()) )? diff --git a/v3/crates/metadata-resolve/src/stages/command_permissions/command_permission.rs b/v3/crates/metadata-resolve/src/stages/command_permissions/command_permission.rs index 01e864c55f9..f34427cc0e9 100644 --- a/v3/crates/metadata-resolve/src/stages/command_permissions/command_permission.rs +++ b/v3/crates/metadata-resolve/src/stages/command_permissions/command_permission.rs @@ -55,7 +55,7 @@ pub fn resolve_command_permissions( data_connectors: &data_connectors::DataConnectors, data_connector_scalars: &BTreeMap< Qualified, - data_connector_scalar_types::ScalarTypeWithRepresentationInfoMap, + data_connector_scalar_types::DataConnectorScalars, >, subgraph: &SubgraphName, ) -> Result, Error> { diff --git a/v3/crates/metadata-resolve/src/stages/command_permissions/mod.rs b/v3/crates/metadata-resolve/src/stages/command_permissions/mod.rs index 36c999a3fe7..af99a7cff80 100644 --- a/v3/crates/metadata-resolve/src/stages/command_permissions/mod.rs +++ b/v3/crates/metadata-resolve/src/stages/command_permissions/mod.rs @@ -35,7 +35,7 @@ pub fn resolve( data_connectors: &data_connectors::DataConnectors, data_connector_scalars: &BTreeMap< Qualified, - data_connector_scalar_types::ScalarTypeWithRepresentationInfoMap, + data_connector_scalar_types::DataConnectorScalars, >, ) -> Result, CommandWithPermissions>, Error> { let mut commands_with_permissions: IndexMap, CommandWithPermissions> = diff --git a/v3/crates/metadata-resolve/src/stages/data_connector_scalar_types/mod.rs b/v3/crates/metadata-resolve/src/stages/data_connector_scalar_types/mod.rs index f70f67ba96f..7d2aa957708 100644 --- a/v3/crates/metadata-resolve/src/stages/data_connector_scalar_types/mod.rs +++ b/v3/crates/metadata-resolve/src/stages/data_connector_scalar_types/mod.rs @@ -4,8 +4,8 @@ pub use error::DataConnectorScalarTypesError; use open_dds::identifier::SubgraphName; use std::collections::{BTreeMap, BTreeSet}; pub use types::{ - ComparisonOperators, DataConnectorWithScalarsOutput, ScalarTypeWithRepresentationInfo, - ScalarTypeWithRepresentationInfoMap, + ComparisonOperators, DataConnectorScalars, DataConnectorWithScalarsOutput, + ScalarTypeWithRepresentationInfo, }; use lang_graphql::ast::common as ast; @@ -54,15 +54,15 @@ pub fn resolve<'a>( data_connector: qualified_data_connector_name.clone(), })?; - let scalar_type = scalars - .0 + let scalar_type_by_ndc_type = scalars + .by_ndc_type .get_mut(&scalar_type_representation.data_connector_scalar_type) .ok_or_else(|| scalar_boolean_expressions::ScalarBooleanExpressionTypeError::UnknownScalarTypeInDataConnector { scalar_type: scalar_type_name.clone(), data_connector: qualified_data_connector_name.clone(), })?; - if scalar_type.representation.is_none() { + if scalar_type_by_ndc_type.representation.is_none() { validate_type_name( &scalar_type_representation.representation, subgraph, @@ -70,7 +70,35 @@ pub fn resolve<'a>( scalar_type_name, )?; - scalar_type.representation = Some(scalar_type_representation.representation.clone()); + scalar_type_by_ndc_type.representation = + Some(scalar_type_representation.representation.clone()); + + // if this is a custom scalar type, + // record the TypeRepresentation for it (ie, `String`, `JSON`, etc) + if let TypeName::Custom(custom_type_name) = &scalar_type_representation.representation { + let data_connector_context = data_connectors + .0 + .get(&qualified_data_connector_name) + .unwrap(); + + let ndc_scalar_name = ndc_models::ScalarTypeName::new(ndc_models::TypeName::new( + scalar_type_representation + .data_connector_scalar_type + .clone() + .into(), + )); + + let ndc_scalar_type = data_connector_context + .schema + .scalar_types + .get(&ndc_scalar_name) + .unwrap(); + + scalars.by_custom_type_name.insert( + Qualified::new(subgraph.clone(), custom_type_name.clone()), + ndc_scalar_type.representation.clone(), + ); + } } else { return Err( DataConnectorScalarTypesError::DuplicateDataConnectorScalarRepresentation { @@ -79,13 +107,14 @@ pub fn resolve<'a>( }, ); } - scalar_type.comparison_expression_name = match scalar_type_representation.graphql.as_ref() { - None => Ok(None), - Some(graphql) => match &graphql.comparison_expression_type_name { + scalar_type_by_ndc_type.comparison_expression_name = + match scalar_type_representation.graphql.as_ref() { None => Ok(None), - Some(type_name) => mk_name(type_name.as_ref()).map(ast::TypeName).map(Some), - }, - }?; + Some(graphql) => match &graphql.comparison_expression_type_name { + None => Ok(None), + Some(type_name) => mk_name(type_name.as_ref()).map(ast::TypeName).map(Some), + }, + }?; // We are allowing conflicting graphql types for scalar comparison expressions, but we still want the typename // to not conflict with other graphql type names @@ -93,7 +122,7 @@ pub fn resolve<'a>( // TODO: This means that comparison expression names conflicting with already encountered graphql type names // will pass through. They'll eventually be caught during schema generation but only if the expression was // reachable in the graphql API. Ideally, we should just fail the build here. - if let Some(new_graphql_type) = &scalar_type.comparison_expression_name { + if let Some(new_graphql_type) = &scalar_type_by_ndc_type.comparison_expression_name { graphql_types.insert(new_graphql_type.clone()); }; } @@ -128,15 +157,15 @@ fn validate_type_name( // convert from types in previous stage to this stage fn convert_data_connectors_contexts<'a>( old_data_connectors: &'a data_connectors::DataConnectors<'a>, -) -> BTreeMap, ScalarTypeWithRepresentationInfoMap<'a>> { +) -> BTreeMap, DataConnectorScalars<'a>> { let mut data_connector_scalars = BTreeMap::new(); for (data_connector_name, context) in &old_data_connectors.0 { - let mut new_scalars = BTreeMap::new(); + let mut by_ndc_type = BTreeMap::new(); for (name, scalar) in &context.schema.scalar_types { - let scalar_name = DataConnectorScalarType::from(name.as_str()); - new_scalars.insert( - scalar_name.clone(), + let ndc_scalar_type_name = DataConnectorScalarType::from(name.as_str()); + by_ndc_type.insert( + ndc_scalar_type_name.clone(), ScalarTypeWithRepresentationInfo { scalar_type: scalar, comparison_expression_name: None, @@ -149,7 +178,10 @@ fn convert_data_connectors_contexts<'a>( data_connector_scalars.insert( data_connector_name.clone(), - ScalarTypeWithRepresentationInfoMap(new_scalars), + DataConnectorScalars { + by_ndc_type, + by_custom_type_name: BTreeMap::new(), + }, ); } data_connector_scalars @@ -190,10 +222,10 @@ pub(crate) fn get_comparison_operators( // helper function to determine whether a ndc type is a simple scalar pub fn get_simple_scalar<'a>( t: ndc_models::Type, - scalars: &'a ScalarTypeWithRepresentationInfoMap<'a>, + scalars: &'a DataConnectorScalars<'a>, ) -> Option<&'a ScalarTypeWithRepresentationInfo<'a>> { match t { - ndc_models::Type::Named { name } => scalars.0.get(name.as_str()), + ndc_models::Type::Named { name } => scalars.by_ndc_type.get(name.as_str()), ndc_models::Type::Nullable { underlying_type } => { get_simple_scalar(*underlying_type, scalars) } diff --git a/v3/crates/metadata-resolve/src/stages/data_connector_scalar_types/types.rs b/v3/crates/metadata-resolve/src/stages/data_connector_scalar_types/types.rs index 6655ad208cb..1ab74880253 100644 --- a/v3/crates/metadata-resolve/src/stages/data_connector_scalar_types/types.rs +++ b/v3/crates/metadata-resolve/src/stages/data_connector_scalar_types/types.rs @@ -4,13 +4,12 @@ use ndc_models; use open_dds::data_connector::{ DataConnectorName, DataConnectorOperatorName, DataConnectorScalarType, }; -use open_dds::types::TypeName; +use open_dds::types::{CustomTypeName, TypeName}; use std::collections::BTreeMap; use std::collections::BTreeSet; pub struct DataConnectorWithScalarsOutput<'a> { - pub data_connector_scalars: - BTreeMap, ScalarTypeWithRepresentationInfoMap<'a>>, + pub data_connector_scalars: BTreeMap, DataConnectorScalars<'a>>, pub graphql_types: BTreeSet, } @@ -26,9 +25,11 @@ pub struct ScalarTypeWithRepresentationInfo<'a> { } #[derive(Debug)] -pub struct ScalarTypeWithRepresentationInfoMap<'a>( - pub BTreeMap>, -); +pub struct DataConnectorScalars<'a> { + pub by_ndc_type: BTreeMap>, + pub by_custom_type_name: + BTreeMap, Option>, +} #[derive(Clone, Debug, PartialEq, Eq, Hash, Default)] pub struct ComparisonOperators { diff --git a/v3/crates/metadata-resolve/src/stages/mod.rs b/v3/crates/metadata-resolve/src/stages/mod.rs index 0e6e64d45a2..9835e7a4409 100644 --- a/v3/crates/metadata-resolve/src/stages/mod.rs +++ b/v3/crates/metadata-resolve/src/stages/mod.rs @@ -27,6 +27,7 @@ mod types; use crate::types::warning::Warning; use open_dds::flags; pub use types::Metadata; +pub mod scalar_type_representations; use crate::types::configuration::Configuration; use crate::types::error::{Error, SeparatedBy, ShouldBeAnError, WithContext}; @@ -316,13 +317,17 @@ pub fn resolve( &commands_with_permissions, ); + // include data connector information for each scalar type + let scalar_types_with_representations = + scalar_type_representations::resolve(&data_connector_scalars, &scalar_types); + let plugin_configs = plugins::resolve(&metadata_accessor); let all_warnings = warnings_as_errors_by_compatibility(&metadata_accessor.flags, all_issues)?; Ok(( Metadata { - scalar_types, + scalar_types: scalar_types_with_representations, object_types: object_types_with_relationships, models, commands, diff --git a/v3/crates/metadata-resolve/src/stages/model_permissions/mod.rs b/v3/crates/metadata-resolve/src/stages/model_permissions/mod.rs index ed503d16e48..a3786170e37 100644 --- a/v3/crates/metadata-resolve/src/stages/model_permissions/mod.rs +++ b/v3/crates/metadata-resolve/src/stages/model_permissions/mod.rs @@ -23,7 +23,7 @@ pub fn resolve( data_connectors: &data_connectors::DataConnectors, data_connector_scalars: &BTreeMap< Qualified, - data_connector_scalar_types::ScalarTypeWithRepresentationInfoMap, + data_connector_scalar_types::DataConnectorScalars, >, object_types: &BTreeMap< Qualified, diff --git a/v3/crates/metadata-resolve/src/stages/model_permissions/model_permission.rs b/v3/crates/metadata-resolve/src/stages/model_permissions/model_permission.rs index da38aef23ea..cf366fb7d43 100644 --- a/v3/crates/metadata-resolve/src/stages/model_permissions/model_permission.rs +++ b/v3/crates/metadata-resolve/src/stages/model_permissions/model_permission.rs @@ -41,7 +41,7 @@ fn resolve_model_predicate_with_model( data_connectors: &data_connectors::DataConnectors, data_connector_scalars: &BTreeMap< Qualified, - data_connector_scalar_types::ScalarTypeWithRepresentationInfoMap, + data_connector_scalar_types::DataConnectorScalars, >, fields: &IndexMap, object_types: &BTreeMap< @@ -146,7 +146,7 @@ pub fn resolve_model_select_permissions( data_connectors: &data_connectors::DataConnectors, data_connector_scalars: &BTreeMap< Qualified, - data_connector_scalar_types::ScalarTypeWithRepresentationInfoMap, + data_connector_scalar_types::DataConnectorScalars, >, object_types: &BTreeMap< Qualified, @@ -282,7 +282,7 @@ pub(crate) fn resolve_model_predicate_with_type( data_connector_field_mappings: &BTreeMap, data_connector_link: &data_connectors::DataConnectorLink, subgraph: &SubgraphName, - scalars: &data_connector_scalar_types::ScalarTypeWithRepresentationInfoMap, + scalars: &data_connector_scalar_types::DataConnectorScalars, object_types: &BTreeMap< Qualified, object_relationships::ObjectTypeWithRelationships, @@ -811,7 +811,7 @@ fn resolve_binary_operator_for_type<'a>( data_connector: &'a Qualified, field_name: &'a FieldName, fields: &'a IndexMap, - scalars: &'a data_connector_scalar_types::ScalarTypeWithRepresentationInfoMap, + scalars: &'a data_connector_scalar_types::DataConnectorScalars, ndc_scalar_type: &'a ndc_models::ScalarType, subgraph: &'a SubgraphName, ) -> Result<(DataConnectorOperatorName, QualifiedTypeReference), Error> { diff --git a/v3/crates/metadata-resolve/src/stages/models/helpers.rs b/v3/crates/metadata-resolve/src/stages/models/helpers.rs index 00bd857f12d..4c21d03085d 100644 --- a/v3/crates/metadata-resolve/src/stages/models/helpers.rs +++ b/v3/crates/metadata-resolve/src/stages/models/helpers.rs @@ -19,7 +19,7 @@ pub fn get_ndc_column_for_comparison String>( field: &FieldName, data_connector_scalars: &BTreeMap< Qualified, - data_connector_scalar_types::ScalarTypeWithRepresentationInfoMap, + data_connector_scalar_types::DataConnectorScalars, >, comparison_location: F, ) -> Result { diff --git a/v3/crates/metadata-resolve/src/stages/models/mod.rs b/v3/crates/metadata-resolve/src/stages/models/mod.rs index 5682bca7d5a..68141ba1b79 100644 --- a/v3/crates/metadata-resolve/src/stages/models/mod.rs +++ b/v3/crates/metadata-resolve/src/stages/models/mod.rs @@ -45,7 +45,7 @@ pub fn resolve( data_connectors: &data_connectors::DataConnectors, data_connector_scalars: &BTreeMap< Qualified, - data_connector_scalar_types::ScalarTypeWithRepresentationInfoMap, + data_connector_scalar_types::DataConnectorScalars, >, mut global_id_enabled_types: BTreeMap, Vec>>, mut apollo_federation_entity_enabled_types: BTreeMap< diff --git a/v3/crates/metadata-resolve/src/stages/models/source.rs b/v3/crates/metadata-resolve/src/stages/models/source.rs index 4550e6f4f93..380f8aebba0 100644 --- a/v3/crates/metadata-resolve/src/stages/models/source.rs +++ b/v3/crates/metadata-resolve/src/stages/models/source.rs @@ -31,7 +31,7 @@ pub(crate) fn resolve_model_source( data_connectors: &data_connectors::DataConnectors, data_connector_scalars: &BTreeMap< Qualified, - data_connector_scalar_types::ScalarTypeWithRepresentationInfoMap, + data_connector_scalar_types::DataConnectorScalars, >, object_types: &type_permissions::ObjectTypesWithPermissions, scalar_types: &BTreeMap, scalar_types::ScalarTypeRepresentation>, diff --git a/v3/crates/metadata-resolve/src/stages/models_graphql/graphql.rs b/v3/crates/metadata-resolve/src/stages/models_graphql/graphql.rs index 2370689aa70..2f023d435ca 100644 --- a/v3/crates/metadata-resolve/src/stages/models_graphql/graphql.rs +++ b/v3/crates/metadata-resolve/src/stages/models_graphql/graphql.rs @@ -30,7 +30,7 @@ pub(crate) fn resolve_model_graphql_api( existing_graphql_types: &mut BTreeSet, data_connector_scalars: &BTreeMap< Qualified, - data_connector_scalar_types::ScalarTypeWithRepresentationInfoMap, + data_connector_scalar_types::DataConnectorScalars, >, model_description: &Option, aggregate_expression_name: &Option>, diff --git a/v3/crates/metadata-resolve/src/stages/models_graphql/mod.rs b/v3/crates/metadata-resolve/src/stages/models_graphql/mod.rs index 3a0f015fd11..8760ad46a8f 100644 --- a/v3/crates/metadata-resolve/src/stages/models_graphql/mod.rs +++ b/v3/crates/metadata-resolve/src/stages/models_graphql/mod.rs @@ -31,7 +31,7 @@ pub fn resolve( models: &IndexMap, models::Model>, data_connector_scalars: &BTreeMap< Qualified, - data_connector_scalar_types::ScalarTypeWithRepresentationInfoMap, + data_connector_scalar_types::DataConnectorScalars, >, object_types: &BTreeMap< Qualified, diff --git a/v3/crates/metadata-resolve/src/stages/object_boolean_expressions/helpers.rs b/v3/crates/metadata-resolve/src/stages/object_boolean_expressions/helpers.rs index 1594d09d81e..0922a0f848b 100644 --- a/v3/crates/metadata-resolve/src/stages/object_boolean_expressions/helpers.rs +++ b/v3/crates/metadata-resolve/src/stages/object_boolean_expressions/helpers.rs @@ -14,12 +14,12 @@ use open_dds::identifier::SubgraphName; pub fn resolve_ndc_type( data_connector: &Qualified, source_type: &ndc_models::Type, - scalars: &data_connector_scalar_types::ScalarTypeWithRepresentationInfoMap, + scalars: &data_connector_scalar_types::DataConnectorScalars, subgraph: &SubgraphName, ) -> Result { match source_type { ndc_models::Type::Named { name } => { - let scalar_type = scalars.0.get(name.as_str()).ok_or( + let scalar_type = scalars.by_ndc_type.get(name.as_str()).ok_or( scalar_boolean_expressions::ScalarBooleanExpressionTypeError::UnknownScalarTypeInDataConnector { data_connector: data_connector.clone(), scalar_type: DataConnectorScalarType::from(name.as_str()), diff --git a/v3/crates/metadata-resolve/src/stages/object_boolean_expressions/mod.rs b/v3/crates/metadata-resolve/src/stages/object_boolean_expressions/mod.rs index 1e50aabfc4f..6316752237d 100644 --- a/v3/crates/metadata-resolve/src/stages/object_boolean_expressions/mod.rs +++ b/v3/crates/metadata-resolve/src/stages/object_boolean_expressions/mod.rs @@ -25,7 +25,7 @@ pub fn resolve( data_connectors: &data_connectors::DataConnectors, data_connector_scalars: &BTreeMap< Qualified, - data_connector_scalar_types::ScalarTypeWithRepresentationInfoMap, + data_connector_scalar_types::DataConnectorScalars, >, object_types: &type_permissions::ObjectTypesWithPermissions, mut graphql_types: BTreeSet, @@ -83,7 +83,7 @@ pub(crate) fn resolve_object_boolean_expression_type( data_connectors: &data_connectors::DataConnectors, data_connector_scalars: &BTreeMap< Qualified, - data_connector_scalar_types::ScalarTypeWithRepresentationInfoMap, + data_connector_scalar_types::DataConnectorScalars, >, object_types: &type_permissions::ObjectTypesWithPermissions, existing_graphql_types: &mut BTreeSet, @@ -263,7 +263,7 @@ pub fn resolve_boolean_expression_graphql_config( data_connector_name: &Qualified, where_type_name: ast::TypeName, subgraph: &SubgraphName, - scalars: &data_connector_scalar_types::ScalarTypeWithRepresentationInfoMap, + scalars: &data_connector_scalar_types::DataConnectorScalars, type_mappings: &object_types::TypeMapping, graphql_config: &graphql_config::GraphqlConfig, fields: &IndexMap, diff --git a/v3/crates/metadata-resolve/src/stages/object_relationships/mod.rs b/v3/crates/metadata-resolve/src/stages/object_relationships/mod.rs index d2f8c2f9767..207c2e69ad5 100644 --- a/v3/crates/metadata-resolve/src/stages/object_relationships/mod.rs +++ b/v3/crates/metadata-resolve/src/stages/object_relationships/mod.rs @@ -36,7 +36,7 @@ pub fn resolve( data_connectors: &data_connectors::DataConnectors, data_connector_scalars: &BTreeMap< Qualified, - data_connector_scalar_types::ScalarTypeWithRepresentationInfoMap, + data_connector_scalar_types::DataConnectorScalars, >, models: &IndexMap, models::Model>, commands: &IndexMap, commands::Command>, @@ -193,7 +193,7 @@ fn resolve_relationship_mappings_model( target_model: &models::Model, data_connector_scalars: &BTreeMap< Qualified, - data_connector_scalar_types::ScalarTypeWithRepresentationInfoMap, + data_connector_scalar_types::DataConnectorScalars, >, ) -> Result, Error> { let mut resolved_relationship_mappings = Vec::new(); @@ -548,7 +548,7 @@ fn resolve_model_relationship_fields( source_type: &object_types::ObjectTypeRepresentation, data_connector_scalars: &BTreeMap< Qualified, - data_connector_scalar_types::ScalarTypeWithRepresentationInfoMap, + data_connector_scalar_types::DataConnectorScalars, >, aggregate_expressions: &BTreeMap< Qualified, @@ -701,7 +701,7 @@ fn resolve_relationship_fields( data_connectors: &data_connectors::DataConnectors, data_connector_scalars: &BTreeMap< Qualified, - data_connector_scalar_types::ScalarTypeWithRepresentationInfoMap, + data_connector_scalar_types::DataConnectorScalars, >, aggregate_expressions: &BTreeMap< Qualified, diff --git a/v3/crates/metadata-resolve/src/stages/scalar_type_representations/mod.rs b/v3/crates/metadata-resolve/src/stages/scalar_type_representations/mod.rs new file mode 100644 index 00000000000..6d259ec6cdf --- /dev/null +++ b/v3/crates/metadata-resolve/src/stages/scalar_type_representations/mod.rs @@ -0,0 +1,42 @@ +use crate::stages::{data_connector_scalar_types, scalar_types}; +use crate::Qualified; +use open_dds::{data_connector::DataConnectorName, types::CustomTypeName}; +use std::collections::BTreeMap; +mod types; +pub use types::{ScalarTypeRepresentation, ValueRepresentation}; + +/// include data connector type representations for each scalar type +pub fn resolve( + data_connector_scalar_types: &BTreeMap< + Qualified, + data_connector_scalar_types::DataConnectorScalars, + >, + scalar_types: &BTreeMap, scalar_types::ScalarTypeRepresentation>, +) -> BTreeMap, ScalarTypeRepresentation> { + let mut new_scalar_types = BTreeMap::new(); + for (scalar_type_name, scalar_type) in scalar_types { + let mut representations = BTreeMap::new(); + // grab information about this scalar from each data connector + for (data_connector_name, data_connector_scalars) in data_connector_scalar_types { + if let Some(data_connector_representation) = data_connector_scalars + .by_custom_type_name + .get(scalar_type_name) + { + let scalar_type_representation = match data_connector_representation { + Some(rep) => ValueRepresentation::FromDataConnectorSchema(rep.clone()), + None => ValueRepresentation::AssumeJson, + }; + representations.insert(data_connector_name.clone(), scalar_type_representation); + } + } + new_scalar_types.insert( + scalar_type_name.clone(), + ScalarTypeRepresentation { + graphql_type_name: scalar_type.graphql_type_name.clone(), + description: scalar_type.description.clone(), + representations, + }, + ); + } + new_scalar_types +} diff --git a/v3/crates/metadata-resolve/src/stages/scalar_type_representations/types.rs b/v3/crates/metadata-resolve/src/stages/scalar_type_representations/types.rs new file mode 100644 index 00000000000..02087359ef5 --- /dev/null +++ b/v3/crates/metadata-resolve/src/stages/scalar_type_representations/types.rs @@ -0,0 +1,24 @@ +use crate::{deserialize_non_string_key_btreemap, serialize_non_string_key_btreemap, Qualified}; +use lang_graphql::ast::common as ast; +use open_dds::data_connector::DataConnectorName; +use serde::{Deserialize, Serialize}; +use std::collections::BTreeMap; + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] +// what type should we advertise for this value? useful for generating schema for +// JSONAPI and SQL frontends +pub enum ValueRepresentation { + FromDataConnectorSchema(ndc_models::TypeRepresentation), + AssumeJson, +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] +pub struct ScalarTypeRepresentation { + pub graphql_type_name: Option, + pub description: Option, + #[serde( + serialize_with = "serialize_non_string_key_btreemap", + deserialize_with = "deserialize_non_string_key_btreemap" + )] + pub representations: BTreeMap, ValueRepresentation>, +} diff --git a/v3/crates/metadata-resolve/src/stages/types.rs b/v3/crates/metadata-resolve/src/stages/types.rs index bb0dafde604..aebccc4aa83 100644 --- a/v3/crates/metadata-resolve/src/stages/types.rs +++ b/v3/crates/metadata-resolve/src/stages/types.rs @@ -14,7 +14,7 @@ use crate::types::subgraph::Qualified; use crate::stages::{ aggregates, argument_presets, boolean_expressions, graphql_config, object_boolean_expressions, - object_relationships, order_by_expressions, scalar_types, + object_relationships, order_by_expressions, scalar_type_representations, }; use super::plugins::LifecyclePluginConfigs; @@ -27,7 +27,8 @@ pub struct Metadata { pub object_types: BTreeMap, object_relationships::ObjectTypeWithRelationships>, #[serde_as(as = "Vec<(_, _)>")] - pub scalar_types: BTreeMap, scalar_types::ScalarTypeRepresentation>, + pub scalar_types: + BTreeMap, scalar_type_representations::ScalarTypeRepresentation>, #[serde_as(as = "Vec<(_, _)>")] pub models: IndexMap, argument_presets::ModelWithArgumentPresets>, #[serde_as(as = "Vec<(_, _)>")] diff --git a/v3/crates/metadata-resolve/tests/passing/aggregate_expressions/missing_aggregate_graphql_config/resolved.snap b/v3/crates/metadata-resolve/tests/passing/aggregate_expressions/missing_aggregate_graphql_config/resolved.snap index 986b710f774..ab85f213f04 100644 --- a/v3/crates/metadata-resolve/tests/passing/aggregate_expressions/missing_aggregate_graphql_config/resolved.snap +++ b/v3/crates/metadata-resolve/tests/passing/aggregate_expressions/missing_aggregate_graphql_config/resolved.snap @@ -299,6 +299,7 @@ input_file: crates/metadata-resolve/tests/passing/aggregate_expressions/missing_ ), ), description: None, + representations: {}, }, }, models: {}, diff --git a/v3/crates/metadata-resolve/tests/passing/aggregate_expressions/missing_filter_input_field_name_in_graphql_config/resolved.snap b/v3/crates/metadata-resolve/tests/passing/aggregate_expressions/missing_filter_input_field_name_in_graphql_config/resolved.snap index 09d8ae52610..adc038c4839 100644 --- a/v3/crates/metadata-resolve/tests/passing/aggregate_expressions/missing_filter_input_field_name_in_graphql_config/resolved.snap +++ b/v3/crates/metadata-resolve/tests/passing/aggregate_expressions/missing_filter_input_field_name_in_graphql_config/resolved.snap @@ -985,6 +985,20 @@ input_file: crates/metadata-resolve/tests/passing/aggregate_expressions/missing_ ), ), description: None, + representations: { + Qualified { + subgraph: SubgraphName( + "default", + ), + name: DataConnectorName( + Identifier( + "mypg", + ), + ), + }: FromDataConnectorSchema( + Int32, + ), + }, }, Qualified { subgraph: SubgraphName( @@ -1004,6 +1018,18 @@ input_file: crates/metadata-resolve/tests/passing/aggregate_expressions/missing_ ), ), description: None, + representations: { + Qualified { + subgraph: SubgraphName( + "default", + ), + name: DataConnectorName( + Identifier( + "mypg", + ), + ), + }: AssumeJson, + }, }, }, models: { diff --git a/v3/crates/metadata-resolve/tests/passing/aggregate_expressions/relationship/resolved.snap b/v3/crates/metadata-resolve/tests/passing/aggregate_expressions/relationship/resolved.snap index 649f6cb2f0c..830be44525d 100644 --- a/v3/crates/metadata-resolve/tests/passing/aggregate_expressions/relationship/resolved.snap +++ b/v3/crates/metadata-resolve/tests/passing/aggregate_expressions/relationship/resolved.snap @@ -1637,6 +1637,20 @@ input_file: crates/metadata-resolve/tests/passing/aggregate_expressions/relation ), ), description: None, + representations: { + Qualified { + subgraph: SubgraphName( + "default", + ), + name: DataConnectorName( + Identifier( + "mypg", + ), + ), + }: FromDataConnectorSchema( + Int32, + ), + }, }, Qualified { subgraph: SubgraphName( @@ -1656,6 +1670,18 @@ input_file: crates/metadata-resolve/tests/passing/aggregate_expressions/relation ), ), description: None, + representations: { + Qualified { + subgraph: SubgraphName( + "default", + ), + name: DataConnectorName( + Identifier( + "mypg", + ), + ), + }: AssumeJson, + }, }, }, models: { diff --git a/v3/crates/metadata-resolve/tests/passing/aggregate_expressions/root_field/resolved.snap b/v3/crates/metadata-resolve/tests/passing/aggregate_expressions/root_field/resolved.snap index b444257325d..283f37da812 100644 --- a/v3/crates/metadata-resolve/tests/passing/aggregate_expressions/root_field/resolved.snap +++ b/v3/crates/metadata-resolve/tests/passing/aggregate_expressions/root_field/resolved.snap @@ -985,6 +985,20 @@ input_file: crates/metadata-resolve/tests/passing/aggregate_expressions/root_fie ), ), description: None, + representations: { + Qualified { + subgraph: SubgraphName( + "default", + ), + name: DataConnectorName( + Identifier( + "mypg", + ), + ), + }: FromDataConnectorSchema( + Int32, + ), + }, }, Qualified { subgraph: SubgraphName( @@ -1004,6 +1018,18 @@ input_file: crates/metadata-resolve/tests/passing/aggregate_expressions/root_fie ), ), description: None, + representations: { + Qualified { + subgraph: SubgraphName( + "default", + ), + name: DataConnectorName( + Identifier( + "mypg", + ), + ), + }: AssumeJson, + }, }, }, models: { diff --git a/v3/crates/metadata-resolve/tests/passing/commands/functions/all_args_are_set_including_connector_link_presets/resolved.snap b/v3/crates/metadata-resolve/tests/passing/commands/functions/all_args_are_set_including_connector_link_presets/resolved.snap index e48860f3ece..48d1833dcde 100644 --- a/v3/crates/metadata-resolve/tests/passing/commands/functions/all_args_are_set_including_connector_link_presets/resolved.snap +++ b/v3/crates/metadata-resolve/tests/passing/commands/functions/all_args_are_set_including_connector_link_presets/resolved.snap @@ -27,6 +27,20 @@ input_file: crates/metadata-resolve/tests/passing/commands/functions/all_args_ar description: Some( "Headers map", ), + representations: { + Qualified { + subgraph: SubgraphName( + "default", + ), + name: DataConnectorName( + Identifier( + "myconnector", + ), + ), + }: FromDataConnectorSchema( + JSON, + ), + }, }, }, models: {}, diff --git a/v3/crates/metadata-resolve/tests/passing/commands/functions/issue_when_not_all_arguments_defined/resolved.snap b/v3/crates/metadata-resolve/tests/passing/commands/functions/issue_when_not_all_arguments_defined/resolved.snap index b49637ee56a..f06f9d78612 100644 --- a/v3/crates/metadata-resolve/tests/passing/commands/functions/issue_when_not_all_arguments_defined/resolved.snap +++ b/v3/crates/metadata-resolve/tests/passing/commands/functions/issue_when_not_all_arguments_defined/resolved.snap @@ -27,6 +27,20 @@ input_file: crates/metadata-resolve/tests/passing/commands/functions/issue_when_ description: Some( "Headers map", ), + representations: { + Qualified { + subgraph: SubgraphName( + "default", + ), + name: DataConnectorName( + Identifier( + "myconnector", + ), + ), + }: FromDataConnectorSchema( + JSON, + ), + }, }, }, models: {}, diff --git a/v3/crates/metadata-resolve/tests/passing/commands/procedures/all_args_are_set_including_connector_link_presets/resolved.snap b/v3/crates/metadata-resolve/tests/passing/commands/procedures/all_args_are_set_including_connector_link_presets/resolved.snap index e412f430192..2faa8b9f8ff 100644 --- a/v3/crates/metadata-resolve/tests/passing/commands/procedures/all_args_are_set_including_connector_link_presets/resolved.snap +++ b/v3/crates/metadata-resolve/tests/passing/commands/procedures/all_args_are_set_including_connector_link_presets/resolved.snap @@ -27,6 +27,20 @@ input_file: crates/metadata-resolve/tests/passing/commands/procedures/all_args_a description: Some( "Headers map", ), + representations: { + Qualified { + subgraph: SubgraphName( + "default", + ), + name: DataConnectorName( + Identifier( + "myconnector", + ), + ), + }: FromDataConnectorSchema( + JSON, + ), + }, }, }, models: {}, diff --git a/v3/crates/metadata-resolve/tests/passing/commands/procedures/issue_when_not_all_arguments_defined/resolved.snap b/v3/crates/metadata-resolve/tests/passing/commands/procedures/issue_when_not_all_arguments_defined/resolved.snap index 01c65bce9f7..61c94de4f92 100644 --- a/v3/crates/metadata-resolve/tests/passing/commands/procedures/issue_when_not_all_arguments_defined/resolved.snap +++ b/v3/crates/metadata-resolve/tests/passing/commands/procedures/issue_when_not_all_arguments_defined/resolved.snap @@ -27,6 +27,20 @@ input_file: crates/metadata-resolve/tests/passing/commands/procedures/issue_when description: Some( "Headers map", ), + representations: { + Qualified { + subgraph: SubgraphName( + "default", + ), + name: DataConnectorName( + Identifier( + "myconnector", + ), + ), + }: FromDataConnectorSchema( + JSON, + ), + }, }, }, models: {}, diff --git a/v3/crates/metadata-resolve/tests/passing/models/all_args_are_set_including_connector_link_presets/resolved.snap b/v3/crates/metadata-resolve/tests/passing/models/all_args_are_set_including_connector_link_presets/resolved.snap index 535343e1cf6..2928801ced6 100644 --- a/v3/crates/metadata-resolve/tests/passing/models/all_args_are_set_including_connector_link_presets/resolved.snap +++ b/v3/crates/metadata-resolve/tests/passing/models/all_args_are_set_including_connector_link_presets/resolved.snap @@ -126,6 +126,20 @@ input_file: crates/metadata-resolve/tests/passing/models/all_args_are_set_includ description: Some( "Headers map", ), + representations: { + Qualified { + subgraph: SubgraphName( + "default", + ), + name: DataConnectorName( + Identifier( + "myconnector", + ), + ), + }: FromDataConnectorSchema( + JSON, + ), + }, }, }, models: { diff --git a/v3/crates/metadata-resolve/tests/passing/models/issue_when_not_all_arguments_defined/resolved.snap b/v3/crates/metadata-resolve/tests/passing/models/issue_when_not_all_arguments_defined/resolved.snap index fe19d8da140..ee31c2581d1 100644 --- a/v3/crates/metadata-resolve/tests/passing/models/issue_when_not_all_arguments_defined/resolved.snap +++ b/v3/crates/metadata-resolve/tests/passing/models/issue_when_not_all_arguments_defined/resolved.snap @@ -126,6 +126,20 @@ input_file: crates/metadata-resolve/tests/passing/models/issue_when_not_all_argu description: Some( "Headers map", ), + representations: { + Qualified { + subgraph: SubgraphName( + "default", + ), + name: DataConnectorName( + Identifier( + "myconnector", + ), + ), + }: FromDataConnectorSchema( + JSON, + ), + }, }, }, models: {