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