diff --git a/crates/torii/graphql/src/mapping.rs b/crates/torii/graphql/src/mapping.rs index 190cbf4b62..02bbd5618d 100644 --- a/crates/torii/graphql/src/mapping.rs +++ b/crates/torii/graphql/src/mapping.rs @@ -100,8 +100,8 @@ lazy_static! { ), ]); pub static ref PAGE_INFO_TYPE_MAPPING: TypeMapping = TypeMapping::from([ - (Name::new("hasPreviousPage"), TypeData::Simple(TypeRef::named(TypeRef::BOOLEAN))), - (Name::new("hasNextPage"), TypeData::Simple(TypeRef::named(TypeRef::BOOLEAN))), + (Name::new("hasPreviousPage"), TypeData::Simple(TypeRef::named_nn(TypeRef::BOOLEAN))), + (Name::new("hasNextPage"), TypeData::Simple(TypeRef::named_nn(TypeRef::BOOLEAN))), ( Name::new("startCursor"), TypeData::Simple(TypeRef::named(GraphqlType::Cursor.to_string())), @@ -160,7 +160,7 @@ lazy_static! { pub static ref ERC20_TOKEN_TYPE_MAPPING: TypeMapping = IndexMap::from([ (Name::new("name"), TypeData::Simple(TypeRef::named_nn(TypeRef::STRING))), (Name::new("symbol"), TypeData::Simple(TypeRef::named_nn(TypeRef::STRING))), - (Name::new("decimals"), TypeData::Simple(TypeRef::named_nn(TypeRef::STRING))), + (Name::new("decimals"), TypeData::Simple(TypeRef::named_nn(TypeRef::INT))), (Name::new("contractAddress"), TypeData::Simple(TypeRef::named_nn(TypeRef::STRING))), (Name::new("amount"), TypeData::Simple(TypeRef::named_nn(TypeRef::STRING))), ]); @@ -171,9 +171,9 @@ lazy_static! { (Name::new("tokenId"), TypeData::Simple(TypeRef::named_nn(TypeRef::STRING))), (Name::new("contractAddress"), TypeData::Simple(TypeRef::named_nn(TypeRef::STRING))), (Name::new("metadata"), TypeData::Simple(TypeRef::named_nn(TypeRef::STRING))), - (Name::new("metadataName"), TypeData::Simple(TypeRef::named_nn(TypeRef::STRING))), - (Name::new("metadataDescription"), TypeData::Simple(TypeRef::named_nn(TypeRef::STRING))), - (Name::new("metadataAttributes"), TypeData::Simple(TypeRef::named_nn(TypeRef::STRING))), + (Name::new("metadataName"), TypeData::Simple(TypeRef::named(TypeRef::STRING))), + (Name::new("metadataDescription"), TypeData::Simple(TypeRef::named(TypeRef::STRING))), + (Name::new("metadataAttributes"), TypeData::Simple(TypeRef::named(TypeRef::STRING))), (Name::new("imagePath"), TypeData::Simple(TypeRef::named_nn(TypeRef::STRING))), ]); diff --git a/crates/torii/graphql/src/object/erc/token_balance.rs b/crates/torii/graphql/src/object/erc/token_balance.rs index 7fdcca4fe5..ab018822e2 100644 --- a/crates/torii/graphql/src/object/erc/token_balance.rs +++ b/crates/torii/graphql/src/object/erc/token_balance.rs @@ -234,8 +234,14 @@ fn token_balances_connection_output<'a>( let token_id = row.token_id.split(':').collect::>(); assert!(token_id.len() == 2); + // skip the token if metadata is null + if row.metadata.is_none() { + continue; + } + let metadata_str = row.metadata.as_ref().unwrap(); + let metadata: serde_json::Value = - serde_json::from_str(&row.metadata).expect("metadata is always json"); + serde_json::from_str(metadata_str).expect("metadata is always json"); let metadata_name = metadata.get("name").map(|v| v.to_string().trim_matches('"').to_string()); let metadata_description = metadata @@ -248,7 +254,7 @@ fn token_balances_connection_output<'a>( let token_metadata = Erc721Token { name: row.name, - metadata: row.metadata, + metadata: metadata_str.to_owned(), contract_address: row.contract_address, symbol: row.symbol, token_id: token_id[1].to_string(), @@ -295,5 +301,5 @@ struct BalanceQueryResultRaw { pub token_id: String, pub balance: String, pub contract_type: String, - pub metadata: String, + pub metadata: Option, } diff --git a/crates/torii/graphql/src/object/erc/token_transfer.rs b/crates/torii/graphql/src/object/erc/token_transfer.rs index 1441937c2e..0053db28dc 100644 --- a/crates/torii/graphql/src/object/erc/token_transfer.rs +++ b/crates/torii/graphql/src/object/erc/token_transfer.rs @@ -263,8 +263,14 @@ fn token_transfers_connection_output<'a>( let token_id = row.token_id.split(':').collect::>(); assert!(token_id.len() == 2); + // skip the token if metadata is null + if row.metadata.is_none() { + continue; + } + + let metadata_str = row.metadata.as_ref().unwrap(); let metadata: serde_json::Value = - serde_json::from_str(&row.metadata).expect("metadata is always json"); + serde_json::from_str(metadata_str).expect("metadata is always json"); let metadata_name = metadata.get("name").map(|v| v.to_string().trim_matches('"').to_string()); let metadata_description = metadata @@ -277,7 +283,7 @@ fn token_transfers_connection_output<'a>( let token_metadata = ErcTokenType::Erc721(Erc721Token { name: row.name, - metadata: row.metadata, + metadata: metadata_str.to_owned(), contract_address: row.contract_address, symbol: row.symbol, token_id: token_id[1].to_string(), @@ -333,7 +339,7 @@ struct TransferQueryResultRaw { pub symbol: String, pub decimals: u8, pub contract_type: String, - pub metadata: String, + pub metadata: Option, } #[derive(Debug, Clone)]