Skip to content

Commit

Permalink
Register "related entity" / "entity" without relation
Browse files Browse the repository at this point in the history
  • Loading branch information
billy1624 committed May 17, 2023
1 parent 28b7930 commit f23b1af
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 19 deletions.
2 changes: 1 addition & 1 deletion examples/sqlite/src/query_root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub fn schema(
depth: Option<usize>,
complexity: Option<usize>,
) -> Result<Schema, SchemaError> {
let builder = seaography::register_entities!(
let builder = seaography::register_related_entities!(
Builder::new(&CONTEXT),
&CONTEXT,
[
Expand Down
2 changes: 1 addition & 1 deletion generator/src/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pub fn generate_query_root<P: AsRef<Path>>(entities_path: &P) -> TokenStream {
depth: Option<usize>,
complexity: Option<usize>,
) -> Result<Schema, SchemaError> {
let builder = seaography::register_entities!(Builder::new(&CONTEXT), &CONTEXT, [
let builder = seaography::register_related_entities!(Builder::new(&CONTEXT), &CONTEXT, [
#(#entities,)*
]);

Expand Down
36 changes: 21 additions & 15 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);)*
};
}
4 changes: 2 additions & 2 deletions src/inputs/active_enum_filter_input.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down Expand Up @@ -68,7 +68,7 @@ impl ActiveEnumFilterInputBuilder {
pub fn prepare_enumeration_condition<T>(
filter: &ObjectAccessor,
column: T,
variants: &[std::sync::Arc<dyn Iden>],
variants: &[SeaRc<dyn Iden>],
condition: Condition,
) -> Condition
where
Expand Down

0 comments on commit f23b1af

Please sign in to comment.