Skip to content

Commit

Permalink
Change model query field to camel case
Browse files Browse the repository at this point in the history
  • Loading branch information
JunichiSugiura committed Jan 9, 2024
1 parent 36e5853 commit 2682ca1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
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
15 changes: 15 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,21 @@ mod tests {
let connection: Connection<Record> = serde_json::from_value(records).unwrap();
assert_eq!(connection.edges.len(), 0);

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

Ok(())
}
}

0 comments on commit 2682ca1

Please sign in to comment.