From e7df4f17f5f81fa27884b4419a3bcb40de046541 Mon Sep 17 00:00:00 2001 From: gianalarcon Date: Mon, 27 Nov 2023 16:54:31 -0500 Subject: [PATCH 01/14] Implement camelCase convetion --- crates/torii/graphql/src/mapping.rs | 46 +++++++++--------- .../graphql/src/tests/subscription_test.rs | 48 +++++++++---------- 2 files changed, 47 insertions(+), 47 deletions(-) diff --git a/crates/torii/graphql/src/mapping.rs b/crates/torii/graphql/src/mapping.rs index b378146787..9d1426d733 100644 --- a/crates/torii/graphql/src/mapping.rs +++ b/crates/torii/graphql/src/mapping.rs @@ -11,14 +11,14 @@ lazy_static! { pub static ref ENTITY_TYPE_MAPPING: TypeMapping = IndexMap::from([ (Name::new("id"), TypeData::Simple(TypeRef::named(TypeRef::ID))), (Name::new("keys"), TypeData::Simple(TypeRef::named_list(TypeRef::STRING))), - (Name::new("model_names"), TypeData::Simple(TypeRef::named(TypeRef::STRING))), - (Name::new("event_id"), TypeData::Simple(TypeRef::named(TypeRef::STRING))), + (Name::new("modelNames"), TypeData::Simple(TypeRef::named(TypeRef::STRING))), + (Name::new("eventId"), TypeData::Simple(TypeRef::named(TypeRef::STRING))), ( - Name::new("created_at"), + Name::new("createdAt"), TypeData::Simple(TypeRef::named(GraphqlType::DateTime.to_string())), ), ( - Name::new("updated_at"), + Name::new("updatedAt"), TypeData::Simple(TypeRef::named(GraphqlType::DateTime.to_string())), ), ]); @@ -27,35 +27,35 @@ lazy_static! { (Name::new("keys"), TypeData::Simple(TypeRef::named_list(TypeRef::STRING))), (Name::new("data"), TypeData::Simple(TypeRef::named_list(TypeRef::STRING))), ( - Name::new("created_at"), + Name::new("createdAt"), TypeData::Simple(TypeRef::named(GraphqlType::DateTime.to_string())), ), - (Name::new("transaction_hash"), TypeData::Simple(TypeRef::named(TypeRef::STRING))), + (Name::new("transactionHash"), TypeData::Simple(TypeRef::named(TypeRef::STRING))), ]); pub static ref MODEL_TYPE_MAPPING: TypeMapping = IndexMap::from([ (Name::new("id"), TypeData::Simple(TypeRef::named(TypeRef::ID))), (Name::new("name"), TypeData::Simple(TypeRef::named(TypeRef::STRING))), ( - Name::new("class_hash"), + Name::new("classHash"), TypeData::Simple(TypeRef::named(Primitive::Felt252(None).to_string())), ), ( - Name::new("transaction_hash"), + Name::new("transactionHash"), TypeData::Simple(TypeRef::named(Primitive::Felt252(None).to_string())), ), ( - Name::new("created_at"), + Name::new("createdAt"), TypeData::Simple(TypeRef::named(GraphqlType::DateTime.to_string())), ), ]); pub static ref TRANSACTION_MAPPING: TypeMapping = IndexMap::from([ (Name::new("id"), TypeData::Simple(TypeRef::named(TypeRef::ID))), ( - Name::new("transaction_hash"), + Name::new("transactionHash"), TypeData::Simple(TypeRef::named(Primitive::Felt252(None).to_string())) ), ( - Name::new("sender_address"), + Name::new("senderAddress"), TypeData::Simple(TypeRef::named(Primitive::Felt252(None).to_string())) ), ( @@ -63,7 +63,7 @@ lazy_static! { TypeData::Simple(TypeRef::named_list(Primitive::Felt252(None).to_string())) ), ( - Name::new("max_fee"), + Name::new("maxFee"), TypeData::Simple(TypeRef::named(Primitive::Felt252(None).to_string())) ), ( @@ -75,19 +75,19 @@ lazy_static! { TypeData::Simple(TypeRef::named(Primitive::Felt252(None).to_string())) ), ( - Name::new("created_at"), + Name::new("createdAt"), TypeData::Simple(TypeRef::named(GraphqlType::DateTime.to_string())), ), ]); pub static ref PAGE_INFO_TYPE_MAPPING: TypeMapping = TypeMapping::from([ - (Name::new("has_previous_page"), TypeData::Simple(TypeRef::named(TypeRef::BOOLEAN))), - (Name::new("has_next_page"), TypeData::Simple(TypeRef::named(TypeRef::BOOLEAN))), + (Name::new("hasPreviousPage"), TypeData::Simple(TypeRef::named(TypeRef::BOOLEAN))), + (Name::new("hasNextPage"), TypeData::Simple(TypeRef::named(TypeRef::BOOLEAN))), ( - Name::new("start_cursor"), + Name::new("startCursor"), TypeData::Simple(TypeRef::named(GraphqlType::Cursor.to_string())), ), ( - Name::new("end_cursor"), + Name::new("endCursor"), TypeData::Simple(TypeRef::named(GraphqlType::Cursor.to_string())), ), ]); @@ -99,8 +99,8 @@ lazy_static! { (Name::new("name"), TypeData::Simple(TypeRef::named(TypeRef::STRING))), (Name::new("description"), TypeData::Simple(TypeRef::named(TypeRef::STRING))), (Name::new("website"), TypeData::Simple(TypeRef::named(TypeRef::STRING))), - (Name::new("icon_uri"), TypeData::Simple(TypeRef::named(TypeRef::STRING))), - (Name::new("cover_uri"), TypeData::Simple(TypeRef::named(TypeRef::STRING))), + (Name::new("iconUri"), TypeData::Simple(TypeRef::named(TypeRef::STRING))), + (Name::new("coverUri"), TypeData::Simple(TypeRef::named(TypeRef::STRING))), (Name::new("socials"), TypeData::Simple(TypeRef::named_list(SOCIAL_TYPE_NAME))) ]); pub static ref METADATA_TYPE_MAPPING: TypeMapping = IndexMap::from([ @@ -110,14 +110,14 @@ lazy_static! { Name::new("content"), TypeData::Nested((TypeRef::named(CONTENT_TYPE_NAME), IndexMap::new())) ), - (Name::new("icon_img"), TypeData::Simple(TypeRef::named(TypeRef::STRING))), - (Name::new("cover_img"), TypeData::Simple(TypeRef::named(TypeRef::STRING))), + (Name::new("iconImg"), TypeData::Simple(TypeRef::named(TypeRef::STRING))), + (Name::new("coverImg"), TypeData::Simple(TypeRef::named(TypeRef::STRING))), ( - Name::new("created_at"), + Name::new("createdAt"), TypeData::Simple(TypeRef::named(GraphqlType::DateTime.to_string())) ), ( - Name::new("updated_at"), + Name::new("updatedAt"), TypeData::Simple(TypeRef::named(GraphqlType::DateTime.to_string())) ), ]); diff --git a/crates/torii/graphql/src/tests/subscription_test.rs b/crates/torii/graphql/src/tests/subscription_test.rs index 4c48dc93ba..3f243ac929 100644 --- a/crates/torii/graphql/src/tests/subscription_test.rs +++ b/crates/torii/graphql/src/tests/subscription_test.rs @@ -30,16 +30,16 @@ mod tests { "entityUpdated": { "id": entity_id, "keys":vec![keys_str], - "model_names": model_name, + "modelNames": model_name, "models" : [{ "__typename": model_name, "depth": "Zero", - "record_id": 0, - "type_u16": 1, - "type_u64": 1, - "type_bool": true, - "type_felt": format!("{:#x}", FieldElement::from(1u128)), - "type_contract_address": format!("{:#x}", FieldElement::ONE) + "recordId": 0, + "typeU16": 1, + "typeU64": 1, + "typeBool": true, + "typeFelt": format!("{:#x}", FieldElement::from(1u128)), + "typeContractAddress": format!("{:#x}", FieldElement::ONE) }] } }); @@ -115,17 +115,17 @@ mod tests { entityUpdated { id keys - model_names + modelNames models { __typename ... on Record { depth - record_id - type_u16 - type_u64 - type_bool - type_felt - type_contract_address + recordId + typeU16 + typeU64 + typeBool + typeFelt + typeContractAddress } } } @@ -153,13 +153,13 @@ mod tests { "entityUpdated": { "id": entity_id, "keys":vec![keys_str], - "model_names": model_name, + "modelNames": model_name, "models" : [{ "__typename": model_name, "depth": "Zero", - "record_id": 0, - "type_felt": format!("{:#x}", FieldElement::from(1u128)), - "type_contract_address": format!("{:#x}", FieldElement::ONE) + "recordId": 0, + "typeFelt": format!("{:#x}", FieldElement::from(1u128)), + "typeContractAddress": format!("{:#x}", FieldElement::ONE) }] } }); @@ -220,14 +220,14 @@ mod tests { entityUpdated(id: "0x579e8877c7755365d5ec1ec7d3a94a457eff5d1f40482bbe9729c064cdead2") { id keys - model_names + modelNames models { __typename ... on Record { depth - record_id - type_felt - type_contract_address + recordId + typeFelt + typeContractAddress } } } @@ -373,7 +373,7 @@ mod tests { eventEmitted (keys: ["*", "{:#x}"]) {{ keys data - transaction_hash + transactionHash }} }} "#, @@ -389,7 +389,7 @@ mod tests { ], "data": vec![ format!("{:#x}", FieldElement::from_str("0xc0de").unwrap()), format!("{:#x}", FieldElement::from_str("0xface").unwrap()) - ], "transaction_hash": format!("{:#x}", FieldElement::ZERO)} + ], "transactionHash": format!("{:#x}", FieldElement::ZERO)} }); assert_eq!(response_value, expected_value); From 8558ea4dab33e91d2c216c2a2d30e746bdd96def Mon Sep 17 00:00:00 2001 From: gianalarcon Date: Mon, 27 Nov 2023 21:33:27 -0500 Subject: [PATCH 02/14] update susbcriptions and events --- crates/torii/graphql/src/mapping.rs | 4 ++-- .../graphql/src/object/connection/mod.rs | 8 +++---- crates/torii/graphql/src/object/entity.rs | 10 ++++----- crates/torii/graphql/src/object/event.rs | 4 ++-- crates/torii/graphql/src/object/mod.rs | 1 + crates/torii/graphql/src/object/model.rs | 6 ++--- .../torii/graphql/src/tests/entities_test.rs | 2 +- crates/torii/graphql/src/tests/mod.rs | 21 +++++++++--------- .../graphql/src/tests/subscription_test.rs | 22 +++++++++---------- 9 files changed, 40 insertions(+), 38 deletions(-) diff --git a/crates/torii/graphql/src/mapping.rs b/crates/torii/graphql/src/mapping.rs index 9d1426d733..826390c122 100644 --- a/crates/torii/graphql/src/mapping.rs +++ b/crates/torii/graphql/src/mapping.rs @@ -110,8 +110,8 @@ lazy_static! { Name::new("content"), TypeData::Nested((TypeRef::named(CONTENT_TYPE_NAME), IndexMap::new())) ), - (Name::new("iconImg"), TypeData::Simple(TypeRef::named(TypeRef::STRING))), - (Name::new("coverImg"), TypeData::Simple(TypeRef::named(TypeRef::STRING))), + (Name::new("icon_img"), TypeData::Simple(TypeRef::named(TypeRef::STRING))), + (Name::new("cover_img"), TypeData::Simple(TypeRef::named(TypeRef::STRING))), ( Name::new("createdAt"), TypeData::Simple(TypeRef::named(GraphqlType::DateTime.to_string())) diff --git a/crates/torii/graphql/src/object/connection/mod.rs b/crates/torii/graphql/src/object/connection/mod.rs index 63b796e31b..7785188785 100644 --- a/crates/torii/graphql/src/object/connection/mod.rs +++ b/crates/torii/graphql/src/object/connection/mod.rs @@ -40,9 +40,9 @@ impl ConnectionObject { Name::new("edges"), TypeData::Simple(TypeRef::named_list(format!("{}Edge", type_name))), ), - (Name::new("total_count"), TypeData::Simple(TypeRef::named_nn(TypeRef::INT))), + (Name::new("totalCount"), TypeData::Simple(TypeRef::named_nn(TypeRef::INT))), ( - Name::new("page_info"), + Name::new("pageInfo"), TypeData::Nested((TypeRef::named_nn(PAGE_INFO_TYPE_NAME), IndexMap::new())), ), ]); @@ -141,8 +141,8 @@ pub fn connection_output( .collect::>>(); Ok(ValueMapping::from([ - (Name::new("total_count"), Value::from(total_count)), + (Name::new("totalCount"), Value::from(total_count)), (Name::new("edges"), Value::List(model_edges?)), - (Name::new("page_info"), PageInfoObject::value(page_info)), + (Name::new("pageInfo"), PageInfoObject::value(page_info)), ])) } diff --git a/crates/torii/graphql/src/object/entity.rs b/crates/torii/graphql/src/object/entity.rs index 4d9751573e..5f061f7e5b 100644 --- a/crates/torii/graphql/src/object/entity.rs +++ b/crates/torii/graphql/src/object/entity.rs @@ -115,14 +115,14 @@ impl EntityObject { IndexMap::from([ (Name::new("id"), Value::from(entity.id)), (Name::new("keys"), Value::from(keys)), - (Name::new("model_names"), Value::from(entity.model_names)), - (Name::new("event_id"), Value::from(entity.event_id)), + (Name::new("modelNames"), Value::from(entity.model_names)), + (Name::new("eventId"), Value::from(entity.event_id)), ( - Name::new("created_at"), + Name::new("createdAt"), Value::from(entity.created_at.format("%Y-%m-%d %H:%M:%S").to_string()), ), ( - Name::new("updated_at"), + Name::new("updatedAt"), Value::from(entity.updated_at.format("%Y-%m-%d %H:%M:%S").to_string()), ), ]) @@ -135,7 +135,7 @@ fn model_union_field() -> Field { match ctx.parent_value.try_to_value()? { Value::Object(indexmap) => { let mut conn = ctx.data::>()?.acquire().await?; - let model_names: Vec = extract::(indexmap, "model_names")? + let model_names: Vec = extract::(indexmap, "modelNames")? .split(',') .map(|s| s.to_string()) .collect(); diff --git a/crates/torii/graphql/src/object/event.rs b/crates/torii/graphql/src/object/event.rs index 31b660c2b9..7a7e28377f 100644 --- a/crates/torii/graphql/src/object/event.rs +++ b/crates/torii/graphql/src/object/event.rs @@ -102,9 +102,9 @@ impl EventObject { (Name::new("id"), Value::from(event.id)), (Name::new("keys"), Value::from(keys)), (Name::new("data"), Value::from(data)), - (Name::new("transaction_hash"), Value::from(event.transaction_hash)), + (Name::new("transactionHash"), Value::from(event.transaction_hash)), ( - Name::new("created_at"), + Name::new("createdAt"), Value::from(event.created_at.format("%Y-%m-%d %H:%M:%S").to_string()), ), ]) diff --git a/crates/torii/graphql/src/object/mod.rs b/crates/torii/graphql/src/object/mod.rs index 494449654f..0f57cd6bb2 100644 --- a/crates/torii/graphql/src/object/mod.rs +++ b/crates/torii/graphql/src/object/mod.rs @@ -149,6 +149,7 @@ pub trait ObjectTrait: Send + Sync { for (field_name, type_data) in self.type_mapping().clone() { let field = Field::new(field_name.to_string(), type_data.type_ref(), move |ctx| { let field_name = field_name.clone(); + println!("field_name: {}", field_name); FieldFuture::new(async move { match ctx.parent_value.try_to_value()? { diff --git a/crates/torii/graphql/src/object/model.rs b/crates/torii/graphql/src/object/model.rs index a23e8b18a6..402bfe7935 100644 --- a/crates/torii/graphql/src/object/model.rs +++ b/crates/torii/graphql/src/object/model.rs @@ -60,10 +60,10 @@ impl ModelObject { IndexMap::from([ (Name::new("id"), Value::from(model.id)), (Name::new("name"), Value::from(model.name)), - (Name::new("class_hash"), Value::from(model.class_hash)), - (Name::new("transaction_hash"), Value::from(model.transaction_hash)), + (Name::new("classHash"), Value::from(model.class_hash)), + (Name::new("transactionHash"), Value::from(model.transaction_hash)), ( - Name::new("created_at"), + Name::new("createdAt"), Value::from(model.created_at.format("%Y-%m-%d %H:%M:%S").to_string()), ), ]) diff --git a/crates/torii/graphql/src/tests/entities_test.rs b/crates/torii/graphql/src/tests/entities_test.rs index ac42333c8d..08d929be23 100644 --- a/crates/torii/graphql/src/tests/entities_test.rs +++ b/crates/torii/graphql/src/tests/entities_test.rs @@ -16,7 +16,7 @@ mod tests { r#" {{ entities {} {{ - total_count + totalCount edges {{ cursor node {{ diff --git a/crates/torii/graphql/src/tests/mod.rs b/crates/torii/graphql/src/tests/mod.rs index 72c32b7902..5227817073 100644 --- a/crates/torii/graphql/src/tests/mod.rs +++ b/crates/torii/graphql/src/tests/mod.rs @@ -29,10 +29,10 @@ use torii_core::processors::register_model::RegisterModelProcessor; use torii_core::processors::store_set_record::StoreSetRecordProcessor; use torii_core::sql::Sql; -mod entities_test; +// mod entities_test; mod metadata_test; -mod models_test; -mod subscription_test; +// mod models_test; +// mod subscription_test; use crate::schema::build_schema; @@ -161,6 +161,7 @@ pub struct Content { } #[derive(Deserialize, Debug)] +#[serde(rename_all = "camelCase")] pub struct Metadata { pub uri: String, pub icon_img: String, @@ -205,33 +206,33 @@ pub async fn model_fixtures(db: &mut Sql) { ], }), }, - Member { - name: "record_id".to_string(), + Member { + name: "recordId".to_string(), key: true, ty: Ty::Primitive(Primitive::U32(None)), }, Member { - name: "type_u16".to_string(), + name: "typeU16".to_string(), key: false, ty: Ty::Primitive(Primitive::U16(None)), }, Member { - name: "type_u64".to_string(), + name: "typeU64".to_string(), key: false, ty: Ty::Primitive(Primitive::U64(None)), }, Member { - name: "type_bool".to_string(), + name: "typeBool".to_string(), key: false, ty: Ty::Primitive(Primitive::Bool(None)), }, Member { - name: "type_felt".to_string(), + name: "typeFelt".to_string(), key: false, ty: Ty::Primitive(Primitive::Felt252(None)), }, Member { - name: "type_contract_address".to_string(), + name: "typeContractAddress".to_string(), key: true, ty: Ty::Primitive(Primitive::ContractAddress(None)), }, diff --git a/crates/torii/graphql/src/tests/subscription_test.rs b/crates/torii/graphql/src/tests/subscription_test.rs index 3f243ac929..c9eee89cc1 100644 --- a/crates/torii/graphql/src/tests/subscription_test.rs +++ b/crates/torii/graphql/src/tests/subscription_test.rs @@ -69,32 +69,32 @@ mod tests { }), }, Member { - name: "record_id".to_string(), + name: "recordId".to_string(), key: false, ty: Ty::Primitive(Primitive::U8(Some(0))), }, Member { - name: "type_u16".to_string(), + name: "typeU16".to_string(), key: false, ty: Ty::Primitive(Primitive::U16(Some(1))), }, Member { - name: "type_u64".to_string(), + name: "typeU64".to_string(), key: false, ty: Ty::Primitive(Primitive::U64(Some(1))), }, Member { - name: "type_bool".to_string(), + name: "typeBool".to_string(), key: false, ty: Ty::Primitive(Primitive::Bool(Some(true))), }, Member { - name: "type_felt".to_string(), + name: "typeFelt".to_string(), key: false, ty: Ty::Primitive(Primitive::Felt252(Some(FieldElement::from(1u128)))), }, Member { - name: "type_contract_address".to_string(), + name: "typeContractAddress".to_string(), key: true, ty: Ty::Primitive(Primitive::ContractAddress(Some(FieldElement::ONE))), }, @@ -189,17 +189,17 @@ mod tests { }), }, Member { - name: "record_id".to_string(), + name: "recordId".to_string(), key: false, ty: Ty::Primitive(Primitive::U32(Some(0))), }, Member { - name: "type_felt".to_string(), + name: "typeFelt".to_string(), key: false, ty: Ty::Primitive(Primitive::Felt252(Some(FieldElement::from(1u128)))), }, Member { - name: "type_contract_address".to_string(), + name: "typeContractAddress".to_string(), key: true, ty: Ty::Primitive(Primitive::ContractAddress(Some(FieldElement::ONE))), }, @@ -260,7 +260,7 @@ mod tests { let model = Ty::Struct(Struct { name: model_name, children: vec![Member { - name: "subrecord_id".to_string(), + name: "subrecordId".to_string(), key: true, ty: Ty::Primitive(Primitive::U32(None)), }], @@ -309,7 +309,7 @@ mod tests { let model = Ty::Struct(Struct { name: model_name, children: vec![Member { - name: "type_u8".into(), + name: "typeU8".into(), key: false, ty: Ty::Primitive(Primitive::U8(None)), }], From 2938df0fef8c7886de5c705189ae45a64b29797c Mon Sep 17 00:00:00 2001 From: gianalarcon Date: Mon, 27 Nov 2023 22:52:42 -0500 Subject: [PATCH 03/14] WIP: metadata test --- crates/torii/graphql/src/mapping.rs | 4 ++-- .../graphql/src/object/connection/page_info.rs | 8 ++++---- crates/torii/graphql/src/object/metadata/mod.rs | 8 ++++---- crates/torii/graphql/src/tests/metadata_test.rs | 16 ++++++++-------- crates/torii/graphql/src/tests/mod.rs | 6 +++--- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/crates/torii/graphql/src/mapping.rs b/crates/torii/graphql/src/mapping.rs index 826390c122..982cc135a0 100644 --- a/crates/torii/graphql/src/mapping.rs +++ b/crates/torii/graphql/src/mapping.rs @@ -113,11 +113,11 @@ lazy_static! { (Name::new("icon_img"), TypeData::Simple(TypeRef::named(TypeRef::STRING))), (Name::new("cover_img"), TypeData::Simple(TypeRef::named(TypeRef::STRING))), ( - Name::new("createdAt"), + Name::new("created_at"), TypeData::Simple(TypeRef::named(GraphqlType::DateTime.to_string())) ), ( - Name::new("updatedAt"), + Name::new("updated_at"), TypeData::Simple(TypeRef::named(GraphqlType::DateTime.to_string())) ), ]); diff --git a/crates/torii/graphql/src/object/connection/page_info.rs b/crates/torii/graphql/src/object/connection/page_info.rs index 126f00f7aa..7a27b5b98e 100644 --- a/crates/torii/graphql/src/object/connection/page_info.rs +++ b/crates/torii/graphql/src/object/connection/page_info.rs @@ -33,17 +33,17 @@ impl ObjectTrait for PageInfoObject { impl PageInfoObject { pub fn value(page_info: PageInfo) -> Value { Value::Object(IndexMap::from([ - (Name::new("has_previous_page"), Value::from(page_info.has_previous_page)), - (Name::new("has_next_page"), Value::from(page_info.has_next_page)), + (Name::new("hasPreviousPage"), Value::from(page_info.has_previous_page)), + (Name::new("hasNextPage"), Value::from(page_info.has_next_page)), ( - Name::new("start_cursor"), + Name::new("startCursor"), match page_info.start_cursor { Some(val) => Value::from(val), None => Value::Null, }, ), ( - Name::new("end_cursor"), + Name::new("endCursor"), match page_info.end_cursor { Some(val) => Value::from(val), None => Value::Null, diff --git a/crates/torii/graphql/src/object/metadata/mod.rs b/crates/torii/graphql/src/object/metadata/mod.rs index 4a00b2dd43..8f4da77e70 100644 --- a/crates/torii/graphql/src/object/metadata/mod.rs +++ b/crates/torii/graphql/src/object/metadata/mod.rs @@ -105,8 +105,8 @@ fn metadata_connection_output( extract_str_mapping("name", &serde_value), extract_str_mapping("description", &serde_value), extract_str_mapping("website", &serde_value), - extract_str_mapping("icon_uri", &serde_value), - extract_str_mapping("cover_uri", &serde_value), + extract_str_mapping("iconUri", &serde_value), + extract_str_mapping("coverUri", &serde_value), extract_socials_mapping("socials", &serde_value), ]); @@ -122,9 +122,9 @@ fn metadata_connection_output( .collect::>>(); Ok(ValueMapping::from([ - (Name::new("total_count"), Value::from(total_count)), + (Name::new("totalCount"), Value::from(total_count)), (Name::new("edges"), Value::List(edges?)), - (Name::new("page_info"), PageInfoObject::value(page_info)), + (Name::new("pageInfo"), PageInfoObject::value(page_info)), ])) } diff --git a/crates/torii/graphql/src/tests/metadata_test.rs b/crates/torii/graphql/src/tests/metadata_test.rs index d6490421ff..950ed581d2 100644 --- a/crates/torii/graphql/src/tests/metadata_test.rs +++ b/crates/torii/graphql/src/tests/metadata_test.rs @@ -13,7 +13,7 @@ mod tests { const QUERY: &str = r#" { metadatas { - total_count + totalCount edges { cursor node { @@ -23,8 +23,8 @@ mod tests { content { name description - cover_uri - icon_uri + coverUri + iconUri website socials { name @@ -33,11 +33,11 @@ mod tests { } } } - page_info { - has_previous_page - has_next_page - start_cursor - end_cursor + pageInfo { + hasPreviousPage + hasNextPage + startCursor + endCursor } } } diff --git a/crates/torii/graphql/src/tests/mod.rs b/crates/torii/graphql/src/tests/mod.rs index 5227817073..d332dce838 100644 --- a/crates/torii/graphql/src/tests/mod.rs +++ b/crates/torii/graphql/src/tests/mod.rs @@ -30,9 +30,9 @@ use torii_core::processors::store_set_record::StoreSetRecordProcessor; use torii_core::sql::Sql; // mod entities_test; -mod metadata_test; +// mod metadata_test; // mod models_test; -// mod subscription_test; +mod subscription_test; use crate::schema::build_schema; @@ -161,7 +161,7 @@ pub struct Content { } #[derive(Deserialize, Debug)] -#[serde(rename_all = "camelCase")] +//#[serde(rename_all = "camelCase")] pub struct Metadata { pub uri: String, pub icon_img: String, From 776df1879465b07917eecb11341a0526f40bf222 Mon Sep 17 00:00:00 2001 From: gianalarcon Date: Mon, 27 Nov 2023 23:00:18 -0500 Subject: [PATCH 04/14] fmt --- crates/torii/graphql/src/mapping.rs | 5 +---- crates/torii/graphql/src/tests/mod.rs | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/crates/torii/graphql/src/mapping.rs b/crates/torii/graphql/src/mapping.rs index 982cc135a0..5cd265b86c 100644 --- a/crates/torii/graphql/src/mapping.rs +++ b/crates/torii/graphql/src/mapping.rs @@ -86,10 +86,7 @@ lazy_static! { Name::new("startCursor"), TypeData::Simple(TypeRef::named(GraphqlType::Cursor.to_string())), ), - ( - Name::new("endCursor"), - TypeData::Simple(TypeRef::named(GraphqlType::Cursor.to_string())), - ), + (Name::new("endCursor"), TypeData::Simple(TypeRef::named(GraphqlType::Cursor.to_string())),), ]); pub static ref SOCIAL_TYPE_MAPPING: TypeMapping = IndexMap::from([ (Name::new("name"), TypeData::Simple(TypeRef::named(TypeRef::STRING))), diff --git a/crates/torii/graphql/src/tests/mod.rs b/crates/torii/graphql/src/tests/mod.rs index d332dce838..f24bc06000 100644 --- a/crates/torii/graphql/src/tests/mod.rs +++ b/crates/torii/graphql/src/tests/mod.rs @@ -206,7 +206,7 @@ pub async fn model_fixtures(db: &mut Sql) { ], }), }, - Member { + Member { name: "recordId".to_string(), key: true, ty: Ty::Primitive(Primitive::U32(None)), From 132b7d58f4aebf5126e5786f4f7f569540424d67 Mon Sep 17 00:00:00 2001 From: gianalarcon Date: Tue, 28 Nov 2023 15:39:29 -0500 Subject: [PATCH 05/14] fix merge --- crates/torii/graphql/src/object/entity.rs | 4 ---- crates/torii/graphql/src/tests/subscription_test.rs | 4 ---- 2 files changed, 8 deletions(-) diff --git a/crates/torii/graphql/src/object/entity.rs b/crates/torii/graphql/src/object/entity.rs index d3dc81acac..aa19481648 100644 --- a/crates/torii/graphql/src/object/entity.rs +++ b/crates/torii/graphql/src/object/entity.rs @@ -134,10 +134,6 @@ fn model_union_field() -> Field { match ctx.parent_value.try_to_value()? { Value::Object(indexmap) => { let mut conn = ctx.data::>()?.acquire().await?; - let model_names: Vec = extract::(indexmap, "modelNames")? - .split(',') - .map(|s| s.to_string()) - .collect(); let entity_id = extract::(indexmap, "id")?; let model_ids: Vec<(String,)> = diff --git a/crates/torii/graphql/src/tests/subscription_test.rs b/crates/torii/graphql/src/tests/subscription_test.rs index c9eee89cc1..084615501c 100644 --- a/crates/torii/graphql/src/tests/subscription_test.rs +++ b/crates/torii/graphql/src/tests/subscription_test.rs @@ -30,7 +30,6 @@ mod tests { "entityUpdated": { "id": entity_id, "keys":vec![keys_str], - "modelNames": model_name, "models" : [{ "__typename": model_name, "depth": "Zero", @@ -115,7 +114,6 @@ mod tests { entityUpdated { id keys - modelNames models { __typename ... on Record { @@ -153,7 +151,6 @@ mod tests { "entityUpdated": { "id": entity_id, "keys":vec![keys_str], - "modelNames": model_name, "models" : [{ "__typename": model_name, "depth": "Zero", @@ -220,7 +217,6 @@ mod tests { entityUpdated(id: "0x579e8877c7755365d5ec1ec7d3a94a457eff5d1f40482bbe9729c064cdead2") { id keys - modelNames models { __typename ... on Record { From 2cb2bf6bea1d4b949933fa13b575434b775ca4a6 Mon Sep 17 00:00:00 2001 From: gianalarcon Date: Tue, 28 Nov 2023 16:56:36 -0500 Subject: [PATCH 06/14] pass metadata test --- crates/dojo-world/src/metadata.rs | 1 + crates/torii/graphql/src/mapping.rs | 1 + .../torii/graphql/src/tests/metadata_test.rs | 4 +- crates/torii/graphql/src/tests/mod.rs | 51 +++++++++++-------- 4 files changed, 34 insertions(+), 23 deletions(-) diff --git a/crates/dojo-world/src/metadata.rs b/crates/dojo-world/src/metadata.rs index 9726192215..f4bc519f40 100644 --- a/crates/dojo-world/src/metadata.rs +++ b/crates/dojo-world/src/metadata.rs @@ -77,6 +77,7 @@ impl Uri { } #[derive(Default, Serialize, Deserialize, Debug, Clone)] +#[serde(rename_all = "camelCase")] pub struct WorldMetadata { pub name: Option, pub description: Option, diff --git a/crates/torii/graphql/src/mapping.rs b/crates/torii/graphql/src/mapping.rs index ffb6039f5f..0e7167a34b 100644 --- a/crates/torii/graphql/src/mapping.rs +++ b/crates/torii/graphql/src/mapping.rs @@ -99,6 +99,7 @@ lazy_static! { (Name::new("coverUri"), TypeData::Simple(TypeRef::named(TypeRef::STRING))), (Name::new("socials"), TypeData::Simple(TypeRef::named_list(SOCIAL_TYPE_NAME))) ]); + // Todo: refactor this to use the same type as the one in dojo-world pub static ref METADATA_TYPE_MAPPING: TypeMapping = IndexMap::from([ (Name::new("id"), TypeData::Simple(TypeRef::named(TypeRef::ID))), (Name::new("uri"), TypeData::Simple(TypeRef::named(TypeRef::STRING))), diff --git a/crates/torii/graphql/src/tests/metadata_test.rs b/crates/torii/graphql/src/tests/metadata_test.rs index 950ed581d2..90331ae5e4 100644 --- a/crates/torii/graphql/src/tests/metadata_test.rs +++ b/crates/torii/graphql/src/tests/metadata_test.rs @@ -54,13 +54,13 @@ mod tests { [world] name = "example" description = "example world" - cover_uri = "file://example_cover.png" + coverUri = "file://example_cover.png" website = "https://dojoengine.org" socials.x = "https://x.com/dojostarknet" "#, ) .unwrap(); - + // todo: coverUri -> cover_uri? let world_metadata = dojo_metadata.world.unwrap(); db.update_metadata(&RESOURCE, URI, &world_metadata, &None, &Some(cover_img.to_string())) .await diff --git a/crates/torii/graphql/src/tests/mod.rs b/crates/torii/graphql/src/tests/mod.rs index 281de3a53d..23a144f7f4 100644 --- a/crates/torii/graphql/src/tests/mod.rs +++ b/crates/torii/graphql/src/tests/mod.rs @@ -30,13 +30,14 @@ use torii_core::processors::store_set_record::StoreSetRecordProcessor; use torii_core::sql::Sql; // mod entities_test; -// mod metadata_test; + mod metadata_test; // mod models_test; mod subscription_test; use crate::schema::build_schema; #[derive(Deserialize, Debug, PartialEq)] +#[serde(rename_all = "camelCase")] pub struct Connection { pub total_count: i64, pub edges: Vec>, @@ -56,6 +57,8 @@ pub struct Entity { } #[derive(Deserialize, Debug, PartialEq)] +#[serde(rename_all = "camelCase")] + // same as type from `async-graphql` but derive necessary traits // https://docs.rs/async-graphql/6.0.10/async_graphql/types/connection/struct.PageInfo.html pub struct PageInfo { @@ -65,26 +68,31 @@ pub struct PageInfo { pub end_cursor: Option, } -#[derive(Deserialize, Debug)] -pub struct Moves { - pub __typename: String, - pub remaining: u32, - pub last_direction: String, - pub entity: Option, -} - -#[derive(Deserialize, Debug)] -pub struct Vec2 { - pub x: u32, - pub y: u32, -} - -#[derive(Deserialize, Debug)] -pub struct Position { - pub __typename: String, - pub vec: Vec2, - pub entity: Option, -} +// #[derive(Deserialize, Debug)] +// pub struct Moves { +// pub __typename: String, +// pub remaining: u32, +// pub last_direction: String, +// pub entity: Option, +// } + +// #[derive(Deserialize, Debug)] +// pub struct Vec2 { +// pub x: u32, +// pub y: u32, +// } + +// #[derive(Deserialize, Debug)] +// pub struct Position { +// pub __typename: String, +// pub vec: Vec2, +// pub entity:#[derive(Deserialize, Debug)] +// pub struct Position { +// pub __typename: String, +// pub vec: Vec2, +// pub entity: Option, +// } Option, +// } #[derive(Deserialize, Debug, PartialEq)] pub struct Record { @@ -150,6 +158,7 @@ pub struct Social { } #[derive(Deserialize, Debug, PartialEq)] +#[serde(rename_all = "camelCase")] pub struct Content { pub name: Option, pub description: Option, From 9714a17b541dbff815659379c4343abc9556bb63 Mon Sep 17 00:00:00 2001 From: gianalarcon Date: Tue, 28 Nov 2023 17:20:01 -0500 Subject: [PATCH 07/14] tests models, WIP --- crates/torii/graphql/src/tests/mod.rs | 11 ++- crates/torii/graphql/src/tests/models_test.rs | 90 +++++++++---------- 2 files changed, 53 insertions(+), 48 deletions(-) diff --git a/crates/torii/graphql/src/tests/mod.rs b/crates/torii/graphql/src/tests/mod.rs index 23a144f7f4..b15766e79e 100644 --- a/crates/torii/graphql/src/tests/mod.rs +++ b/crates/torii/graphql/src/tests/mod.rs @@ -30,8 +30,8 @@ use torii_core::processors::store_set_record::StoreSetRecordProcessor; use torii_core::sql::Sql; // mod entities_test; - mod metadata_test; -// mod models_test; +mod metadata_test; +mod models_test; mod subscription_test; use crate::schema::build_schema; @@ -95,6 +95,7 @@ pub struct PageInfo { // } #[derive(Deserialize, Debug, PartialEq)] +#[serde(rename_all = "camelCase")] pub struct Record { pub __typename: String, pub depth: String, @@ -116,6 +117,7 @@ pub struct Record { } #[derive(Deserialize, Debug, PartialEq)] +#[serde(rename_all = "camelCase")] pub struct Nested { pub __typename: String, pub depth: String, @@ -125,6 +127,7 @@ pub struct Nested { } #[derive(Deserialize, Debug, PartialEq)] +#[serde(rename_all = "camelCase")] pub struct NestedMore { pub __typename: String, pub depth: String, @@ -134,6 +137,7 @@ pub struct NestedMore { } #[derive(Deserialize, Debug, PartialEq)] +#[serde(rename_all = "camelCase")] pub struct NestedMoreMore { pub __typename: String, pub depth: String, @@ -141,7 +145,8 @@ pub struct NestedMoreMore { pub type_string: String, } -#[derive(Deserialize, Debug, PartialEq)] +#[derive(Deserialize, Debug, PartialEq)]#[serde(rename_all = "camelCase")] +#[serde(rename_all = "camelCase")] pub struct Subrecord { pub __typename: String, pub record_id: u32, diff --git a/crates/torii/graphql/src/tests/models_test.rs b/crates/torii/graphql/src/tests/models_test.rs index 4678013f9f..4c9f89e4b8 100644 --- a/crates/torii/graphql/src/tests/models_test.rs +++ b/crates/torii/graphql/src/tests/models_test.rs @@ -15,40 +15,40 @@ mod tests { r#" {{ recordModels {} {{ - total_count + totalCount edges {{ cursor node {{ __typename - record_id + recordId depth - type_u8 - type_u16 - type_u32 - type_u64 - type_u128 - type_u256 - type_bool - type_felt - type_class_hash - type_contract_address - random_u8 - random_u128 - type_nested {{ + typeU8 + typeU16 + typeU32 + typeU64 + typeU128 + typeU256 + typeBool + typeFelt + typeClassHash + typeContractAddress + randomU8 + randomU128 + typeNested {{ __typename depth - type_number - type_string - type_nested_more {{ + typeNumber + typeString + typeNestedMore {{ __typename depth - type_number - type_string - type_nested_more_more {{ + typeNumber + typeString + typeNestedMoreMore {{ __typename depth - type_number - type_string + typeNumber + typeString }} }} }} @@ -57,11 +57,11 @@ mod tests { }} }} }} - page_info {{ - has_previous_page - has_next_page - start_cursor - end_cursor + pageInfo {{ + hasPreviousPage + hasNextPage + startCursor + endCursor }} }} }} @@ -100,25 +100,25 @@ mod tests { // *** WHERE FILTER TESTING *** // where filter EQ on u8 - let records = records_model_query(&schema, "(where: { type_u8: 0 })").await; + let records = records_model_query(&schema, "(where: { typeU8: 0 })").await; let connection: Connection = serde_json::from_value(records).unwrap(); let first_record = connection.edges.first().unwrap(); assert_eq!(connection.total_count, 1); assert_eq!(first_record.node.record_id, 0); // where filter GTE on u16 - let records = records_model_query(&schema, "(where: { type_u16GTE: 5 })").await; + let records = records_model_query(&schema, "(where: { typeU16GTE: 5 })").await; let connection: Connection = serde_json::from_value(records).unwrap(); assert_eq!(connection.total_count, 5); // where filter LTE on u32 - let records = records_model_query(&schema, "(where: { type_u32LTE: 4 })").await; + let records = records_model_query(&schema, "(where: { typeU32LTE: 4 })").await; let connection: Connection = serde_json::from_value(records).unwrap(); assert_eq!(connection.total_count, 5); // where filter LT and GT let records = - records_model_query(&schema, "(where: { type_u32GT: 2, type_u64LT: 4 })").await; + records_model_query(&schema, "(where: { typeU32GT: 2, typeU64LT: 4 })").await; let connection: Connection = serde_json::from_value(records).unwrap(); let first_record = connection.edges.first().unwrap(); assert_eq!(first_record.node.type_u64, 3); @@ -131,7 +131,7 @@ mod tests { let records = records_model_query( &schema, &format!( - "(where: {{ type_class_hash: \"{}\", type_contract_address: \"{}\" }})", + "(where: {{ typeClassHash: \"{}\", typeContractAddress: \"{}\" }})", felt_str_0x5, felt_str_0x5 ), ) @@ -143,7 +143,7 @@ mod tests { // where filter GTE on u128 (string) let records = records_model_query( &schema, - &format!("(where: {{ type_u128GTE: \"{}\" }})", felt_str_0x5), + &format!("(where: {{ typeU128GTE: \"{}\" }})", felt_str_0x5), ) .await; let connection: Connection = serde_json::from_value(records).unwrap(); @@ -156,7 +156,7 @@ mod tests { // where filter LT on u256 (string) let records = records_model_query( &schema, - &format!("(where: {{ type_u256LT: \"{}\" }})", felt_str_0x5), + &format!("(where: {{ typeU256LT: \"{}\" }})", felt_str_0x5), ) .await; let connection: Connection = serde_json::from_value(records).unwrap(); @@ -167,14 +167,14 @@ mod tests { assert_eq!(last_record.node.type_u256, "0x0"); // where filter on true bool - let records = records_model_query(&schema, "(where: { type_bool: true })").await; + let records = records_model_query(&schema, "(where: { typeBool: true })").await; let connection: Connection = serde_json::from_value(records).unwrap(); let first_record = connection.edges.first().unwrap(); assert_eq!(connection.total_count, 5); assert!(first_record.node.type_bool, "should be true"); // where filter on false bool - let records = records_model_query(&schema, "(where: { type_bool: false })").await; + let records = records_model_query(&schema, "(where: { typeBool: false })").await; let connection: Connection = serde_json::from_value(records).unwrap(); let first_record = connection.edges.first().unwrap(); assert_eq!(connection.total_count, 5); @@ -208,7 +208,7 @@ mod tests { let records = records_model_query( &schema, &format!( - "(where: {{ type_feltGTE: \"{}\" }}, order: {{ field: TYPE_FELT, direction: DESC \ + "(where: {{ typeFeltGTE: \"{}\" }}, order: {{ field: TYPE_FELT, direction: DESC \ }})", felt_str_0x5 ), @@ -222,7 +222,7 @@ mod tests { // *** WHERE FILTER + PAGINATION TESTING *** - let records = records_model_query(&schema, "(where: { type_u8GTE: 5 })").await; + let records = records_model_query(&schema, "(where: { typeU8GTE: 5 })").await; let connection: Connection = serde_json::from_value(records).unwrap(); let one = connection.edges.get(0).unwrap(); let two = connection.edges.get(1).unwrap(); @@ -231,7 +231,7 @@ mod tests { let five = connection.edges.get(4).unwrap(); // cursor based pagination - let records = records_model_query(&schema, "(where: { type_u8GTE: 5 }, first: 2)").await; + let records = records_model_query(&schema, "(where: { typeU8GTE: 5 }, first: 2)").await; let connection: Connection = serde_json::from_value(records).unwrap(); let first_record = connection.edges.first().unwrap(); let last_record = connection.edges.last().unwrap(); @@ -242,7 +242,7 @@ mod tests { let records = records_model_query( &schema, - &format!("(where: {{ type_u8GTE: 5 }}, first: 3, after: \"{}\")", last_record.cursor), + &format!("(where: {{ typeU8GTE: 5 }}, first: 3, after: \"{}\")", last_record.cursor), ) .await; let connection: Connection = serde_json::from_value(records).unwrap(); @@ -255,7 +255,7 @@ mod tests { // offset/limit base pagination let records = - records_model_query(&schema, "(where: { type_u8GTE: 5 }, limit: 2, offset: 2)").await; + records_model_query(&schema, "(where: { typeU8GTE: 5 }, limit: 2, offset: 2)").await; let connection: Connection = serde_json::from_value(records).unwrap(); let first_record = connection.edges.first().unwrap(); let last_record = connection.edges.last().unwrap(); @@ -268,7 +268,7 @@ mod tests { let records = records_model_query( &schema, - "(where: { type_u8GTE: 7 }, order: {field: TYPE_U8, direction: DESC})", + "(where: { typeU8GTE: 7 }, order: {field: TYPE_U8, direction: DESC})", ) .await; let connection: Connection = serde_json::from_value(records).unwrap(); @@ -280,7 +280,7 @@ mod tests { let records = records_model_query( &schema, &format!( - "(where: {{ type_u8GTE: 7 }}, order: {{field: TYPE_U8, direction: DESC}}, after: \ + "(where: {{ typeU8GTE: 7 }}, order: {{field: TYPE_U8, direction: DESC}}, after: \ \"{}\")", one.cursor ), @@ -293,7 +293,7 @@ mod tests { let records = records_model_query( &schema, &format!( - "(where: {{ type_u8GTE: 7 }}, order: {{field: TYPE_U8, direction: DESC}}, after: \ + "(where: {{ typeU8GTE: 7 }}, order: {{field: TYPE_U8, direction: DESC}}, after: \ \"{}\")", three.cursor ), From 9d57e64282980ff4627eb7341c53e5fb88e7edf3 Mon Sep 17 00:00:00 2001 From: gianalarcon Date: Wed, 29 Nov 2023 14:22:26 -0500 Subject: [PATCH 08/14] refactor subscriptions and events to mixed_case format --- crates/torii/graphql/src/tests/mod.rs | 10 +++--- .../graphql/src/tests/subscription_test.rs | 32 +++++++++---------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/crates/torii/graphql/src/tests/mod.rs b/crates/torii/graphql/src/tests/mod.rs index b15766e79e..ddd5534950 100644 --- a/crates/torii/graphql/src/tests/mod.rs +++ b/crates/torii/graphql/src/tests/mod.rs @@ -31,7 +31,7 @@ use torii_core::sql::Sql; // mod entities_test; mod metadata_test; -mod models_test; +// mod models_test; mod subscription_test; use crate::schema::build_schema; @@ -145,7 +145,7 @@ pub struct NestedMoreMore { pub type_string: String, } -#[derive(Deserialize, Debug, PartialEq)]#[serde(rename_all = "camelCase")] +#[derive(Deserialize, Debug, PartialEq)] #[serde(rename_all = "camelCase")] pub struct Subrecord { pub __typename: String, @@ -220,7 +220,7 @@ pub async fn model_fixtures(db: &mut Sql) { }), }, Member { - name: "recordId".to_string(), + name: "record_id".to_string(), key: true, ty: Ty::Primitive(Primitive::U32(None)), }, @@ -230,7 +230,7 @@ pub async fn model_fixtures(db: &mut Sql) { ty: Ty::Primitive(Primitive::U16(None)), }, Member { - name: "typeU64".to_string(), + name: "type_u64".to_string(), key: false, ty: Ty::Primitive(Primitive::U64(None)), }, @@ -240,7 +240,7 @@ pub async fn model_fixtures(db: &mut Sql) { ty: Ty::Primitive(Primitive::Bool(None)), }, Member { - name: "typeFelt".to_string(), + name: "type_felt".to_string(), key: false, ty: Ty::Primitive(Primitive::Felt252(None)), }, diff --git a/crates/torii/graphql/src/tests/subscription_test.rs b/crates/torii/graphql/src/tests/subscription_test.rs index 084615501c..879d209dec 100644 --- a/crates/torii/graphql/src/tests/subscription_test.rs +++ b/crates/torii/graphql/src/tests/subscription_test.rs @@ -33,11 +33,11 @@ mod tests { "models" : [{ "__typename": model_name, "depth": "Zero", - "recordId": 0, + "record_id": 0, "typeU16": 1, - "typeU64": 1, + "type_u64": 1, "typeBool": true, - "typeFelt": format!("{:#x}", FieldElement::from(1u128)), + "type_felt": format!("{:#x}", FieldElement::from(1u128)), "typeContractAddress": format!("{:#x}", FieldElement::ONE) }] } @@ -68,7 +68,7 @@ mod tests { }), }, Member { - name: "recordId".to_string(), + name: "record_id".to_string(), key: false, ty: Ty::Primitive(Primitive::U8(Some(0))), }, @@ -78,7 +78,7 @@ mod tests { ty: Ty::Primitive(Primitive::U16(Some(1))), }, Member { - name: "typeU64".to_string(), + name: "type_u64".to_string(), key: false, ty: Ty::Primitive(Primitive::U64(Some(1))), }, @@ -88,7 +88,7 @@ mod tests { ty: Ty::Primitive(Primitive::Bool(Some(true))), }, Member { - name: "typeFelt".to_string(), + name: "type_felt".to_string(), key: false, ty: Ty::Primitive(Primitive::Felt252(Some(FieldElement::from(1u128)))), }, @@ -118,11 +118,11 @@ mod tests { __typename ... on Record { depth - recordId + record_id typeU16 - typeU64 + type_u64 typeBool - typeFelt + type_felt typeContractAddress } } @@ -154,8 +154,8 @@ mod tests { "models" : [{ "__typename": model_name, "depth": "Zero", - "recordId": 0, - "typeFelt": format!("{:#x}", FieldElement::from(1u128)), + "record_id": 0, + "type_felt": format!("{:#x}", FieldElement::from(1u128)), "typeContractAddress": format!("{:#x}", FieldElement::ONE) }] } @@ -186,12 +186,12 @@ mod tests { }), }, Member { - name: "recordId".to_string(), + name: "record_id".to_string(), key: false, ty: Ty::Primitive(Primitive::U32(Some(0))), }, Member { - name: "typeFelt".to_string(), + name: "type_felt".to_string(), key: false, ty: Ty::Primitive(Primitive::Felt252(Some(FieldElement::from(1u128)))), }, @@ -221,8 +221,8 @@ mod tests { __typename ... on Record { depth - recordId - typeFelt + record_id + type_felt typeContractAddress } } @@ -305,7 +305,7 @@ mod tests { let model = Ty::Struct(Struct { name: model_name, children: vec![Member { - name: "typeU8".into(), + name: "type_u8".into(), key: false, ty: Ty::Primitive(Primitive::U8(None)), }], From 02ee0685853110d7d5876dd2dc5bdc0a7717b88b Mon Sep 17 00:00:00 2001 From: gianalarcon Date: Wed, 29 Nov 2023 16:12:08 -0500 Subject: [PATCH 09/14] Pass models_tests --- crates/torii/core/src/types.rs | 2 +- crates/torii/graphql/src/mapping.rs | 4 +- crates/torii/graphql/src/object/entity.rs | 6 +- crates/torii/graphql/src/tests/mod.rs | 16 ++-- crates/torii/graphql/src/tests/models_test.rs | 78 +++++++++---------- 5 files changed, 53 insertions(+), 53 deletions(-) diff --git a/crates/torii/core/src/types.rs b/crates/torii/core/src/types.rs index cfca4769bb..1b84024524 100644 --- a/crates/torii/core/src/types.rs +++ b/crates/torii/core/src/types.rs @@ -29,7 +29,7 @@ impl fmt::LowerHex for SQLFieldElement { } #[derive(FromRow, Deserialize, Debug, Clone)] -#[serde(rename_all = "camelCase")] +//#[serde(rename_all = "camelCase")] pub struct Entity { pub id: String, pub keys: String, diff --git a/crates/torii/graphql/src/mapping.rs b/crates/torii/graphql/src/mapping.rs index 0e7167a34b..4b02d27939 100644 --- a/crates/torii/graphql/src/mapping.rs +++ b/crates/torii/graphql/src/mapping.rs @@ -13,11 +13,11 @@ lazy_static! { (Name::new("keys"), TypeData::Simple(TypeRef::named_list(TypeRef::STRING))), (Name::new("event_id"), TypeData::Simple(TypeRef::named(TypeRef::STRING))), ( - Name::new("createdAt"), + Name::new("created_at"), TypeData::Simple(TypeRef::named(GraphqlType::DateTime.to_string())), ), ( - Name::new("updatedAt"), + Name::new("updated_at"), TypeData::Simple(TypeRef::named(GraphqlType::DateTime.to_string())), ), ]); diff --git a/crates/torii/graphql/src/object/entity.rs b/crates/torii/graphql/src/object/entity.rs index aa19481648..cabad6d057 100644 --- a/crates/torii/graphql/src/object/entity.rs +++ b/crates/torii/graphql/src/object/entity.rs @@ -115,13 +115,13 @@ impl EntityObject { IndexMap::from([ (Name::new("id"), Value::from(entity.id)), (Name::new("keys"), Value::from(keys)), - (Name::new("eventId"), Value::from(entity.event_id)), + (Name::new("event_id"), Value::from(entity.event_id)), ( - Name::new("createdAt"), + Name::new("created_at"), Value::from(entity.created_at.format("%Y-%m-%d %H:%M:%S").to_string()), ), ( - Name::new("updatedAt"), + Name::new("updated_at"), Value::from(entity.updated_at.format("%Y-%m-%d %H:%M:%S").to_string()), ), ]) diff --git a/crates/torii/graphql/src/tests/mod.rs b/crates/torii/graphql/src/tests/mod.rs index ddd5534950..79ee37f246 100644 --- a/crates/torii/graphql/src/tests/mod.rs +++ b/crates/torii/graphql/src/tests/mod.rs @@ -29,9 +29,9 @@ use torii_core::processors::register_model::RegisterModelProcessor; use torii_core::processors::store_set_record::StoreSetRecordProcessor; use torii_core::sql::Sql; -// mod entities_test; +mod entities_test; mod metadata_test; -// mod models_test; +mod models_test; mod subscription_test; use crate::schema::build_schema; @@ -51,6 +51,7 @@ pub struct Edge { } #[derive(Deserialize, Debug, PartialEq)] +#[serde(rename_all = "camelCase")] pub struct Entity { pub keys: Option>, pub created_at: Option, @@ -58,7 +59,6 @@ pub struct Entity { #[derive(Deserialize, Debug, PartialEq)] #[serde(rename_all = "camelCase")] - // same as type from `async-graphql` but derive necessary traits // https://docs.rs/async-graphql/6.0.10/async_graphql/types/connection/struct.PageInfo.html pub struct PageInfo { @@ -95,7 +95,7 @@ pub struct PageInfo { // } #[derive(Deserialize, Debug, PartialEq)] -#[serde(rename_all = "camelCase")] +//#[serde(rename_all = "camelCase")] pub struct Record { pub __typename: String, pub depth: String, @@ -117,7 +117,7 @@ pub struct Record { } #[derive(Deserialize, Debug, PartialEq)] -#[serde(rename_all = "camelCase")] +//#[serde(rename_all = "camelCase")] pub struct Nested { pub __typename: String, pub depth: String, @@ -127,7 +127,7 @@ pub struct Nested { } #[derive(Deserialize, Debug, PartialEq)] -#[serde(rename_all = "camelCase")] +//#[serde(rename_all = "camelCase")] pub struct NestedMore { pub __typename: String, pub depth: String, @@ -137,7 +137,7 @@ pub struct NestedMore { } #[derive(Deserialize, Debug, PartialEq)] -#[serde(rename_all = "camelCase")] +//#[serde(rename_all = "camelCase")] pub struct NestedMoreMore { pub __typename: String, pub depth: String, @@ -284,7 +284,7 @@ pub async fn spinup_types_test() -> Result { execute_strategy(&ws, &migration, &account, None).await.unwrap(); // Execute `create` and insert 10 records into storage - let records_contract = "0x2e6254aaf7e47502319f35de01376cece263f9b83afe6169a4b3a76ef47c8a3"; + let records_contract = "0x2753d30656b393ecea156189bf0acf5e1063f3ac978fb5c3cebe7a4570bbc78"; let InvokeTransactionResult { transaction_hash } = account .execute(vec![Call { calldata: vec![FieldElement::from_str("0xa").unwrap()], diff --git a/crates/torii/graphql/src/tests/models_test.rs b/crates/torii/graphql/src/tests/models_test.rs index 4c9f89e4b8..ab6e0f748d 100644 --- a/crates/torii/graphql/src/tests/models_test.rs +++ b/crates/torii/graphql/src/tests/models_test.rs @@ -20,35 +20,35 @@ mod tests { cursor node {{ __typename - recordId + record_id depth - typeU8 - typeU16 - typeU32 - typeU64 - typeU128 - typeU256 - typeBool - typeFelt - typeClassHash - typeContractAddress - randomU8 - randomU128 - typeNested {{ + type_u8 + type_u16 + type_u32 + type_u64 + type_u128 + type_u256 + type_bool + type_felt + type_class_hash + type_contract_address + random_u8 + random_u128 + type_nested {{ __typename depth - typeNumber - typeString - typeNestedMore {{ + type_number + type_string + type_nested_more {{ __typename depth - typeNumber - typeString - typeNestedMoreMore {{ + type_number + type_string + type_nested_more_more {{ __typename depth - typeNumber - typeString + type_number + type_string }} }} }} @@ -100,25 +100,25 @@ mod tests { // *** WHERE FILTER TESTING *** // where filter EQ on u8 - let records = records_model_query(&schema, "(where: { typeU8: 0 })").await; + let records = records_model_query(&schema, "(where: { type_u8: 0 })").await; let connection: Connection = serde_json::from_value(records).unwrap(); let first_record = connection.edges.first().unwrap(); assert_eq!(connection.total_count, 1); assert_eq!(first_record.node.record_id, 0); // where filter GTE on u16 - let records = records_model_query(&schema, "(where: { typeU16GTE: 5 })").await; + let records = records_model_query(&schema, "(where: { type_u16GTE: 5 })").await; let connection: Connection = serde_json::from_value(records).unwrap(); assert_eq!(connection.total_count, 5); // where filter LTE on u32 - let records = records_model_query(&schema, "(where: { typeU32LTE: 4 })").await; + let records = records_model_query(&schema, "(where: { type_u32LTE: 4 })").await; let connection: Connection = serde_json::from_value(records).unwrap(); assert_eq!(connection.total_count, 5); // where filter LT and GT let records = - records_model_query(&schema, "(where: { typeU32GT: 2, typeU64LT: 4 })").await; + records_model_query(&schema, "(where: { type_u32GT: 2, type_u64LT: 4 })").await; let connection: Connection = serde_json::from_value(records).unwrap(); let first_record = connection.edges.first().unwrap(); assert_eq!(first_record.node.type_u64, 3); @@ -131,7 +131,7 @@ mod tests { let records = records_model_query( &schema, &format!( - "(where: {{ typeClassHash: \"{}\", typeContractAddress: \"{}\" }})", + "(where: {{ type_class_hash: \"{}\", type_contract_address: \"{}\" }})", felt_str_0x5, felt_str_0x5 ), ) @@ -143,7 +143,7 @@ mod tests { // where filter GTE on u128 (string) let records = records_model_query( &schema, - &format!("(where: {{ typeU128GTE: \"{}\" }})", felt_str_0x5), + &format!("(where: {{ type_u128GTE: \"{}\" }})", felt_str_0x5), ) .await; let connection: Connection = serde_json::from_value(records).unwrap(); @@ -156,7 +156,7 @@ mod tests { // where filter LT on u256 (string) let records = records_model_query( &schema, - &format!("(where: {{ typeU256LT: \"{}\" }})", felt_str_0x5), + &format!("(where: {{ type_u256LT: \"{}\" }})", felt_str_0x5), ) .await; let connection: Connection = serde_json::from_value(records).unwrap(); @@ -167,14 +167,14 @@ mod tests { assert_eq!(last_record.node.type_u256, "0x0"); // where filter on true bool - let records = records_model_query(&schema, "(where: { typeBool: true })").await; + let records = records_model_query(&schema, "(where: { type_bool: true })").await; let connection: Connection = serde_json::from_value(records).unwrap(); let first_record = connection.edges.first().unwrap(); assert_eq!(connection.total_count, 5); assert!(first_record.node.type_bool, "should be true"); // where filter on false bool - let records = records_model_query(&schema, "(where: { typeBool: false })").await; + let records = records_model_query(&schema, "(where: { type_bool: false })").await; let connection: Connection = serde_json::from_value(records).unwrap(); let first_record = connection.edges.first().unwrap(); assert_eq!(connection.total_count, 5); @@ -208,7 +208,7 @@ mod tests { let records = records_model_query( &schema, &format!( - "(where: {{ typeFeltGTE: \"{}\" }}, order: {{ field: TYPE_FELT, direction: DESC \ + "(where: {{ type_feltGTE: \"{}\" }}, order: {{ field: TYPE_FELT, direction: DESC \ }})", felt_str_0x5 ), @@ -222,7 +222,7 @@ mod tests { // *** WHERE FILTER + PAGINATION TESTING *** - let records = records_model_query(&schema, "(where: { typeU8GTE: 5 })").await; + let records = records_model_query(&schema, "(where: { type_u8GTE: 5 })").await; let connection: Connection = serde_json::from_value(records).unwrap(); let one = connection.edges.get(0).unwrap(); let two = connection.edges.get(1).unwrap(); @@ -231,7 +231,7 @@ mod tests { let five = connection.edges.get(4).unwrap(); // cursor based pagination - let records = records_model_query(&schema, "(where: { typeU8GTE: 5 }, first: 2)").await; + let records = records_model_query(&schema, "(where: { type_u8GTE: 5 }, first: 2)").await; let connection: Connection = serde_json::from_value(records).unwrap(); let first_record = connection.edges.first().unwrap(); let last_record = connection.edges.last().unwrap(); @@ -242,7 +242,7 @@ mod tests { let records = records_model_query( &schema, - &format!("(where: {{ typeU8GTE: 5 }}, first: 3, after: \"{}\")", last_record.cursor), + &format!("(where: {{ type_u8GTE: 5 }}, first: 3, after: \"{}\")", last_record.cursor), ) .await; let connection: Connection = serde_json::from_value(records).unwrap(); @@ -255,7 +255,7 @@ mod tests { // offset/limit base pagination let records = - records_model_query(&schema, "(where: { typeU8GTE: 5 }, limit: 2, offset: 2)").await; + records_model_query(&schema, "(where: { type_u8GTE: 5 }, limit: 2, offset: 2)").await; let connection: Connection = serde_json::from_value(records).unwrap(); let first_record = connection.edges.first().unwrap(); let last_record = connection.edges.last().unwrap(); @@ -268,7 +268,7 @@ mod tests { let records = records_model_query( &schema, - "(where: { typeU8GTE: 7 }, order: {field: TYPE_U8, direction: DESC})", + "(where: { type_u8GTE: 7 }, order: {field: TYPE_U8, direction: DESC})", ) .await; let connection: Connection = serde_json::from_value(records).unwrap(); @@ -280,7 +280,7 @@ mod tests { let records = records_model_query( &schema, &format!( - "(where: {{ typeU8GTE: 7 }}, order: {{field: TYPE_U8, direction: DESC}}, after: \ + "(where: {{ type_u8GTE: 7 }}, order: {{field: TYPE_U8, direction: DESC}}, after: \ \"{}\")", one.cursor ), @@ -293,7 +293,7 @@ mod tests { let records = records_model_query( &schema, &format!( - "(where: {{ typeU8GTE: 7 }}, order: {{field: TYPE_U8, direction: DESC}}, after: \ + "(where: {{ type_u8GTE: 7 }}, order: {{field: TYPE_U8, direction: DESC}}, after: \ \"{}\")", three.cursor ), From 9e2a0a9406e33163e4970e97988d34e251dcf683 Mon Sep 17 00:00:00 2001 From: gianalarcon Date: Wed, 29 Nov 2023 16:29:51 -0500 Subject: [PATCH 10/14] pass entities_test --- crates/torii/graphql/src/tests/entities_test.rs | 10 +++++----- crates/torii/graphql/src/tests/mod.rs | 5 ----- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/crates/torii/graphql/src/tests/entities_test.rs b/crates/torii/graphql/src/tests/entities_test.rs index 0a8baed0a5..af8bbcc905 100644 --- a/crates/torii/graphql/src/tests/entities_test.rs +++ b/crates/torii/graphql/src/tests/entities_test.rs @@ -23,11 +23,11 @@ mod tests { keys }} }} - page_info {{ - has_previous_page - has_next_page - start_cursor - end_cursor + pageInfo {{ + hasPreviousPage + hasNextPage + startCursor + endCursor }} }} }} diff --git a/crates/torii/graphql/src/tests/mod.rs b/crates/torii/graphql/src/tests/mod.rs index 79ee37f246..4f42d3401c 100644 --- a/crates/torii/graphql/src/tests/mod.rs +++ b/crates/torii/graphql/src/tests/mod.rs @@ -95,7 +95,6 @@ pub struct PageInfo { // } #[derive(Deserialize, Debug, PartialEq)] -//#[serde(rename_all = "camelCase")] pub struct Record { pub __typename: String, pub depth: String, @@ -117,7 +116,6 @@ pub struct Record { } #[derive(Deserialize, Debug, PartialEq)] -//#[serde(rename_all = "camelCase")] pub struct Nested { pub __typename: String, pub depth: String, @@ -127,7 +125,6 @@ pub struct Nested { } #[derive(Deserialize, Debug, PartialEq)] -//#[serde(rename_all = "camelCase")] pub struct NestedMore { pub __typename: String, pub depth: String, @@ -137,7 +134,6 @@ pub struct NestedMore { } #[derive(Deserialize, Debug, PartialEq)] -//#[serde(rename_all = "camelCase")] pub struct NestedMoreMore { pub __typename: String, pub depth: String, @@ -146,7 +142,6 @@ pub struct NestedMoreMore { } #[derive(Deserialize, Debug, PartialEq)] -#[serde(rename_all = "camelCase")] pub struct Subrecord { pub __typename: String, pub record_id: u32, From b383155cda696cfb196594e7b11f7e57ffa881c4 Mon Sep 17 00:00:00 2001 From: gianalarcon Date: Wed, 29 Nov 2023 16:51:30 -0500 Subject: [PATCH 11/14] clean --- crates/dojo-core/Scarb.lock | 2 +- crates/torii/graphql/src/mapping.rs | 6 +++--- crates/torii/graphql/src/tests/mod.rs | 28 +-------------------------- 3 files changed, 5 insertions(+), 31 deletions(-) diff --git a/crates/dojo-core/Scarb.lock b/crates/dojo-core/Scarb.lock index 72531bfc18..c7222cdada 100644 --- a/crates/dojo-core/Scarb.lock +++ b/crates/dojo-core/Scarb.lock @@ -3,7 +3,7 @@ version = 1 [[package]] name = "dojo" -version = "0.3.12" +version = "0.3.13" dependencies = [ "dojo_plugin", ] diff --git a/crates/torii/graphql/src/mapping.rs b/crates/torii/graphql/src/mapping.rs index 4b02d27939..8fc596001e 100644 --- a/crates/torii/graphql/src/mapping.rs +++ b/crates/torii/graphql/src/mapping.rs @@ -35,15 +35,15 @@ lazy_static! { (Name::new("id"), TypeData::Simple(TypeRef::named(TypeRef::ID))), (Name::new("name"), TypeData::Simple(TypeRef::named(TypeRef::STRING))), ( - Name::new("classHash"), + Name::new("class_hash"), TypeData::Simple(TypeRef::named(Primitive::Felt252(None).to_string())), ), ( - Name::new("transactionHash"), + Name::new("transaction_hash"), TypeData::Simple(TypeRef::named(Primitive::Felt252(None).to_string())), ), ( - Name::new("createdAt"), + Name::new("created_at"), TypeData::Simple(TypeRef::named(GraphqlType::DateTime.to_string())), ), ]); diff --git a/crates/torii/graphql/src/tests/mod.rs b/crates/torii/graphql/src/tests/mod.rs index 4f42d3401c..584c6713b3 100644 --- a/crates/torii/graphql/src/tests/mod.rs +++ b/crates/torii/graphql/src/tests/mod.rs @@ -68,32 +68,6 @@ pub struct PageInfo { pub end_cursor: Option, } -// #[derive(Deserialize, Debug)] -// pub struct Moves { -// pub __typename: String, -// pub remaining: u32, -// pub last_direction: String, -// pub entity: Option, -// } - -// #[derive(Deserialize, Debug)] -// pub struct Vec2 { -// pub x: u32, -// pub y: u32, -// } - -// #[derive(Deserialize, Debug)] -// pub struct Position { -// pub __typename: String, -// pub vec: Vec2, -// pub entity:#[derive(Deserialize, Debug)] -// pub struct Position { -// pub __typename: String, -// pub vec: Vec2, -// pub entity: Option, -// } Option, -// } - #[derive(Deserialize, Debug, PartialEq)] pub struct Record { pub __typename: String, @@ -279,7 +253,7 @@ pub async fn spinup_types_test() -> Result { execute_strategy(&ws, &migration, &account, None).await.unwrap(); // Execute `create` and insert 10 records into storage - let records_contract = "0x2753d30656b393ecea156189bf0acf5e1063f3ac978fb5c3cebe7a4570bbc78"; + let records_contract = "0x2e6254aaf7e47502319f35de01376cece263f9b83afe6169a4b3a76ef47c8a3"; let InvokeTransactionResult { transaction_hash } = account .execute(vec![Call { calldata: vec![FieldElement::from_str("0xa").unwrap()], From 847d4f67976483471bbfbc6c1670e26726bf0999 Mon Sep 17 00:00:00 2001 From: gianalarcon Date: Thu, 30 Nov 2023 00:28:13 -0500 Subject: [PATCH 12/14] keep cover_uri to snake_case --- crates/dojo-world/src/metadata.rs | 1 - crates/torii/graphql/src/mapping.rs | 4 ++-- crates/torii/graphql/src/object/metadata/mod.rs | 4 ++-- crates/torii/graphql/src/tests/metadata_test.rs | 7 +++---- crates/torii/graphql/src/tests/mod.rs | 1 - 5 files changed, 7 insertions(+), 10 deletions(-) diff --git a/crates/dojo-world/src/metadata.rs b/crates/dojo-world/src/metadata.rs index f4bc519f40..9726192215 100644 --- a/crates/dojo-world/src/metadata.rs +++ b/crates/dojo-world/src/metadata.rs @@ -77,7 +77,6 @@ impl Uri { } #[derive(Default, Serialize, Deserialize, Debug, Clone)] -#[serde(rename_all = "camelCase")] pub struct WorldMetadata { pub name: Option, pub description: Option, diff --git a/crates/torii/graphql/src/mapping.rs b/crates/torii/graphql/src/mapping.rs index 8fc596001e..679d3eda92 100644 --- a/crates/torii/graphql/src/mapping.rs +++ b/crates/torii/graphql/src/mapping.rs @@ -95,8 +95,8 @@ lazy_static! { (Name::new("name"), TypeData::Simple(TypeRef::named(TypeRef::STRING))), (Name::new("description"), TypeData::Simple(TypeRef::named(TypeRef::STRING))), (Name::new("website"), TypeData::Simple(TypeRef::named(TypeRef::STRING))), - (Name::new("iconUri"), TypeData::Simple(TypeRef::named(TypeRef::STRING))), - (Name::new("coverUri"), TypeData::Simple(TypeRef::named(TypeRef::STRING))), + (Name::new("icon_uri"), TypeData::Simple(TypeRef::named(TypeRef::STRING))), + (Name::new("cover_uri"), TypeData::Simple(TypeRef::named(TypeRef::STRING))), (Name::new("socials"), TypeData::Simple(TypeRef::named_list(SOCIAL_TYPE_NAME))) ]); // Todo: refactor this to use the same type as the one in dojo-world diff --git a/crates/torii/graphql/src/object/metadata/mod.rs b/crates/torii/graphql/src/object/metadata/mod.rs index 8f4da77e70..94e8171d4a 100644 --- a/crates/torii/graphql/src/object/metadata/mod.rs +++ b/crates/torii/graphql/src/object/metadata/mod.rs @@ -105,8 +105,8 @@ fn metadata_connection_output( extract_str_mapping("name", &serde_value), extract_str_mapping("description", &serde_value), extract_str_mapping("website", &serde_value), - extract_str_mapping("iconUri", &serde_value), - extract_str_mapping("coverUri", &serde_value), + extract_str_mapping("icon_uri", &serde_value), + extract_str_mapping("cover_uri", &serde_value), extract_socials_mapping("socials", &serde_value), ]); diff --git a/crates/torii/graphql/src/tests/metadata_test.rs b/crates/torii/graphql/src/tests/metadata_test.rs index 90331ae5e4..6977031703 100644 --- a/crates/torii/graphql/src/tests/metadata_test.rs +++ b/crates/torii/graphql/src/tests/metadata_test.rs @@ -23,8 +23,8 @@ mod tests { content { name description - coverUri - iconUri + cover_uri + icon_uri website socials { name @@ -54,13 +54,12 @@ mod tests { [world] name = "example" description = "example world" - coverUri = "file://example_cover.png" + cover_uri = "file://example_cover.png" website = "https://dojoengine.org" socials.x = "https://x.com/dojostarknet" "#, ) .unwrap(); - // todo: coverUri -> cover_uri? let world_metadata = dojo_metadata.world.unwrap(); db.update_metadata(&RESOURCE, URI, &world_metadata, &None, &Some(cover_img.to_string())) .await diff --git a/crates/torii/graphql/src/tests/mod.rs b/crates/torii/graphql/src/tests/mod.rs index 584c6713b3..92e0c5bdb0 100644 --- a/crates/torii/graphql/src/tests/mod.rs +++ b/crates/torii/graphql/src/tests/mod.rs @@ -132,7 +132,6 @@ pub struct Social { } #[derive(Deserialize, Debug, PartialEq)] -#[serde(rename_all = "camelCase")] pub struct Content { pub name: Option, pub description: Option, From 371c339c7a145f125f55c384caf1815e52733085 Mon Sep 17 00:00:00 2001 From: gianalarcon Date: Thu, 30 Nov 2023 00:51:30 -0500 Subject: [PATCH 13/14] fix models format --- crates/torii/graphql/src/mapping.rs | 6 +++--- crates/torii/graphql/src/tests/mod.rs | 2 +- examples/spawn-and-move/Scarb.lock | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/torii/graphql/src/mapping.rs b/crates/torii/graphql/src/mapping.rs index 679d3eda92..ac8d7e8eab 100644 --- a/crates/torii/graphql/src/mapping.rs +++ b/crates/torii/graphql/src/mapping.rs @@ -35,15 +35,15 @@ lazy_static! { (Name::new("id"), TypeData::Simple(TypeRef::named(TypeRef::ID))), (Name::new("name"), TypeData::Simple(TypeRef::named(TypeRef::STRING))), ( - Name::new("class_hash"), + Name::new("classHash"), TypeData::Simple(TypeRef::named(Primitive::Felt252(None).to_string())), ), ( - Name::new("transaction_hash"), + Name::new("transactionHash"), TypeData::Simple(TypeRef::named(Primitive::Felt252(None).to_string())), ), ( - Name::new("created_at"), + Name::new("createdAt"), TypeData::Simple(TypeRef::named(GraphqlType::DateTime.to_string())), ), ]); diff --git a/crates/torii/graphql/src/tests/mod.rs b/crates/torii/graphql/src/tests/mod.rs index 92e0c5bdb0..c87d7966ac 100644 --- a/crates/torii/graphql/src/tests/mod.rs +++ b/crates/torii/graphql/src/tests/mod.rs @@ -252,7 +252,7 @@ pub async fn spinup_types_test() -> Result { execute_strategy(&ws, &migration, &account, None).await.unwrap(); // Execute `create` and insert 10 records into storage - let records_contract = "0x2e6254aaf7e47502319f35de01376cece263f9b83afe6169a4b3a76ef47c8a3"; + let records_contract = "0x2753d30656b393ecea156189bf0acf5e1063f3ac978fb5c3cebe7a4570bbc78"; let InvokeTransactionResult { transaction_hash } = account .execute(vec![Call { calldata: vec![FieldElement::from_str("0xa").unwrap()], diff --git a/examples/spawn-and-move/Scarb.lock b/examples/spawn-and-move/Scarb.lock index 24a4548ad3..87ccac7512 100644 --- a/examples/spawn-and-move/Scarb.lock +++ b/examples/spawn-and-move/Scarb.lock @@ -3,14 +3,14 @@ version = 1 [[package]] name = "dojo" -version = "0.3.12" +version = "0.3.13" dependencies = [ "dojo_plugin", ] [[package]] name = "dojo_examples" -version = "0.3.12" +version = "0.3.13" dependencies = [ "dojo", ] From 5fa17bf10345bb50e30785290932e726da39c30b Mon Sep 17 00:00:00 2001 From: gianalarcon Date: Thu, 30 Nov 2023 12:44:17 -0500 Subject: [PATCH 14/14] add dependency for camelCase --- Cargo.lock | 1 + crates/torii/core/src/types.rs | 2 +- crates/torii/graphql/Cargo.toml | 5 +++-- crates/torii/graphql/src/mapping.rs | 14 +++++++------- crates/torii/graphql/src/object/entity.rs | 6 +++--- crates/torii/graphql/src/object/mod.rs | 1 - crates/torii/graphql/src/query/mod.rs | 8 ++++++-- crates/torii/graphql/src/tests/metadata_test.rs | 4 ++-- crates/torii/graphql/src/tests/mod.rs | 4 ++-- 9 files changed, 25 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e83a521a57..0fc697ab14 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8339,6 +8339,7 @@ dependencies = [ "base64 0.21.5", "camino", "chrono", + "convert_case 0.6.0", "dojo-test-utils", "dojo-types", "dojo-world", diff --git a/crates/torii/core/src/types.rs b/crates/torii/core/src/types.rs index 1b84024524..cfca4769bb 100644 --- a/crates/torii/core/src/types.rs +++ b/crates/torii/core/src/types.rs @@ -29,7 +29,7 @@ impl fmt::LowerHex for SQLFieldElement { } #[derive(FromRow, Deserialize, Debug, Clone)] -//#[serde(rename_all = "camelCase")] +#[serde(rename_all = "camelCase")] pub struct Entity { pub id: String, pub keys: String, diff --git a/crates/torii/graphql/Cargo.toml b/crates/torii/graphql/Cargo.toml index 242bf96213..2b7854c59a 100644 --- a/crates/torii/graphql/Cargo.toml +++ b/crates/torii/graphql/Cargo.toml @@ -16,6 +16,7 @@ async-recursion = "1.0.5" async-trait.workspace = true base64.workspace = true chrono.workspace = true +convert_case = "0.6.0" dojo-types = { path = "../../dojo-types" } lazy_static.workspace = true scarb-ui.workspace = true @@ -28,8 +29,8 @@ thiserror.workspace = true tokio-stream = "0.1.11" tokio-util = "0.7.7" tokio.workspace = true -torii-core = { path = "../core" } toml.workspace = true +torii-core = { path = "../core" } tracing.workspace = true url.workspace = true warp.workspace = true @@ -39,7 +40,7 @@ camino.workspace = true dojo-test-utils = { path = "../../dojo-test-utils", features = [ "build-examples" ] } dojo-world = { path = "../../dojo-world" } scarb.workspace = true +serial_test = "2.0.0" sozo = { path = "../../sozo" } starknet-crypto.workspace = true starknet.workspace = true -serial_test = "2.0.0" diff --git a/crates/torii/graphql/src/mapping.rs b/crates/torii/graphql/src/mapping.rs index ac8d7e8eab..64c49aa0ab 100644 --- a/crates/torii/graphql/src/mapping.rs +++ b/crates/torii/graphql/src/mapping.rs @@ -11,13 +11,13 @@ lazy_static! { pub static ref ENTITY_TYPE_MAPPING: TypeMapping = IndexMap::from([ (Name::new("id"), TypeData::Simple(TypeRef::named(TypeRef::ID))), (Name::new("keys"), TypeData::Simple(TypeRef::named_list(TypeRef::STRING))), - (Name::new("event_id"), TypeData::Simple(TypeRef::named(TypeRef::STRING))), + (Name::new("eventId"), TypeData::Simple(TypeRef::named(TypeRef::STRING))), ( - Name::new("created_at"), + Name::new("createdAt"), TypeData::Simple(TypeRef::named(GraphqlType::DateTime.to_string())), ), ( - Name::new("updated_at"), + Name::new("updatedAt"), TypeData::Simple(TypeRef::named(GraphqlType::DateTime.to_string())), ), ]); @@ -107,14 +107,14 @@ lazy_static! { Name::new("content"), TypeData::Nested((TypeRef::named(CONTENT_TYPE_NAME), IndexMap::new())) ), - (Name::new("icon_img"), TypeData::Simple(TypeRef::named(TypeRef::STRING))), - (Name::new("cover_img"), TypeData::Simple(TypeRef::named(TypeRef::STRING))), + (Name::new("iconImg"), TypeData::Simple(TypeRef::named(TypeRef::STRING))), + (Name::new("coverImg"), TypeData::Simple(TypeRef::named(TypeRef::STRING))), ( - Name::new("created_at"), + Name::new("createdAt"), TypeData::Simple(TypeRef::named(GraphqlType::DateTime.to_string())) ), ( - Name::new("updated_at"), + Name::new("updatedAt"), TypeData::Simple(TypeRef::named(GraphqlType::DateTime.to_string())) ), ]); diff --git a/crates/torii/graphql/src/object/entity.rs b/crates/torii/graphql/src/object/entity.rs index cabad6d057..aa19481648 100644 --- a/crates/torii/graphql/src/object/entity.rs +++ b/crates/torii/graphql/src/object/entity.rs @@ -115,13 +115,13 @@ impl EntityObject { IndexMap::from([ (Name::new("id"), Value::from(entity.id)), (Name::new("keys"), Value::from(keys)), - (Name::new("event_id"), Value::from(entity.event_id)), + (Name::new("eventId"), Value::from(entity.event_id)), ( - Name::new("created_at"), + Name::new("createdAt"), Value::from(entity.created_at.format("%Y-%m-%d %H:%M:%S").to_string()), ), ( - Name::new("updated_at"), + Name::new("updatedAt"), Value::from(entity.updated_at.format("%Y-%m-%d %H:%M:%S").to_string()), ), ]) diff --git a/crates/torii/graphql/src/object/mod.rs b/crates/torii/graphql/src/object/mod.rs index 0f57cd6bb2..494449654f 100644 --- a/crates/torii/graphql/src/object/mod.rs +++ b/crates/torii/graphql/src/object/mod.rs @@ -149,7 +149,6 @@ pub trait ObjectTrait: Send + Sync { for (field_name, type_data) in self.type_mapping().clone() { let field = Field::new(field_name.to_string(), type_data.type_ref(), move |ctx| { let field_name = field_name.clone(); - println!("field_name: {}", field_name); FieldFuture::new(async move { match ctx.parent_value.try_to_value()? { diff --git a/crates/torii/graphql/src/query/mod.rs b/crates/torii/graphql/src/query/mod.rs index b256164632..140dcc8caa 100644 --- a/crates/torii/graphql/src/query/mod.rs +++ b/crates/torii/graphql/src/query/mod.rs @@ -2,6 +2,7 @@ use std::str::FromStr; use async_graphql::dynamic::TypeRef; use async_graphql::{Name, Value}; +use convert_case::{Case, Casing}; use dojo_types::primitive::{Primitive, SqlType}; use sqlx::pool::PoolConnection; use sqlx::sqlite::SqliteRow; @@ -144,8 +145,11 @@ fn fetch_value( type_name: &str, is_external: bool, ) -> sqlx::Result { - let column_name = - if is_external { format!("external_{}", field_name) } else { field_name.to_string() }; + let column_name = if is_external { + format!("external_{}", field_name) + } else { + field_name.to_string().to_case(Case::Snake) + }; match Primitive::from_str(type_name) { // fetch boolean diff --git a/crates/torii/graphql/src/tests/metadata_test.rs b/crates/torii/graphql/src/tests/metadata_test.rs index 6977031703..47c16e2949 100644 --- a/crates/torii/graphql/src/tests/metadata_test.rs +++ b/crates/torii/graphql/src/tests/metadata_test.rs @@ -18,8 +18,8 @@ mod tests { cursor node { uri - cover_img - icon_img + coverImg + iconImg content { name description diff --git a/crates/torii/graphql/src/tests/mod.rs b/crates/torii/graphql/src/tests/mod.rs index c87d7966ac..927faf3a0a 100644 --- a/crates/torii/graphql/src/tests/mod.rs +++ b/crates/torii/graphql/src/tests/mod.rs @@ -142,7 +142,7 @@ pub struct Content { } #[derive(Deserialize, Debug)] -//#[serde(rename_all = "camelCase")] +#[serde(rename_all = "camelCase")] pub struct Metadata { pub uri: String, pub icon_img: String, @@ -252,7 +252,7 @@ pub async fn spinup_types_test() -> Result { execute_strategy(&ws, &migration, &account, None).await.unwrap(); // Execute `create` and insert 10 records into storage - let records_contract = "0x2753d30656b393ecea156189bf0acf5e1063f3ac978fb5c3cebe7a4570bbc78"; + let records_contract = "0x2e6254aaf7e47502319f35de01376cece263f9b83afe6169a4b3a76ef47c8a3"; let InvokeTransactionResult { transaction_hash } = account .execute(vec![Call { calldata: vec![FieldElement::from_str("0xa").unwrap()],