Skip to content

Commit

Permalink
update cairotype to primitive
Browse files Browse the repository at this point in the history
  • Loading branch information
broody committed Oct 2, 2023
1 parent 1de16d3 commit 02918b7
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 15 deletions.
6 changes: 3 additions & 3 deletions crates/torii/graphql/src/object/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use async_graphql::dynamic::{
Field, FieldFuture, InputValue, SubscriptionField, SubscriptionFieldFuture, TypeRef,
};
use async_graphql::{Name, Value};
use dojo_types::core::CairoType;
use indexmap::IndexMap;
use dojo_types::primitive::Primitive;
use sqlx::{Pool, Sqlite};
use tokio_stream::StreamExt;
use torii_core::simple_broker::SimpleBroker;
Expand All @@ -28,11 +28,11 @@ impl Default for ModelObject {
(Name::new("name"), TypeData::Simple(TypeRef::named(TypeRef::STRING))),
(
Name::new("classHash"),
TypeData::Simple(TypeRef::named(CairoType::Felt252.to_string())),
TypeData::Simple(TypeRef::named("felt252")),
),
(
Name::new("transactionHash"),
TypeData::Simple(TypeRef::named(CairoType::Felt252.to_string())),
TypeData::Simple(TypeRef::named("felt252")),
),
(
Name::new("createdAt"),
Expand Down
6 changes: 3 additions & 3 deletions crates/torii/graphql/src/object/model_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::str::FromStr;
use async_graphql::dynamic::{Enum, Field, FieldFuture, InputObject, Object, TypeRef};
use async_graphql::{Error, Name, Value};
use chrono::{DateTime, Utc};
use dojo_types::core::CairoType;
use dojo_types::primitive::Primitive;
use serde::Deserialize;
use sqlx::pool::PoolConnection;
use sqlx::sqlite::SqliteRow;
Expand Down Expand Up @@ -358,9 +358,9 @@ fn value_mapping_from_row(row: &SqliteRow, types: &TypeMapping) -> sqlx::Result<
}

fn fetch_value(row: &SqliteRow, column_name: &str, field_type: &str) -> sqlx::Result<Value> {
match CairoType::from_str(field_type) {
match Primitive::from_str(field_type) {
// fetch boolean
Ok(CairoType::Bool) => {
Ok(Primitive::Bool(_)) => {
Ok(Value::from(matches!(row.try_get::<i64, &str>(column_name)?, BOOLEAN_TRUE)))
}
// fetch integer
Expand Down
5 changes: 2 additions & 3 deletions crates/torii/graphql/src/object/system.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use async_graphql::dynamic::{Field, FieldFuture, FieldValue, InputValue, TypeRef};
use async_graphql::{Name, Value};
use chrono::{DateTime, Utc};
use dojo_types::core::CairoType;
use indexmap::IndexMap;
use serde::Deserialize;
use sqlx::{FromRow, Pool, Sqlite};
Expand Down Expand Up @@ -36,11 +35,11 @@ impl Default for SystemObject {
(Name::new("name"), TypeData::Simple(TypeRef::named(TypeRef::STRING))),
(
Name::new("classHash"),
TypeData::Simple(TypeRef::named(CairoType::Felt252.to_string())),
TypeData::Simple(TypeRef::named("felt252")),
),
(
Name::new("transactionHash"),
TypeData::Simple(TypeRef::named(CairoType::Felt252.to_string())),
TypeData::Simple(TypeRef::named("felt252")),
),
(
Name::new("createdAt"),
Expand Down
6 changes: 3 additions & 3 deletions crates/torii/graphql/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::str::FromStr;

use async_graphql::dynamic::TypeRef;
use async_graphql::Name;
use dojo_types::core::CairoType;
use dojo_types::primitive::Primitive;
use sqlx::pool::PoolConnection;
use sqlx::sqlite::SqliteRow;
use sqlx::{FromRow, QueryBuilder, Result, Sqlite};
Expand Down Expand Up @@ -94,7 +94,7 @@ pub async fn type_mapping_query(
let type_mapping: TypeMapping = root_members
.iter()
.map(|member| {
let type_data = match CairoType::from_str(&member.ty) {
let type_data = match Primitive::from_str(&member.ty) {
Ok(_) => TypeData::Simple(TypeRef::named(member.ty.clone())),
_ => parse_nested_type(&member.model_id, &member.ty, &nested_members),
};
Expand All @@ -116,7 +116,7 @@ fn parse_nested_type(
.filter_map(|member| {
// search for target type in nested members
if target_id == member.model_id && member.id.ends_with(target_type) {
let type_data = match CairoType::from_str(&member.ty) {
let type_data = match Primitive::from_str(&member.ty) {
Ok(_) => TypeData::Simple(TypeRef::named(member.ty.clone())),
_ => parse_nested_type(&member.model_id, &member.ty, nested_members),
};
Expand Down
6 changes: 3 additions & 3 deletions crates/torii/graphql/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use async_graphql::dynamic::TypeRef;
use async_graphql::{Name, Value};
use dojo_types::core::CairoType;
use dojo_types::primitive::Primitive;
use indexmap::IndexMap;
use strum::IntoEnumIterator;
use strum_macros::{AsRefStr, Display, EnumIter, EnumString};
Expand Down Expand Up @@ -44,7 +44,7 @@ impl TypeData {

#[derive(Debug)]
pub enum ScalarType {
Cairo(CairoType),
Cairo(Primitive),
Torii(GraphqlType),
}

Expand All @@ -57,7 +57,7 @@ pub enum GraphqlType {

impl ScalarType {
pub fn all() -> Vec<String> {
CairoType::iter()
Primitive::iter()
.map(|ty| ty.to_string())
.chain(GraphqlType::iter().map(|ty| ty.to_string()))
.collect()
Expand Down

0 comments on commit 02918b7

Please sign in to comment.