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
This commit is contained in:
Samir Talwar 2024-06-27 11:12:20 +02:00 committed by hasura-bot
parent 5b2e36cd4f
commit 00db411c6e
4 changed files with 46 additions and 52 deletions

View File

@ -154,10 +154,7 @@ pub fn resolve(
// Resolve the filter expressions and graphql settings for models // Resolve the filter expressions and graphql settings for models
// This is a separate step so we can look up resolved models and their sources // This is a separate step so we can look up resolved models and their sources
let models_graphql::ModelsGraphqlOutput { let models_with_graphql = models_graphql::resolve(
models_with_graphql,
graphql_types: _,
} = models_graphql::resolve(
&metadata_accessor, &metadata_accessor,
&models, &models,
&data_connector_scalars, &data_connector_scalars,

View File

@ -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::stages::{data_connectors, models, models_graphql, object_types, relationships};
use crate::types::error::{Error, RelationshipError}; use crate::types::error::{Error, RelationshipError};
use crate::types::permission::ValueExpression; use crate::types::permission::ValueExpression;
use crate::types::subgraph::{deserialize_qualified_btreemap, serialize_qualified_btreemap}; 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 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)] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
pub struct ModelWithPermissions { pub struct ModelWithPermissions {
pub model: models::Model, pub model: models::Model,

View File

@ -1,25 +1,27 @@
mod filter; mod filter;
mod graphql; mod graphql;
mod types; 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::{ use crate::stages::{
boolean_expressions, data_connector_scalar_types, graphql_config, models, boolean_expressions, data_connector_scalar_types, graphql_config, models,
object_boolean_expressions, relationships, object_boolean_expressions, relationships,
}; };
use crate::types::error::Error; use crate::types::error::Error;
use crate::types::subgraph::Qualified;
pub(crate) use types::ModelWithGraphql;
pub use types::{ pub use types::{
ModelExpressionType, ModelGraphQlApi, ModelOrderByExpression, ModelWithGraphql, ModelExpressionType, ModelGraphQlApi, ModelOrderByExpression, SelectAggregateGraphQlDefinition,
ModelsGraphqlOutput, SelectAggregateGraphQlDefinition, SelectManyGraphQlDefinition, SelectManyGraphQlDefinition, SelectUniqueGraphQlDefinition,
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( pub fn resolve(
metadata_accessor: &open_dds::accessor::MetadataAccessor, metadata_accessor: &open_dds::accessor::MetadataAccessor,
models: &IndexMap<Qualified<ModelName>, models::Model>, models: &IndexMap<Qualified<ModelName>, models::Model>,
@ -35,9 +37,11 @@ pub fn resolve(
boolean_expression_types: &boolean_expressions::BooleanExpressionTypes, boolean_expression_types: &boolean_expressions::BooleanExpressionTypes,
existing_graphql_types: &BTreeSet<ast::TypeName>, existing_graphql_types: &BTreeSet<ast::TypeName>,
graphql_config: &graphql_config::GraphqlConfig, graphql_config: &graphql_config::GraphqlConfig,
) -> Result<ModelsGraphqlOutput, Error> { ) -> Result<types::ModelsWithGraphql, Error> {
let mut models_with_graphql = IndexMap::new(); let mut models_with_graphql = types::ModelsWithGraphql::new();
let mut graphql_types = existing_graphql_types.clone();
// 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() { for (model_name, model) in models.clone() {
let filter_expression_type = match &model.raw.filter_expression_type { let filter_expression_type = match &model.raw.filter_expression_type {
@ -70,18 +74,18 @@ pub fn resolve(
metadata_accessor, metadata_accessor,
model_graphql_definition, model_graphql_definition,
&model, &model,
&mut graphql_types, &mut existing_graphql_types,
data_connector_scalars, data_connector_scalars,
&model.raw.description, &model.raw.description,
&model.aggregate_expression, &model.aggregate_expression,
graphql_config, graphql_config,
)?, )?,
None => ModelGraphQlApi::default(), None => types::ModelGraphQlApi::default(),
}; };
models_with_graphql.insert( models_with_graphql.insert(
model_name, model_name,
ModelWithGraphql { types::ModelWithGraphql {
inner: model, inner: model,
graphql_api, graphql_api,
filter_expression_type, filter_expression_type,
@ -89,8 +93,5 @@ pub fn resolve(
); );
} }
Ok(ModelsGraphqlOutput { Ok(models_with_graphql)
models_with_graphql,
graphql_types,
})
} }

View File

@ -1,31 +1,28 @@
use crate::stages::{boolean_expressions, models, object_boolean_expressions}; use std::collections::BTreeMap;
use crate::types::subgraph::{Qualified, QualifiedTypeReference};
use indexmap::IndexMap; use indexmap::IndexMap;
use serde::{Deserialize, Serialize};
use lang_graphql::ast::common::{self as ast};
use open_dds::{ use open_dds::{
aggregates::AggregateExpressionName,
data_connector::{DataConnectorColumnName, DataConnectorName}, data_connector::{DataConnectorColumnName, DataConnectorName},
models::ModelName, models::ModelName,
types::FieldName, types::{Deprecated, FieldName},
}; };
use serde::{Deserialize, Serialize};
use std::collections::{BTreeMap, BTreeSet};
use crate::helpers::types::NdcColumnForComparison; use crate::helpers::types::NdcColumnForComparison;
use lang_graphql::ast::common::{self as ast}; use crate::stages::{boolean_expressions, models, object_boolean_expressions};
use crate::types::subgraph::{Qualified, QualifiedTypeReference};
use open_dds::aggregates::AggregateExpressionName;
use open_dds::types::Deprecated;
/// A Model, once we have added filter expression and graphql for it /// A Model, once we have added filter expression and graphql for it
pub struct ModelWithGraphql { pub(crate) struct ModelWithGraphql {
pub inner: models::Model, pub inner: models::Model,
pub filter_expression_type: Option<ModelExpressionType>, pub filter_expression_type: Option<ModelExpressionType>,
pub graphql_api: ModelGraphQlApi, pub graphql_api: ModelGraphQlApi,
} }
pub struct ModelsGraphqlOutput { pub(crate) type ModelsWithGraphql = IndexMap<Qualified<ModelName>, ModelWithGraphql>;
pub models_with_graphql: IndexMap<Qualified<ModelName>, ModelWithGraphql>,
pub graphql_types: BTreeSet<ast::TypeName>,
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
pub enum ModelExpressionType { pub enum ModelExpressionType {