Skip to content

Commit

Permalink
Change model query field to camel case (dojoengine#1410)
Browse files Browse the repository at this point in the history
  • Loading branch information
JunichiSugiura authored Jan 10, 2024
1 parent 36e5853 commit 042d46b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion crates/torii/graphql/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use anyhow::Result;
use async_graphql::dynamic::{
Field, Object, Scalar, Schema, Subscription, SubscriptionField, Union,
};
use convert_case::{Case, Casing};
use sqlx::SqlitePool;
use torii_core::types::Model;

Expand Down Expand Up @@ -126,7 +127,7 @@ async fn build_objects(pool: &SqlitePool) -> Result<(Vec<Box<dyn ObjectTrait>>,
let type_mapping = type_mapping_query(&mut conn, &model.id).await?;

if !type_mapping.is_empty() {
let field_name = model.name.to_lowercase();
let field_name = model.name.to_case(Case::Camel);
let type_name = model.name;

union = union.possible_type(&type_name);
Expand Down
2 changes: 1 addition & 1 deletion crates/torii/graphql/src/tests/models_ordering_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ mod tests {
createdAt
}}
}}
pageInfo{{
pageInfo {{
startCursor
hasPreviousPage
hasNextPage
Expand Down
17 changes: 17 additions & 0 deletions crates/torii/graphql/src/tests/models_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,23 @@ mod tests {
let connection: Connection<Record> = serde_json::from_value(records).unwrap();
assert_eq!(connection.edges.len(), 0);

let result = run_graphql_query(
&schema,
r#"
{
recordSiblingModels {
edges {
node {
__typename
}
}
}
}
"#,
)
.await;
assert!(result.get("recordSiblingModels").is_some());

Ok(())
}
}

0 comments on commit 042d46b

Please sign in to comment.