mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-14 08:02:15 +03:00
Be more explicit about clones, and remove a few. (#671)
Calling `.to_owned()` on a reference, `.to_vec()` on a vector reference, etc. are just synonyms for `.clone()` which are less explicit about cloning. Let's be explicit. This also removes some unnecessary clones. V3_GIT_ORIGIN_REV_ID: 1bc00c4106f0346303d73e4268c89030c0ce93fc
This commit is contained in:
parent
9b7a2c0b88
commit
ca830c05fb
@ -31,9 +31,7 @@ must_use_candidate = "allow"
|
||||
struct_field_names = "allow"
|
||||
wildcard_imports = "allow"
|
||||
# disable these for now, but we should probably fix them
|
||||
implicit_clone = "allow"
|
||||
implicit_hasher = "allow"
|
||||
inefficient_to_string = "allow"
|
||||
result_large_err = "allow"
|
||||
return_self_not_must_use = "allow"
|
||||
semicolon_if_nothing_returned = "allow"
|
||||
|
@ -446,7 +446,7 @@ fn assign_join_ids<'s, 'ir>(
|
||||
}
|
||||
};
|
||||
let new_location = Location {
|
||||
join_node: new_node.to_owned(),
|
||||
join_node: new_node.clone(),
|
||||
rest: assign_join_ids(&location.rest, state),
|
||||
};
|
||||
(key.to_string(), new_location)
|
||||
|
@ -305,7 +305,7 @@ fn resolve_command_response_row(
|
||||
// the array and use that as the value for the relationship otherwise
|
||||
// we return the array of objects.
|
||||
let array_values: Vec<IndexMap<String, ndc_models::RowFieldValue>> =
|
||||
json::from_value(json::Value::Array(values.to_vec()))?;
|
||||
json::from_value(json::Value::Array(values.clone()))?;
|
||||
|
||||
if type_container.is_list(){
|
||||
Ok(array_values)
|
||||
|
@ -35,7 +35,7 @@ pub(crate) fn resolve_object_boolean_expression_type(
|
||||
) -> Result<ResolvedObjectBooleanExpressionType, Error> {
|
||||
let qualified_object_type_name = Qualified::new(
|
||||
subgraph.to_string(),
|
||||
object_boolean_expression_operand.r#type.to_owned(),
|
||||
object_boolean_expression_operand.r#type.clone(),
|
||||
);
|
||||
|
||||
let object_type_representation =
|
||||
|
@ -29,9 +29,7 @@ pub(crate) fn resolve_scalar_boolean_expression_type(
|
||||
// scope the data connector to the current subgraph
|
||||
let qualified_data_connector_name = Qualified::new(
|
||||
subgraph.to_string(),
|
||||
data_connector_operator_mapping
|
||||
.data_connector_name
|
||||
.to_owned(),
|
||||
data_connector_operator_mapping.data_connector_name.clone(),
|
||||
);
|
||||
|
||||
// lookup the data connector we are referring to
|
||||
|
@ -44,7 +44,7 @@ pub fn resolve<'a>(
|
||||
|
||||
let qualified_data_connector_name = Qualified::new(
|
||||
subgraph.to_string(),
|
||||
scalar_type_representation.data_connector_name.to_owned(),
|
||||
scalar_type_representation.data_connector_name.clone(),
|
||||
);
|
||||
|
||||
let scalars = data_connector_scalars
|
||||
|
@ -231,7 +231,7 @@ fn resolve_model(
|
||||
>,
|
||||
) -> Result<Model, Error> {
|
||||
let qualified_object_type_name =
|
||||
Qualified::new(subgraph.to_string(), model.object_type.to_owned());
|
||||
Qualified::new(subgraph.to_string(), model.object_type.clone());
|
||||
let qualified_model_name = Qualified::new(subgraph.to_string(), model.name.clone());
|
||||
let object_type_representation = get_model_object_type_representation(
|
||||
object_types,
|
||||
|
@ -80,14 +80,12 @@ pub(crate) fn resolve_object_boolean_expression_type(
|
||||
graphql_config: &graphql_config::GraphqlConfig,
|
||||
) -> Result<ObjectBooleanExpressionType, Error> {
|
||||
// name of the boolean expression
|
||||
let qualified_name = Qualified::new(
|
||||
subgraph.to_string(),
|
||||
object_boolean_expression.name.to_owned(),
|
||||
);
|
||||
let qualified_name =
|
||||
Qualified::new(subgraph.to_string(), object_boolean_expression.name.clone());
|
||||
// name of the object type backing the boolean expression
|
||||
let qualified_object_type_name = Qualified::new(
|
||||
subgraph.to_string(),
|
||||
object_boolean_expression.object_type.to_owned(),
|
||||
object_boolean_expression.object_type.clone(),
|
||||
);
|
||||
let object_type_representation =
|
||||
object_types
|
||||
@ -102,7 +100,7 @@ pub(crate) fn resolve_object_boolean_expression_type(
|
||||
|
||||
let qualified_data_connector_name = Qualified::new(
|
||||
subgraph.to_string(),
|
||||
object_boolean_expression.data_connector_name.to_owned(),
|
||||
object_boolean_expression.data_connector_name.clone(),
|
||||
);
|
||||
|
||||
// validate data connector name
|
||||
|
@ -1,30 +1,28 @@
|
||||
mod types;
|
||||
pub use types::{
|
||||
ObjectTypeWithRelationships, Relationship, RelationshipCapabilities,
|
||||
RelationshipCommandMapping, RelationshipExecutionCategory, RelationshipModelMapping,
|
||||
RelationshipTarget, RelationshipTargetName,
|
||||
};
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use std::collections::BTreeSet;
|
||||
|
||||
use indexmap::IndexMap;
|
||||
|
||||
use open_dds::relationships::{self, FieldAccess, RelationshipName, RelationshipV1};
|
||||
use open_dds::{
|
||||
commands::CommandName, data_connector::DataConnectorName, models::ModelName,
|
||||
types::CustomTypeName,
|
||||
};
|
||||
|
||||
use crate::types::error::{Error, RelationshipError};
|
||||
use crate::types::subgraph::Qualified;
|
||||
|
||||
use crate::helpers::types::mk_name;
|
||||
use crate::stages::{
|
||||
commands, data_connector_scalar_types, data_connectors, models, object_types, type_permissions,
|
||||
};
|
||||
use crate::types::error::{Error, RelationshipError};
|
||||
use crate::types::subgraph::Qualified;
|
||||
|
||||
use open_dds::relationships::{self, FieldAccess, RelationshipName, RelationshipV1};
|
||||
|
||||
use std::collections::BTreeSet;
|
||||
pub use types::{
|
||||
ObjectTypeWithRelationships, Relationship, RelationshipCapabilities,
|
||||
RelationshipCommandMapping, RelationshipExecutionCategory, RelationshipModelMapping,
|
||||
RelationshipTarget, RelationshipTargetName,
|
||||
};
|
||||
|
||||
/// resolve relationships
|
||||
/// returns updated `types` value
|
||||
@ -70,7 +68,7 @@ pub fn resolve(
|
||||
} in &metadata_accessor.relationships
|
||||
{
|
||||
let qualified_relationship_source_type_name =
|
||||
Qualified::new(subgraph.to_string(), relationship.source_type.to_owned());
|
||||
Qualified::new(subgraph.to_string(), relationship.source_type.clone());
|
||||
let object_representation = object_types_with_relationships
|
||||
.get_mut(&qualified_relationship_source_type_name)
|
||||
.ok_or_else(|| Error::RelationshipDefinedOnUnknownType {
|
||||
@ -352,11 +350,11 @@ fn resolve_relationship_mappings_command(
|
||||
fn get_relationship_capabilities(
|
||||
type_name: &Qualified<CustomTypeName>,
|
||||
relationship_name: &RelationshipName,
|
||||
source_data_connector: &Option<data_connectors::DataConnectorLink>,
|
||||
source_data_connector: Option<&data_connectors::DataConnectorLink>,
|
||||
target_name: &RelationshipTargetName,
|
||||
data_connectors: &data_connectors::DataConnectors,
|
||||
) -> Result<Option<RelationshipCapabilities>, Error> {
|
||||
let Some(data_connector) = &source_data_connector else {
|
||||
let Some(data_connector) = source_data_connector else {
|
||||
return Ok(None);
|
||||
};
|
||||
|
||||
@ -413,12 +411,8 @@ pub fn resolve_relationship(
|
||||
let (relationship_target, source_data_connector, target_name) = match &relationship.target {
|
||||
relationships::RelationshipTarget::Model(target_model) => {
|
||||
let qualified_target_model_name = Qualified::new(
|
||||
target_model
|
||||
.subgraph()
|
||||
.to_owned()
|
||||
.unwrap_or(subgraph)
|
||||
.to_string(),
|
||||
target_model.name.to_owned(),
|
||||
target_model.subgraph().unwrap_or(subgraph).to_string(),
|
||||
target_model.name.clone(),
|
||||
);
|
||||
let resolved_target_model =
|
||||
models.get(&qualified_target_model_name).ok_or_else(|| {
|
||||
@ -431,7 +425,7 @@ pub fn resolve_relationship(
|
||||
let source_data_connector = resolved_target_model
|
||||
.source
|
||||
.as_ref()
|
||||
.map(|source| source.data_connector.clone());
|
||||
.map(|source| &source.data_connector);
|
||||
(
|
||||
RelationshipTarget::Model {
|
||||
model_name: qualified_target_model_name,
|
||||
@ -456,7 +450,7 @@ pub fn resolve_relationship(
|
||||
.as_deref()
|
||||
.unwrap_or(subgraph)
|
||||
.to_string(),
|
||||
target_command.name.to_owned(),
|
||||
target_command.name.clone(),
|
||||
);
|
||||
let resolved_target_command =
|
||||
commands
|
||||
@ -470,7 +464,7 @@ pub fn resolve_relationship(
|
||||
let source_data_connector = resolved_target_command
|
||||
.source
|
||||
.as_ref()
|
||||
.map(|source| source.data_connector.clone());
|
||||
.map(|source| &source.data_connector);
|
||||
(
|
||||
RelationshipTarget::Command {
|
||||
command_name: qualified_target_command_name,
|
||||
@ -491,7 +485,7 @@ pub fn resolve_relationship(
|
||||
let target_capabilities = get_relationship_capabilities(
|
||||
&source_type_name,
|
||||
&relationship.name,
|
||||
&source_data_connector,
|
||||
source_data_connector,
|
||||
&target_name,
|
||||
data_connectors,
|
||||
)?;
|
||||
|
@ -58,7 +58,7 @@ pub fn resolve(
|
||||
{
|
||||
let qualified_type_name = Qualified::new(
|
||||
subgraph.to_string(),
|
||||
output_type_permission.type_name.to_owned(),
|
||||
output_type_permission.type_name.clone(),
|
||||
);
|
||||
match object_types_with_permissions.get_mut(&qualified_type_name) {
|
||||
None => {
|
||||
|
@ -100,7 +100,7 @@ where
|
||||
let map: BTreeMap<String, V> = Deserialize::deserialize(deserializer)?;
|
||||
let mut result = BTreeMap::new();
|
||||
for (key, value) in map {
|
||||
let qualified = serde_json::from_str(&key.to_owned()).map_err(serde::de::Error::custom)?;
|
||||
let qualified = serde_json::from_str(&key).map_err(serde::de::Error::custom)?;
|
||||
result.insert(qualified, value);
|
||||
}
|
||||
Ok(result)
|
||||
@ -135,7 +135,7 @@ where
|
||||
let map: BTreeMap<String, V> = Deserialize::deserialize(deserializer)?;
|
||||
let mut result = BTreeMap::new();
|
||||
for (key, value) in map {
|
||||
let qualified = serde_json::from_str(&key.to_owned()).map_err(serde::de::Error::custom)?;
|
||||
let qualified = serde_json::from_str(&key).map_err(serde::de::Error::custom)?;
|
||||
result.insert(qualified, value);
|
||||
}
|
||||
Ok(result)
|
||||
|
@ -454,7 +454,7 @@ pub fn output_type_schema(
|
||||
global_id_fields: object_type_representation
|
||||
.object_type
|
||||
.global_id_fields
|
||||
.to_vec(),
|
||||
.clone(),
|
||||
}),
|
||||
get_output_type(gds, builder, &ID_TYPE_REFERENCE)?,
|
||||
BTreeMap::new(),
|
||||
|
Loading…
Reference in New Issue
Block a user