From 00db411c6e89686850e14d932de39fd4c78fa9eb Mon Sep 17 00:00:00 2001 From: Samir Talwar Date: Thu, 27 Jun 2024 11:12:20 +0200 Subject: [PATCH] Remove `ModelsGraphqlOutput::graphql_types`, as it's not used. (#769) ### What This removes an unused field. The remaining struct had just one field and is private to the crate, so I converted it to a type alias. ### How In order to make `rustc` highlight the issue, I reduced the number of types we export as `pub`, changing some to `pub(crate)`. Then I just deleted the field once the warning showed up. V3_GIT_ORIGIN_REV_ID: 7a26e99f062ed0f2c7449e1f57bc76068f059afb --- v3/crates/metadata-resolve/src/stages/mod.rs | 5 +-- .../src/stages/model_permissions/types.rs | 27 ++++++------ .../src/stages/models_graphql/mod.rs | 41 ++++++++++--------- .../src/stages/models_graphql/types.rs | 25 +++++------ 4 files changed, 46 insertions(+), 52 deletions(-) diff --git a/v3/crates/metadata-resolve/src/stages/mod.rs b/v3/crates/metadata-resolve/src/stages/mod.rs index ce8b36411a2..5d2a8e70043 100644 --- a/v3/crates/metadata-resolve/src/stages/mod.rs +++ b/v3/crates/metadata-resolve/src/stages/mod.rs @@ -154,10 +154,7 @@ pub fn resolve( // Resolve the filter expressions and graphql settings for models // This is a separate step so we can look up resolved models and their sources - let models_graphql::ModelsGraphqlOutput { - models_with_graphql, - graphql_types: _, - } = models_graphql::resolve( + let models_with_graphql = models_graphql::resolve( &metadata_accessor, &models, &data_connector_scalars, diff --git a/v3/crates/metadata-resolve/src/stages/model_permissions/types.rs b/v3/crates/metadata-resolve/src/stages/model_permissions/types.rs index df09ec45b8c..1749a2cb452 100644 --- a/v3/crates/metadata-resolve/src/stages/model_permissions/types.rs +++ b/v3/crates/metadata-resolve/src/stages/model_permissions/types.rs @@ -1,23 +1,22 @@ +use std::collections::BTreeMap; + +use serde::{Deserialize, Serialize}; + +use open_dds::{ + arguments::ArgumentName, + data_connector::{DataConnectorColumnName, DataConnectorOperatorName}, + models::ModelName, + permissions::Role, + relationships::{RelationshipName, RelationshipType}, + types::{CustomTypeName, FieldName}, +}; + use crate::stages::{data_connectors, models, models_graphql, object_types, relationships}; use crate::types::error::{Error, RelationshipError}; use crate::types::permission::ValueExpression; use crate::types::subgraph::{deserialize_qualified_btreemap, serialize_qualified_btreemap}; -use open_dds::{ - data_connector::{DataConnectorColumnName, DataConnectorOperatorName}, - models::ModelName, - relationships::{RelationshipName, RelationshipType}, - types::CustomTypeName, -}; - -use std::collections::BTreeMap; - use crate::types::subgraph::{Qualified, QualifiedTypeReference}; -use ndc_models; - -use open_dds::{arguments::ArgumentName, permissions::Role, types::FieldName}; -use serde::{Deserialize, Serialize}; - #[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] pub struct ModelWithPermissions { pub model: models::Model, 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 d0ad6168df9..817dff12b9e 100644 --- a/v3/crates/metadata-resolve/src/stages/models_graphql/mod.rs +++ b/v3/crates/metadata-resolve/src/stages/models_graphql/mod.rs @@ -1,25 +1,27 @@ mod filter; mod graphql; mod types; -use crate::types::subgraph::Qualified; + +use std::collections::{BTreeMap, BTreeSet}; + +use indexmap::IndexMap; + +use lang_graphql::ast::common as ast; +use open_dds::{data_connector::DataConnectorName, models::ModelName, types::CustomTypeName}; use crate::stages::{ boolean_expressions, data_connector_scalar_types, graphql_config, models, object_boolean_expressions, relationships, }; use crate::types::error::Error; +use crate::types::subgraph::Qualified; + +pub(crate) use types::ModelWithGraphql; pub use types::{ - ModelExpressionType, ModelGraphQlApi, ModelOrderByExpression, ModelWithGraphql, - ModelsGraphqlOutput, SelectAggregateGraphQlDefinition, SelectManyGraphQlDefinition, - SelectUniqueGraphQlDefinition, + ModelExpressionType, ModelGraphQlApi, ModelOrderByExpression, SelectAggregateGraphQlDefinition, + SelectManyGraphQlDefinition, SelectUniqueGraphQlDefinition, }; -use open_dds::{data_connector::DataConnectorName, models::ModelName, types::CustomTypeName}; - -use indexmap::IndexMap; -use lang_graphql::ast::common::{self as ast}; -use std::collections::{BTreeMap, BTreeSet}; - pub fn resolve( metadata_accessor: &open_dds::accessor::MetadataAccessor, models: &IndexMap, models::Model>, @@ -35,9 +37,11 @@ pub fn resolve( boolean_expression_types: &boolean_expressions::BooleanExpressionTypes, existing_graphql_types: &BTreeSet, graphql_config: &graphql_config::GraphqlConfig, -) -> Result { - let mut models_with_graphql = IndexMap::new(); - let mut graphql_types = existing_graphql_types.clone(); +) -> Result { + let mut models_with_graphql = types::ModelsWithGraphql::new(); + + // Used to ensure we don't resolve the same type twice. + let mut existing_graphql_types = existing_graphql_types.clone(); for (model_name, model) in models.clone() { let filter_expression_type = match &model.raw.filter_expression_type { @@ -70,18 +74,18 @@ pub fn resolve( metadata_accessor, model_graphql_definition, &model, - &mut graphql_types, + &mut existing_graphql_types, data_connector_scalars, &model.raw.description, &model.aggregate_expression, graphql_config, )?, - None => ModelGraphQlApi::default(), + None => types::ModelGraphQlApi::default(), }; models_with_graphql.insert( model_name, - ModelWithGraphql { + types::ModelWithGraphql { inner: model, graphql_api, filter_expression_type, @@ -89,8 +93,5 @@ pub fn resolve( ); } - Ok(ModelsGraphqlOutput { - models_with_graphql, - graphql_types, - }) + Ok(models_with_graphql) } diff --git a/v3/crates/metadata-resolve/src/stages/models_graphql/types.rs b/v3/crates/metadata-resolve/src/stages/models_graphql/types.rs index b269673e7dd..cd0097b7638 100644 --- a/v3/crates/metadata-resolve/src/stages/models_graphql/types.rs +++ b/v3/crates/metadata-resolve/src/stages/models_graphql/types.rs @@ -1,31 +1,28 @@ -use crate::stages::{boolean_expressions, models, object_boolean_expressions}; -use crate::types::subgraph::{Qualified, QualifiedTypeReference}; +use std::collections::BTreeMap; + use indexmap::IndexMap; +use serde::{Deserialize, Serialize}; + +use lang_graphql::ast::common::{self as ast}; use open_dds::{ + aggregates::AggregateExpressionName, data_connector::{DataConnectorColumnName, DataConnectorName}, models::ModelName, - types::FieldName, + types::{Deprecated, FieldName}, }; -use serde::{Deserialize, Serialize}; -use std::collections::{BTreeMap, BTreeSet}; use crate::helpers::types::NdcColumnForComparison; -use lang_graphql::ast::common::{self as ast}; - -use open_dds::aggregates::AggregateExpressionName; -use open_dds::types::Deprecated; +use crate::stages::{boolean_expressions, models, object_boolean_expressions}; +use crate::types::subgraph::{Qualified, QualifiedTypeReference}; /// A Model, once we have added filter expression and graphql for it -pub struct ModelWithGraphql { +pub(crate) struct ModelWithGraphql { pub inner: models::Model, pub filter_expression_type: Option, pub graphql_api: ModelGraphQlApi, } -pub struct ModelsGraphqlOutput { - pub models_with_graphql: IndexMap, ModelWithGraphql>, - pub graphql_types: BTreeSet, -} +pub(crate) type ModelsWithGraphql = IndexMap, ModelWithGraphql>; #[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] pub enum ModelExpressionType {