Skip to content

Commit

Permalink
refactor(torii/graphql): use camelCase in graphql to be more consistent
Browse files Browse the repository at this point in the history
commit-id:108ca77e
  • Loading branch information
lambda-0x committed Oct 11, 2024
1 parent fd1e0f9 commit 798ff06
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
10 changes: 5 additions & 5 deletions crates/torii/graphql/src/mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,23 +148,23 @@ lazy_static! {
pub static ref ERC_BALANCE_TYPE_MAPPING: TypeMapping = IndexMap::from([
(Name::new("balance"), TypeData::Simple(TypeRef::named(TypeRef::STRING))),
(Name::new("type"), TypeData::Simple(TypeRef::named(TypeRef::STRING))),
(Name::new("token_metadata"), TypeData::Simple(TypeRef::named(ERC_TOKEN_TYPE_NAME))),
(Name::new("tokenMetadata"), TypeData::Simple(TypeRef::named(ERC_TOKEN_TYPE_NAME))),
]);

pub static ref ERC_TRANSFER_TYPE_MAPPING: TypeMapping = IndexMap::from([
(Name::new("from"), TypeData::Simple(TypeRef::named(TypeRef::STRING))),
(Name::new("to"), TypeData::Simple(TypeRef::named(TypeRef::STRING))),
(Name::new("amount"), TypeData::Simple(TypeRef::named(TypeRef::STRING))),
(Name::new("type"), TypeData::Simple(TypeRef::named(TypeRef::STRING))),
(Name::new("executed_at"), TypeData::Simple(TypeRef::named(TypeRef::STRING))),
(Name::new("token_metadata"), TypeData::Simple(TypeRef::named(ERC_TOKEN_TYPE_NAME))),
(Name::new("executedAt"), TypeData::Simple(TypeRef::named(TypeRef::STRING))),
(Name::new("tokenMetadata"), TypeData::Simple(TypeRef::named(ERC_TOKEN_TYPE_NAME))),
]);

pub static ref ERC_TOKEN_TYPE_MAPPING: TypeMapping = IndexMap::from([
(Name::new("name"), TypeData::Simple(TypeRef::named(TypeRef::STRING))),
(Name::new("symbol"), TypeData::Simple(TypeRef::named(TypeRef::STRING))),
(Name::new("token_id"), TypeData::Simple(TypeRef::named(TypeRef::STRING))),
(Name::new("tokenId"), TypeData::Simple(TypeRef::named(TypeRef::STRING))),
(Name::new("decimals"), TypeData::Simple(TypeRef::named(TypeRef::STRING))),
(Name::new("contract_address"), TypeData::Simple(TypeRef::named(TypeRef::STRING))),
(Name::new("contractAddress"), TypeData::Simple(TypeRef::named(TypeRef::STRING))),
]);
}
12 changes: 6 additions & 6 deletions crates/torii/graphql/src/object/erc/erc_balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ async fn fetch_erc_balances(
(Name::new("name"), Value::String(row.name)),
(Name::new("symbol"), Value::String(row.symbol)),
// for erc20 there is no token_id
(Name::new("token_id"), Value::Null),
(Name::new("tokenId"), Value::Null),

Check warning on line 83 in crates/torii/graphql/src/object/erc/erc_balance.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/graphql/src/object/erc/erc_balance.rs#L83

Added line #L83 was not covered by tests
(Name::new("decimals"), Value::String(row.decimals.to_string())),
(Name::new("contract_address"), Value::String(row.contract_address.clone())),
(Name::new("contractAddress"), Value::String(row.contract_address.clone())),

Check warning on line 85 in crates/torii/graphql/src/object/erc/erc_balance.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/graphql/src/object/erc/erc_balance.rs#L85

Added line #L85 was not covered by tests
]));

