diff --git a/crates/torii/graphql/src/object/connection/page_info.rs b/crates/torii/graphql/src/object/connection/page_info.rs index 447d088a73..6e44938a57 100644 --- a/crates/torii/graphql/src/object/connection/page_info.rs +++ b/crates/torii/graphql/src/object/connection/page_info.rs @@ -11,7 +11,7 @@ impl ObjectTrait for PageInfoObject { } fn type_name(&self) -> &str { - "PageInfo" + "World__PageInfo" } fn type_mapping(&self) -> &TypeMapping { diff --git a/crates/torii/graphql/src/object/entity.rs b/crates/torii/graphql/src/object/entity.rs index 8170ca5903..c9127f6a1f 100644 --- a/crates/torii/graphql/src/object/entity.rs +++ b/crates/torii/graphql/src/object/entity.rs @@ -49,7 +49,7 @@ impl ObjectTrait for EntityObject { } fn type_name(&self) -> &str { - "Entity" + "World__Entity" } fn type_mapping(&self) -> &TypeMapping { @@ -174,8 +174,10 @@ pub async fn model_data_recursive_query( entity_id: &str, type_mapping: &TypeMapping, ) -> sqlx::Result { - let table_name = path_array.join("$"); - let query = format!("SELECT * FROM {} WHERE entity_id = '{}'", &table_name, entity_id); + // 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); let row = sqlx::query(&query).fetch_one(conn.as_mut()).await?; let mut value_mapping = value_mapping_from_row(&row, type_mapping, true)?; diff --git a/crates/torii/graphql/src/object/event.rs b/crates/torii/graphql/src/object/event.rs index 247963e5c6..28a407d2af 100644 --- a/crates/torii/graphql/src/object/event.rs +++ b/crates/torii/graphql/src/object/event.rs @@ -17,7 +17,7 @@ impl ObjectTrait for EventObject { } fn type_name(&self) -> &str { - "Event" + "World__Event" } fn type_mapping(&self) -> &TypeMapping { diff --git a/crates/torii/graphql/src/object/metadata.rs b/crates/torii/graphql/src/object/metadata.rs index 3b3737a1b3..0c3b465e43 100644 --- a/crates/torii/graphql/src/object/metadata.rs +++ b/crates/torii/graphql/src/object/metadata.rs @@ -12,7 +12,7 @@ impl ObjectTrait for MetadataObject { } fn type_name(&self) -> &str { - "Metadata" + "World__Metadata" } fn type_mapping(&self) -> &TypeMapping { diff --git a/crates/torii/graphql/src/object/mod.rs b/crates/torii/graphql/src/object/mod.rs index bffce6ece5..8af5d582b6 100644 --- a/crates/torii/graphql/src/object/mod.rs +++ b/crates/torii/graphql/src/object/mod.rs @@ -27,7 +27,7 @@ pub trait ObjectTrait: Send + Sync { // Name of the graphql object, singular and plural (eg "player" and "players") fn name(&self) -> (&str, &str); - // Type name of the graphql object (eg "Player") + // Type name of the graphql object (eg "World__Player") fn type_name(&self) -> &str; // Type mapping defines the fields of the graphql object and their corresponding type diff --git a/crates/torii/graphql/src/object/model.rs b/crates/torii/graphql/src/object/model.rs index 3e031ca745..8f7e70e293 100644 --- a/crates/torii/graphql/src/object/model.rs +++ b/crates/torii/graphql/src/object/model.rs @@ -33,7 +33,7 @@ impl ObjectTrait for ModelObject { } fn type_name(&self) -> &str { - "Model" + "World__Model" } fn type_mapping(&self) -> &TypeMapping { diff --git a/crates/torii/graphql/src/object/model_data.rs b/crates/torii/graphql/src/object/model_data.rs index c62ece582d..a5bc548fca 100644 --- a/crates/torii/graphql/src/object/model_data.rs +++ b/crates/torii/graphql/src/object/model_data.rs @@ -157,8 +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 table_name = path_array.join("$"); - + // 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 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(); @@ -216,7 +217,7 @@ pub fn object(type_name: &str, type_mapping: &TypeMapping, path_array: &[String] } fn entity_field() -> Field { - Field::new("entity", TypeRef::named("Entity"), |ctx| { + Field::new("entity", TypeRef::named("World__Entity"), |ctx| { FieldFuture::new(async move { match ctx.parent_value.try_to_value()? { Value::Object(indexmap) => { diff --git a/crates/torii/graphql/src/query/mod.rs b/crates/torii/graphql/src/query/mod.rs index 88ddb1f077..d2180bbdc9 100644 --- a/crates/torii/graphql/src/query/mod.rs +++ b/crates/torii/graphql/src/query/mod.rs @@ -23,7 +23,6 @@ pub async fn type_mapping_query( model_id: &str, ) -> sqlx::Result { let model_members = fetch_model_members(conn, model_id).await?; - let (root_members, nested_members): (Vec<&ModelMember>, Vec<&ModelMember>) = model_members.iter().partition(|member| member.model_idx == 0); @@ -93,8 +92,8 @@ fn parse_nested_type( } }) .collect(); - - TypeData::Nested((TypeRef::named(target_type), nested_mapping)) + let namespaced = format!("{}_{}", target_id, target_type); + TypeData::Nested((TypeRef::named(namespaced), nested_mapping)) } fn remove_hex_leading_zeros(value: Value) -> Value { diff --git a/crates/torii/graphql/src/tests/subscription_test.rs b/crates/torii/graphql/src/tests/subscription_test.rs index 74cc28a64b..12c5445cd9 100644 --- a/crates/torii/graphql/src/tests/subscription_test.rs +++ b/crates/torii/graphql/src/tests/subscription_test.rs @@ -13,7 +13,6 @@ mod tests { use crate::tests::{model_fixtures, run_graphql_subscription}; - //#[ignore] #[sqlx::test(migrations = "../migrations")] async fn test_entity_subscription(pool: SqlitePool) { // Sleep in order to run this test in a single thread @@ -93,7 +92,6 @@ mod tests { rx.recv().await.unwrap(); } - //#[ignore] #[sqlx::test(migrations = "../migrations")] async fn test_entity_subscription_with_id(pool: SqlitePool) { // Sleep in order to run this test in a single thread @@ -168,7 +166,6 @@ mod tests { rx.recv().await.unwrap(); } - //#[ignore] #[sqlx::test(migrations = "../migrations")] async fn test_model_subscription(pool: SqlitePool) { let mut db = Sql::new(pool.clone(), FieldElement::ZERO).await.unwrap(); @@ -217,7 +214,6 @@ mod tests { rx.recv().await.unwrap(); } - //#[ignore] #[sqlx::test(migrations = "../migrations")] async fn test_model_subscription_with_id(pool: SqlitePool) { // Sleep in order to run this test at the end in a single thread