Skip to content

Commit

Permalink
Fix torii core remove extra quotes on enum options (#1160)
Browse files Browse the repository at this point in the history
  • Loading branch information
broody authored Nov 6, 2023
1 parent 008b9e5 commit 829f2bd
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 20 deletions.
12 changes: 8 additions & 4 deletions crates/torii/core/src/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,10 +413,14 @@ impl Sql {
(external_{name});"
));

options = Some(Argument::String(format!(
r#""{}""#,
e.options.iter().map(|c| c.name.clone()).collect::<Vec<_>>().join(",")
)));
options = Some(Argument::String(
e.options
.iter()
.map(|c| c.name.clone())
.collect::<Vec<_>>()
.join(",")
.to_string(),
));
}

let statement = "INSERT OR IGNORE INTO model_members (id, model_id, model_idx, \
Expand Down
1 change: 1 addition & 0 deletions crates/torii/graphql/src/tests/entities_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ mod tests {
models {{
... on Record {{
__typename
depth
record_id
type_u8
type_u16
Expand Down
7 changes: 4 additions & 3 deletions crates/torii/graphql/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ pub struct Position {
#[derive(Deserialize, Debug, PartialEq)]
pub struct Record {
pub __typename: String,
pub depth: String,
pub record_id: u32,
pub type_u8: u8,
pub type_u16: u16,
Expand All @@ -98,7 +99,7 @@ pub struct Record {
#[derive(Deserialize, Debug, PartialEq)]
pub struct Nested {
pub __typename: String,
pub depth: u8,
pub depth: String,
pub type_number: u8,
pub type_string: String,
pub type_nested_more: NestedMore,
Expand All @@ -107,7 +108,7 @@ pub struct Nested {
#[derive(Deserialize, Debug, PartialEq)]
pub struct NestedMore {
pub __typename: String,
pub depth: u8,
pub depth: String,
pub type_number: u8,
pub type_string: String,
pub type_nested_more_more: NestedMoreMore,
Expand All @@ -116,7 +117,7 @@ pub struct NestedMore {
#[derive(Deserialize, Debug, PartialEq)]
pub struct NestedMoreMore {
pub __typename: String,
pub depth: u8,
pub depth: String,
pub type_number: u8,
pub type_string: String,
}
Expand Down
8 changes: 5 additions & 3 deletions crates/torii/graphql/src/tests/models_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ mod tests {
node {{
__typename
record_id
depth
type_u8
type_u16
type_u32
Expand Down Expand Up @@ -87,9 +88,10 @@ mod tests {
assert_eq!(&record.node.__typename, "Record");
assert_eq!(&entity.model_names, "Record");
assert_eq!(entity.keys.clone().unwrap(), vec!["0x0"]);
assert_eq!(nested.depth, 1);
assert_eq!(nested_more.depth, 2);
assert_eq!(nested_more_more.depth, 3);
assert_eq!(record.node.depth, "Zero");
assert_eq!(nested.depth, "One");
assert_eq!(nested_more.depth, "Two");
assert_eq!(nested_more_more.depth, "Three");

// *** WHERE FILTER TESTING ***

Expand Down
4 changes: 2 additions & 2 deletions crates/torii/graphql/src/tests/types-test/Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ version = 1

[[package]]
name = "dojo"
version = "0.3.3"
version = "0.3.5"
dependencies = [
"dojo_plugin",
]

[[package]]
name = "dojo_plugin"
version = "0.3.3"
version = "0.3.5"

[[package]]
name = "types_test"
Expand Down
9 changes: 5 additions & 4 deletions crates/torii/graphql/src/tests/types-test/src/contracts.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ trait IRecords<TContractState> {
#[dojo::contract]
mod records {
use starknet::{ContractAddress, get_caller_address};
use types_test::models::{Record, Subrecord, Nested, NestedMore, NestedMoreMore};
use types_test::models::{Record, Subrecord, Nested, NestedMore, NestedMoreMore, Depth};
use types_test::{seed, random};
use super::IRecords;

Expand Down Expand Up @@ -54,6 +54,7 @@ mod records {
(
Record {
record_id,
depth: Depth::Zero,
type_u8: record_idx.into(),
type_u16: record_idx.into(),
type_u32: record_idx.into(),
Expand All @@ -69,15 +70,15 @@ mod records {
type_class_hash: type_felt.try_into().unwrap(),
type_contract_address: type_felt.try_into().unwrap(),
type_nested: Nested {
depth: 1,
depth: Depth::One,
type_number: record_idx.into(),
type_string: type_felt,
type_nested_more: NestedMore {
depth: 2,
depth: Depth::Two,
type_number: record_idx.into(),
type_string: type_felt,
type_nested_more_more: NestedMoreMore {
depth: 3,
depth: Depth::Three,
type_number: record_idx.into(),
type_string: type_felt,
}
Expand Down
28 changes: 24 additions & 4 deletions crates/torii/graphql/src/tests/types-test/src/models.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use starknet::{ContractAddress, ClassHash};
struct Record {
#[key]
record_id: u32,
depth: Depth,
type_u8: u8,
type_u16: u16,
type_u32: u32,
Expand All @@ -22,23 +23,23 @@ struct Record {

#[derive(Copy, Drop, Serde, Introspect)]
struct Nested {
depth: u8,
depth: Depth,
type_number: u8,
type_string: felt252,
type_nested_more: NestedMore,
}

#[derive(Copy, Drop, Serde, Introspect)]
struct NestedMore {
depth: u8,
depth: Depth,
type_number: u8,
type_string: felt252,
type_nested_more_more: NestedMoreMore,
}

#[derive(Copy, Drop, Serde, Introspect)]
struct NestedMoreMore {
depth: u8,
depth: Depth,
type_number: u8,
type_string: felt252,
}
Expand All @@ -53,6 +54,25 @@ struct Subrecord {
random_u8: u8,
}

#[derive(Serde, Copy, Drop, Introspect)]
enum Depth {
Zero: (),
One: (),
Two: (),
Three: (),
}

impl DepthIntoFelt252 of Into<Depth, felt252> {
fn into(self: Depth) -> felt252 {
match self {
Depth::Zero => 0,
Depth::One => 1,
Depth::Two => 2,
Depth::Three => 3,
}
}
}

#[derive(Model, Copy, Drop, Serde)]
struct FatModel {
#[key]
Expand Down Expand Up @@ -313,4 +333,4 @@ struct FatModel {
a253: u256,
a254: u256,
a255: u256,
}
}

0 comments on commit 829f2bd

Please sign in to comment.