29 lines
941 B
Rust
29 lines
941 B
Rust
use crate::{entities::*, OrmDataloader};
|
|
use async_graphql::{dataloader::DataLoader, dynamic::*};
|
|
use sea_orm::DatabaseConnection;
|
|
use seaography::{Builder, BuilderContext};
|
|
|
|
lazy_static::lazy_static! { static ref CONTEXT : BuilderContext = BuilderContext :: default () ; }
|
|
|
|
pub fn schema(
|
|
database: DatabaseConnection,
|
|
orm_dataloader: DataLoader<OrmDataloader>,
|
|
depth: Option<usize>,
|
|
complexity: Option<usize>,
|
|
) -> Result<Schema, SchemaError> {
|
|
let mut builder = Builder::new(&CONTEXT);
|
|
seaography::register_entities!(builder, [baker, bakery, cake, cake_baker,]);
|
|
let schema = builder.schema_builder();
|
|
let schema = if let Some(depth) = depth {
|
|
schema.limit_depth(depth)
|
|
} else {
|
|
schema
|
|
};
|
|
let schema = if let Some(complexity) = complexity {
|
|
schema.limit_complexity(complexity)
|
|
} else {
|
|
schema
|
|
};
|
|
schema.data(database).data(orm_dataloader).finish()
|
|
}
|