Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add related queries optimizations #146

Merged
merged 9 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
[workspace]
members = [
".",
"cli",
"generator",
]
members = [".", "cli", "generator"]

[package]
name = "seaography"
Expand All @@ -24,7 +20,9 @@ async-graphql = { version = "6.0.7", features = ["decimal", "chrono", "dataloade
sea-orm = { version = "0.12.0", default-features = false, features = ["seaography"] }
itertools = { version = "0.11.0" }
heck = { version = "0.4.1" }
thiserror = "1.0.44"
thiserror = { version = "1.0.44" }
async-trait = { version = "0.1" }
fnv = { version = "1.0.7" }

[features]
default = []
Expand All @@ -36,4 +34,4 @@ with-decimal = ["sea-orm/with-rust_decimal", "async-graphql/decimal"]
with-bigdecimal = ["sea-orm/with-bigdecimal", "async-graphql/bigdecimal"]
# with-postgres-array = ["sea-orm/postgres-array"]
# with-ipnetwork = ["sea-orm/with-ipnetwork"]
# with-mac_address = ["sea-orm/with-mac_address"]
# with-mac_address = ["sea-orm/with-mac_address"]
6 changes: 0 additions & 6 deletions examples/mysql/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,2 @@
use sea_orm::prelude::*;

pub mod entities;
pub mod query_root;

pub struct OrmDataloader {
pub db: DatabaseConnection,
}
13 changes: 1 addition & 12 deletions examples/mysql/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
use async_graphql::{
dataloader::DataLoader,
http::{playground_source, GraphQLPlaygroundConfig},
};
use async_graphql::http::{playground_source, GraphQLPlaygroundConfig};
use async_graphql_poem::GraphQL;
use dotenv::dotenv;
use lazy_static::lazy_static;
use poem::{get, handler, listener::TcpListener, web::Html, IntoResponse, Route, Server};
use sea_orm::Database;
use seaography_mysql_example::*;
use std::env;

lazy_static! {
Expand Down Expand Up @@ -39,15 +35,8 @@ async fn main() {
let database = Database::connect(&*DATABASE_URL)
.await
.expect("Fail to initialize database connection");
let orm_dataloader: DataLoader<OrmDataloader> = DataLoader::new(
OrmDataloader {
db: database.clone(),
},
tokio::spawn,
);
let schema = seaography_mysql_example::query_root::schema(
database,
orm_dataloader,
*DEPTH_LIMIT,
*COMPLEXITY_LIMIT,
)
Expand Down
7 changes: 3 additions & 4 deletions examples/mysql/src/query_root.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use crate::{entities::*, OrmDataloader};
use async_graphql::{dataloader::DataLoader, dynamic::*};
use crate::entities::*;
use async_graphql::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> {
Expand Down Expand Up @@ -45,5 +44,5 @@ pub fn schema(
} else {
schema
};
schema.data(database).data(orm_dataloader).finish()
schema.data(database).finish()
}
12 changes: 3 additions & 9 deletions examples/mysql/tests/mutation_tests.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
use async_graphql::{dataloader::DataLoader, dynamic::*, Response};
use async_graphql::{dynamic::*, Response};
use sea_orm::Database;
use seaography_mysql_example::OrmDataloader;

pub async fn get_schema() -> Schema {
let database = Database::connect("mysql://sea:[email protected]/sakila")
.await
.unwrap();
let orm_dataloader: DataLoader<OrmDataloader> = DataLoader::new(
OrmDataloader {
db: database.clone(),
},
tokio::spawn,
);
let schema =
seaography_mysql_example::query_root::schema(database, orm_dataloader, None, None).unwrap();
seaography_mysql_example::query_root::schema(database, None, None)
.unwrap();

schema
}
Expand Down
11 changes: 2 additions & 9 deletions examples/mysql/tests/query_tests.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
use async_graphql::{dataloader::DataLoader, dynamic::*, Response};
use async_graphql::{dynamic::*, Response};
use sea_orm::Database;
use seaography_mysql_example::OrmDataloader;

pub async fn get_schema() -> Schema {
let database = Database::connect("mysql://sea:[email protected]/sakila")
.await
.unwrap();
let orm_dataloader: DataLoader<OrmDataloader> = DataLoader::new(
OrmDataloader {
db: database.clone(),
},
tokio::spawn,
);
let schema =
seaography_mysql_example::query_root::schema(database, orm_dataloader, None, None).unwrap();
seaography_mysql_example::query_root::schema(database, None, None).unwrap();

schema
}
Expand Down
5 changes: 0 additions & 5 deletions examples/postgres/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
use sea_orm::prelude::*;

pub mod entities;
pub mod query_root;

pub struct OrmDataloader {
pub db: DatabaseConnection,
}
13 changes: 1 addition & 12 deletions examples/postgres/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
use async_graphql::{
dataloader::DataLoader,
http::{playground_source, GraphQLPlaygroundConfig},
};
use async_graphql::http::{playground_source, GraphQLPlaygroundConfig};
use async_graphql_poem::GraphQL;
use dotenv::dotenv;
use lazy_static::lazy_static;
use poem::{get, handler, listener::TcpListener, web::Html, IntoResponse, Route, Server};
use sea_orm::Database;
use seaography_postgres_example::*;
use std::env;

lazy_static! {
Expand Down Expand Up @@ -39,15 +35,8 @@ async fn main() {
let database = Database::connect(&*DATABASE_URL)
.await
.expect("Fail to initialize database connection");
let orm_dataloader: DataLoader<OrmDataloader> = DataLoader::new(
OrmDataloader {
db: database.clone(),
},
tokio::spawn,
);
let schema = seaography_postgres_example::query_root::schema(
database,
orm_dataloader,
*DEPTH_LIMIT,
*COMPLEXITY_LIMIT,
)
Expand Down
9 changes: 4 additions & 5 deletions examples/postgres/src/query_root.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
use crate::{entities::*, OrmDataloader};
use async_graphql::{dataloader::DataLoader, dynamic::*};
use crate::entities::*;
use async_graphql::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);
let mut builder = Builder::new(&CONTEXT, database.clone());
seaography::register_entities!(
builder,
[
Expand Down Expand Up @@ -44,5 +43,5 @@ pub fn schema(
} else {
schema
};
schema.data(database).data(orm_dataloader).finish()
schema.data(database).finish()
}
11 changes: 2 additions & 9 deletions examples/postgres/tests/mutation_tests.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
use async_graphql::{dataloader::DataLoader, dynamic::*, Response};
use async_graphql::{dynamic::*, Response};
use sea_orm::Database;
use seaography_postgres_example::OrmDataloader;

pub async fn get_schema() -> Schema {
let database = Database::connect("postgres://sea:[email protected]/sakila")
.await
.unwrap();
let orm_dataloader: DataLoader<OrmDataloader> = DataLoader::new(
OrmDataloader {
db: database.clone(),
},
tokio::spawn,
);
let schema =
seaography_postgres_example::query_root::schema(database, orm_dataloader, None, None)
seaography_postgres_example::query_root::schema(database, None, None)
.unwrap();

schema
Expand Down
Loading
Loading