Skip to content

Commit

Permalink
Refactor: Optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
gianalarcon committed Oct 26, 2023
1 parent 3e85b2a commit 8de715d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
1 change: 1 addition & 0 deletions crates/torii/graphql/src/object/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ pub async fn model_data_recursive_query(
entity_id: &str,
type_mapping: &TypeMapping,
) -> sqlx::Result<ValueMapping> {
// For nested types, we need to remove prefix in path array
let namespace = format!("{}_", path_array[0]);
let table_name = &path_array.join("$").replace(&namespace, "");
let query = format!("SELECT * FROM {} WHERE entity_id = '{}'", table_name, entity_id);
Expand Down
7 changes: 2 additions & 5 deletions crates/torii/graphql/src/object/model_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,9 @@ pub fn object(type_name: &str, type_mapping: &TypeMapping, path_array: &[String]
let mut object = Object::new(type_name);

for (field_name, type_data) in type_mapping.clone() {
let mut table_name = path_array[0].clone();
// For nested types, we need to remove prefix in path array
if path_array.len() > 1 {
let namespace = format!("{}_", path_array[0]);
table_name = path_array.join("$").replace(&namespace, "");
}
let namespace = format!("{}_", path_array[0]);
let table_name = path_array.join("$").replace(&namespace, "");
let field = Field::new(field_name.to_string(), type_data.type_ref(), move |ctx| {
let field_name = field_name.clone();
let type_data = type_data.clone();
Expand Down

0 comments on commit 8de715d

Please sign in to comment.