Skip to content

Commit

Permalink
feat(torii-graphql): subscriptions for tokens and token balances (#2999)
Browse files Browse the repository at this point in the history
* feat(torii-graphql): subscriptions for tokens and token balances

* token balance sub

* finish up token balances subscription and start token updte

* fmt

* rename tokenreigstered to token updated

* fix subscriptions and add tokens resolvers

* fix token id subscription

* fmt

* fix unique resolver
  • Loading branch information
Larkooo authored Feb 11, 2025
1 parent 6577d34 commit b8e5ebb
Show file tree
Hide file tree
Showing 8 changed files with 594 additions and 24 deletions.
2 changes: 1 addition & 1 deletion crates/torii/graphql/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub const MODEL_ORDER_TYPE_NAME: &str = "World__ModelOrder";
pub const MODEL_ORDER_FIELD_TYPE_NAME: &str = "World__ModelOrderField";
pub const TOKEN_BALANCE_TYPE_NAME: &str = "Token__Balance";
pub const TOKEN_TRANSFER_TYPE_NAME: &str = "Token__Transfer";
pub const TOKEN_TYPE_NAME: &str = "ERC__Token";
pub const TOKEN_UNION_TYPE_NAME: &str = "ERC__Token";
// pub const ERC721_METADATA_TYPE_NAME: &str = "ERC721__Metadata";

pub const ERC20_TYPE_NAME: &str = "ERC20__Token";
Expand Down
10 changes: 7 additions & 3 deletions crates/torii/graphql/src/mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use async_graphql::Name;
use dojo_types::primitive::Primitive;
use lazy_static::lazy_static;

use crate::constants::{CONTENT_TYPE_NAME, SOCIAL_TYPE_NAME, TOKEN_TYPE_NAME};
use crate::constants::{CONTENT_TYPE_NAME, SOCIAL_TYPE_NAME, TOKEN_UNION_TYPE_NAME};
use crate::types::{GraphqlType, TypeData, TypeMapping};

lazy_static! {
Expand Down Expand Up @@ -146,14 +146,14 @@ lazy_static! {
]);

pub static ref TOKEN_BALANCE_TYPE_MAPPING: TypeMapping = IndexMap::from([
(Name::new("tokenMetadata"), TypeData::Nested((TypeRef::named_nn(TOKEN_TYPE_NAME), IndexMap::new()))),
(Name::new("tokenMetadata"), TypeData::Nested((TypeRef::named_nn(TOKEN_UNION_TYPE_NAME), IndexMap::new()))),
]);

pub static ref TOKEN_TRANSFER_TYPE_MAPPING: TypeMapping = IndexMap::from([
(Name::new("from"), TypeData::Simple(TypeRef::named_nn(TypeRef::STRING))),
(Name::new("to"), TypeData::Simple(TypeRef::named_nn(TypeRef::STRING))),
(Name::new("executedAt"), TypeData::Simple(TypeRef::named_nn(TypeRef::STRING))),
(Name::new("tokenMetadata"), TypeData::Nested((TypeRef::named_nn(TOKEN_TYPE_NAME), IndexMap::new()))),
(Name::new("tokenMetadata"), TypeData::Nested((TypeRef::named_nn(TOKEN_UNION_TYPE_NAME), IndexMap::new()))),
(Name::new("transactionHash"), TypeData::Simple(TypeRef::named_nn(TypeRef::STRING))),
]);

Expand Down Expand Up @@ -190,4 +190,8 @@ lazy_static! {
TypeData::Simple(TypeRef::named_nn(GraphqlType::DateTime.to_string())),
),
]);

pub static ref TOKEN_TYPE_MAPPING: TypeMapping = IndexMap::from([
(Name::new("tokenMetadata"), TypeData::Nested((TypeRef::named_nn(TOKEN_UNION_TYPE_NAME), IndexMap::new()))),
]);
}
2 changes: 1 addition & 1 deletion crates/torii/graphql/src/object/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl BasicObject for ConnectionObject {
}

pub fn parse_connection_arguments(ctx: &ResolverContext<'_>) -> Result<ConnectionArguments, Error> {
let first = extract::<u64>(ctx.args.as_index_map(), "first").ok();
let first: Option<u64> = extract::<u64>(ctx.args.as_index_map(), "first").ok();
let last = extract::<u64>(ctx.args.as_index_map(), "last").ok();
let after = extract::<String>(ctx.args.as_index_map(), "after").ok();
let before = extract::<String>(ctx.args.as_index_map(), "before").ok();
Expand Down
Loading

0 comments on commit b8e5ebb

Please sign in to comment.