diff --git a/examples/sqlite/src/query_root.rs b/examples/sqlite/src/query_root.rs index d149f542..3e5278db 100644 --- a/examples/sqlite/src/query_root.rs +++ b/examples/sqlite/src/query_root.rs @@ -11,7 +11,7 @@ pub fn schema( depth: Option, complexity: Option, ) -> Result { - let builder = seaography::register_entities!( + let builder = seaography::register_related_entities!( Builder::new(&CONTEXT), &CONTEXT, [ diff --git a/generator/src/writer.rs b/generator/src/writer.rs index edc263ab..f99e0f12 100644 --- a/generator/src/writer.rs +++ b/generator/src/writer.rs @@ -96,7 +96,7 @@ pub fn generate_query_root>(entities_path: &P) -> TokenStream { depth: Option, complexity: Option, ) -> Result { - let builder = seaography::register_entities!(Builder::new(&CONTEXT), &CONTEXT, [ + let builder = seaography::register_related_entities!(Builder::new(&CONTEXT), &CONTEXT, [ #(#entities,)* ]); diff --git a/src/builder.rs b/src/builder.rs index 2f29179d..b22e3892 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -244,27 +244,33 @@ pub trait RelationBuilder { } #[macro_export] -macro_rules! register_entity { - ($builder:expr, $context:expr, $module_path:ident) => {{ - use sea_orm::Iterable; - +macro_rules! register_related_entity { + ($builder:expr, $module_path:ident) => { $builder.register_entity::<$module_path::Entity>( - $module_path::RelatedEntity::iter() - .map(|rel| seaography::RelationBuilder::get_relation(&rel, $context)) + <$module_path::RelatedEntity as sea_orm::Iterable>::iter() + .map(|rel| seaography::RelationBuilder::get_relation(&rel, $builder.context)) .collect(), ); - }}; + }; } #[macro_export] -macro_rules! register_entities { - ($builder:expr, $context:expr, [$($module_paths:ident),+ $(,)?]) => {{ - { - let mut builder = $builder; +macro_rules! register_related_entities { + ($builder:expr, [$($module_paths:ident),+ $(,)?]) => { + $(seaography::register_related_entity!($builder, $module_paths);)* + }; +} - $(seaography::register_entity!(builder, $context, $module_paths);)* +#[macro_export] +macro_rules! register_entity { + ($builder:expr, $module_path:ident) => { + $builder.register_entity::<$module_path::Entity>(vec![]); + }; +} - builder - } - }}; +#[macro_export] +macro_rules! register_entities { + ($builder:expr, [$($module_paths:ident),+ $(,)?]) => { + $(seaography::register_entity!($builder, $module_paths);)* + }; } diff --git a/src/inputs/active_enum_filter_input.rs b/src/inputs/active_enum_filter_input.rs index 5fc2ed4a..7924024e 100644 --- a/src/inputs/active_enum_filter_input.rs +++ b/src/inputs/active_enum_filter_input.rs @@ -1,6 +1,6 @@ use async_graphql::dynamic::{InputObject, InputValue, ObjectAccessor, TypeRef}; use heck::ToUpperCamelCase; -use sea_orm::{ActiveEnum, ColumnTrait, Condition, DynIden, Iden}; +use sea_orm::{ActiveEnum, ColumnTrait, Condition, DynIden, Iden, sea_query::SeaRc}; use crate::{ActiveEnumBuilder, BuilderContext}; @@ -68,7 +68,7 @@ impl ActiveEnumFilterInputBuilder { pub fn prepare_enumeration_condition( filter: &ObjectAccessor, column: T, - variants: &[std::sync::Arc], + variants: &[SeaRc], condition: Condition, ) -> Condition where