Value::Object(ValueMapping::from([
(Name::new("balance"), Value::String(row.balance)),
(Name::new("type"), Value::String(row.contract_type)),
(Name::new("token_metadata"), token_metadata),
(Name::new("tokenMetadata"), token_metadata),

Check warning on line 91 in crates/torii/graphql/src/object/erc/erc_balance.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/graphql/src/object/erc/erc_balance.rs#L91

Added line #L91 was not covered by tests
]))
}
"erc721" => {
Expand All @@ -97,17 +97,17 @@ async fn fetch_erc_balances(
assert!(token_id.len() == 2);

let token_metadata = Value::Object(ValueMapping::from([
(Name::new("contract_address"), Value::String(row.contract_address.clone())),
(Name::new("contractAddress"), Value::String(row.contract_address.clone())),

Check warning on line 100 in crates/torii/graphql/src/object/erc/erc_balance.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/graphql/src/object/erc/erc_balance.rs#L100

Added line #L100 was not covered by tests
(Name::new("name"), Value::String(row.name)),
(Name::new("symbol"), Value::String(row.symbol)),
(Name::new("token_id"), Value::String(token_id[1].to_string())),
(Name::new("tokenId"), Value::String(token_id[1].to_string())),

Check warning on line 103 in crates/torii/graphql/src/object/erc/erc_balance.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/graphql/src/object/erc/erc_balance.rs#L103

Added line #L103 was not covered by tests
(Name::new("decimals"), Value::String(row.decimals.to_string())),
]));

Value::Object(ValueMapping::from([
(Name::new("balance"), Value::String(row.balance)),
(Name::new("type"), Value::String(row.contract_type)),
(Name::new("token_metadata"), token_metadata),
(Name::new("tokenMetadata"), token_metadata),

Check warning on line 110 in crates/torii/graphql/src/object/erc/erc_balance.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/graphql/src/object/erc/erc_balance.rs#L110

Added line #L110 was not covered by tests
]))
}
_ => {
Expand Down
22 changes: 11 additions & 11 deletions crates/torii/graphql/src/object/erc/erc_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,46 +103,46 @@ LIMIT {};
for row in rows {
let row = TransferQueryResultRaw::from_row(&row)?;

let transfer_value = match row.contract_type.as_str() {
"ERC20" | "Erc20" | "erc20" => {
let transfer_value = match row.contract_type.to_lowercase().as_str() {
"erc20" => {

Check warning on line 107 in crates/torii/graphql/src/object/erc/erc_transfer.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/graphql/src/object/erc/erc_transfer.rs#L106-L107

Added lines #L106 - L107 were not covered by tests
let token_metadata = Value::Object(ValueMapping::from([
(Name::new("name"), Value::String(row.name)),
(Name::new("symbol"), Value::String(row.symbol)),
// for erc20 there is no token_id
(Name::new("token_id"), Value::Null),
(Name::new("tokenId"), Value::Null),

Check warning on line 112 in crates/torii/graphql/src/object/erc/erc_transfer.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/graphql/src/object/erc/erc_transfer.rs#L112

Added line #L112 was not covered by tests
(Name::new("decimals"), Value::String(row.decimals.to_string())),
(Name::new("contract_address"), Value::String(row.contract_address.clone())),
(Name::new("contractAddress"), Value::String(row.contract_address.clone())),

Check warning on line 114 in crates/torii/graphql/src/object/erc/erc_transfer.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/graphql/src/object/erc/erc_transfer.rs#L114

Added line #L114 was not covered by tests
]));

Value::Object(ValueMapping::from([
(Name::new("from"), Value::String(row.from_address)),
(Name::new("to"), Value::String(row.to_address)),
(Name::new("amount"), Value::String(row.amount)),
(Name::new("type"), Value::String(row.contract_type)),
(Name::new("executed_at"), Value::String(row.executed_at)),
(Name::new("token_metadata"), token_metadata),
(Name::new("executedAt"), Value::String(row.executed_at)),
(Name::new("tokenMetadata"), token_metadata),

Check warning on line 123 in crates/torii/graphql/src/object/erc/erc_transfer.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/graphql/src/object/erc/erc_transfer.rs#L122-L123

Added lines #L122 - L123 were not covered by tests
]))
}
"ERC721" | "Erc721" | "erc721" => {
"erc721" => {

Check warning on line 126 in crates/torii/graphql/src/object/erc/erc_transfer.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/graphql/src/object/erc/erc_transfer.rs#L126

Added line #L126 was not covered by tests
// contract_address:token_id
let token_id = row.token_id.split(':').collect::<Vec<&str>>();
assert!(token_id.len() == 2);

let token_metadata = Value::Object(ValueMapping::from([
(Name::new("name"), Value::String(row.name)),
(Name::new("symbol"), Value::String(row.symbol)),
(Name::new("token_id"), Value::String(token_id[1].to_string())),
(Name::new("tokenId"), Value::String(token_id[1].to_string())),

Check warning on line 134 in crates/torii/graphql/src/object/erc/erc_transfer.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/graphql/src/object/erc/erc_transfer.rs#L134

Added line #L134 was not covered by tests
(Name::new("decimals"), Value::String(row.decimals.to_string())),
(Name::new("contract_address"), Value::String(row.contract_address.clone())),
(Name::new("contractAddress"), Value::String(row.contract_address.clone())),

Check warning on line 136 in crates/torii/graphql/src/object/erc/erc_transfer.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/graphql/src/object/erc/erc_transfer.rs#L136

Added line #L136 was not covered by tests
]));

Value::Object(ValueMapping::from([
(Name::new("from"), Value::String(row.from_address)),
(Name::new("to"), Value::String(row.to_address)),
(Name::new("amount"), Value::String(row.amount)),
(Name::new("type"), Value::String(row.contract_type)),
(Name::new("executed_at"), Value::String(row.executed_at)),
(Name::new("token_metadata"), token_metadata),
(Name::new("executedAt"), Value::String(row.executed_at)),
(Name::new("tokenMetadata"), token_metadata),

Check warning on line 145 in crates/torii/graphql/src/object/erc/erc_transfer.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/graphql/src/object/erc/erc_transfer.rs#L144-L145

Added lines #L144 - L145 were not covered by tests
]))
}
_ => {
Expand Down

0 comments on commit 798ff06

Please sign in to comment.