Skip to content

Commit 1e496a2

Browse files
committed
Update seaography_example
1 parent 216479c commit 1e496a2

File tree

12 files changed

+37
-77
lines changed

12 files changed

+37
-77
lines changed

examples/seaography_example/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ cargo run
2525
## Install Seaography
2626

2727
```sh
28-
cargo install seaography-cli@^1.0.0
28+
cargo install seaography-cli@^1.1.3
2929
```
3030

3131
## Generate GraphQL project
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,23 @@
11
[package]
22
edition = "2021"
33
name = "sea-orm-seaography-example"
4-
version = "0.3.0"
5-
publish = false
4+
version = "0.1.0"
65

76
[dependencies]
87
poem = { version = "3.0" }
98
async-graphql-poem = { version = "7.0" }
10-
async-graphql = { version = "7.0", features = ["decimal", "chrono", "dataloader", "dynamic-schema"] }
11-
async-trait = { version = "0.1.72" }
129
dotenv = "0.15.0"
13-
sea-orm = { path = "../../../", features = ["sqlx-mysql", "runtime-async-std-native-tls", "seaography"] }
10+
sea-orm = { version = "~1.1.4", features = ["sqlx-mysql", "runtime-async-std-native-tls", "seaography"] }
1411
tokio = { version = "1.29.1", features = ["macros", "rt-multi-thread"] }
1512
tracing = { version = "0.1.37" }
1613
tracing-subscriber = { version = "0.3.17" }
17-
lazy_static = { version = "1.4.0" }
18-
seaography = { version = "1.1.0", features = ["with-decimal", "with-chrono"] }
14+
15+
[dependencies.seaography]
16+
version = "~1.1.3" # seaography version
17+
features = ["with-decimal", "with-chrono"]
1918

2019
[dev-dependencies]
2120
serde_json = { version = "1.0.103" }
2221

2322
[workspace]
2423
members = []
25-
26-
# This allows us to develop using a local version of sea-orm
27-
# remove this section in your own project
28-
[patch.crates-io]
29-
sea-orm = { path = "../../../" }

examples/seaography_example/graphql/src/entities/baker.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.1
1+
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.4
22
33
use sea_orm::entity::prelude::*;
44

examples/seaography_example/graphql/src/entities/bakery.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.1
1+
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.4
22
33
use sea_orm::entity::prelude::*;
44

examples/seaography_example/graphql/src/entities/cake.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.1
1+
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.4
22
33
use sea_orm::entity::prelude::*;
44

@@ -10,7 +10,7 @@ pub struct Model {
1010
pub name: String,
1111
#[sea_orm(column_type = "Decimal(Some((16, 4)))")]
1212
pub price: Decimal,
13-
pub bakery_id: Option<i32>,
13+
pub bakery_id: i32,
1414
pub gluten_free: i8,
1515
}
1616

examples/seaography_example/graphql/src/entities/cake_baker.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.1
1+
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.4
22
33
use sea_orm::entity::prelude::*;
44

Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.1
1+
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.4
22
33
pub mod prelude;
44

@@ -7,4 +7,4 @@ pub mod bakery;
77
pub mod cake;
88
pub mod cake_baker;
99

10-
seaography::register_entity_modules!([baker, bakery, cake, cake_baker]);
10+
seaography::register_entity_modules!([baker, bakery, cake, cake_baker,]);

examples/seaography_example/graphql/src/entities/prelude.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.1
1+
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.4
22
33
pub use super::baker::Entity as Baker;
44
pub use super::bakery::Entity as Bakery;
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,2 @@
1-
use sea_orm::prelude::*;
2-
31
pub mod entities;
42
pub mod query_root;
5-
6-
pub struct OrmDataloader {
7-
pub db: DatabaseConnection,
8-
}

examples/seaography_example/graphql/src/main.rs

+6-32
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,12 @@
1-
use async_graphql::{
2-
dataloader::DataLoader,
3-
http::{playground_source, GraphQLPlaygroundConfig},
4-
};
1+
use async_graphql::http::{playground_source, GraphQLPlaygroundConfig};
52
use async_graphql_poem::GraphQL;
63
use dotenv::dotenv;
7-
use lazy_static::lazy_static;
84
use poem::{get, handler, listener::TcpListener, web::Html, IntoResponse, Route, Server};
95
use sea_orm::Database;
10-
use sea_orm_seaography_example::*;
6+
use seaography::{async_graphql, lazy_static};
117
use std::env;
128

13-
lazy_static! {
14-
static ref URL: String = env::var("URL").unwrap_or("0.0.0.0:8000".into());
15-
static ref ENDPOINT: String = env::var("ENDPOINT").unwrap_or("/".into());
16-
static ref DATABASE_URL: String =
17-
env::var("DATABASE_URL").expect("DATABASE_URL environment variable not set");
18-
static ref DEPTH_LIMIT: Option<usize> = env::var("DEPTH_LIMIT").map_or(None, |data| Some(
19-
data.parse().expect("DEPTH_LIMIT is not a number")
20-
));
21-
static ref COMPLEXITY_LIMIT: Option<usize> = env::var("COMPLEXITY_LIMIT")
22-
.map_or(None, |data| {
23-
Some(data.parse().expect("COMPLEXITY_LIMIT is not a number"))
24-
});
25-
}
9+
lazy_static::lazy_static! { static ref URL : String = env :: var ("URL") . unwrap_or ("localhost:8000" . into ()) ; static ref ENDPOINT : String = env :: var ("ENDPOINT") . unwrap_or ("/" . into ()) ; static ref DATABASE_URL : String = env :: var ("DATABASE_URL") . expect ("DATABASE_URL environment variable not set") ; static ref DEPTH_LIMIT : Option < usize > = env :: var ("DEPTH_LIMIT") . map_or (None , | data | Some (data . parse () . expect ("DEPTH_LIMIT is not a number"))) ; static ref COMPLEXITY_LIMIT : Option < usize > = env :: var ("COMPLEXITY_LIMIT") . map_or (None , | data | { Some (data . parse () . expect ("COMPLEXITY_LIMIT is not a number")) }) ; }
2610

2711
#[handler]
2812
async fn graphql_playground() -> impl IntoResponse {
@@ -39,19 +23,9 @@ async fn main() {
3923
let database = Database::connect(&*DATABASE_URL)
4024
.await
4125
.expect("Fail to initialize database connection");
42-
let orm_dataloader: DataLoader<OrmDataloader> = DataLoader::new(
43-
OrmDataloader {
44-
db: database.clone(),
45-
},
46-
tokio::spawn,
47-
);
48-
let schema = sea_orm_seaography_example::query_root::schema(
49-
database,
50-
orm_dataloader,
51-
*DEPTH_LIMIT,
52-
*COMPLEXITY_LIMIT,
53-
)
54-
.unwrap();
26+
let schema =
27+
sea_orm_seaography_example::query_root::schema(database, *DEPTH_LIMIT, *COMPLEXITY_LIMIT)
28+
.unwrap();
5529
let app = Route::new().at(
5630
&*ENDPOINT,
5731
get(graphql_playground).post(GraphQL::new(schema)),
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,21 @@
1-
use crate::{entities::*, OrmDataloader};
2-
use async_graphql::{dataloader::DataLoader, dynamic::*};
1+
use crate::entities::*;
2+
use async_graphql::dynamic::*;
33
use sea_orm::DatabaseConnection;
4-
use seaography::{Builder, BuilderContext};
4+
use seaography::{async_graphql, lazy_static, Builder, BuilderContext};
55

66
lazy_static::lazy_static! { static ref CONTEXT : BuilderContext = BuilderContext :: default () ; }
77

88
pub fn schema(
99
database: DatabaseConnection,
10-
orm_dataloader: DataLoader<OrmDataloader>,
1110
depth: Option<usize>,
1211
complexity: Option<usize>,
1312
) -> Result<Schema, SchemaError> {
14-
let builder = Builder::new(&CONTEXT, database.clone());
15-
let builder = crate::entities::register_entity_modules(builder);
16-
let schema = builder.schema_builder();
17-
let schema = if let Some(depth) = depth {
18-
schema.limit_depth(depth)
19-
} else {
20-
schema
21-
};
22-
let schema = if let Some(complexity) = complexity {
23-
schema.limit_complexity(complexity)
24-
} else {
25-
schema
26-
};
27-
schema.data(database).data(orm_dataloader).finish()
13+
let mut builder = Builder::new(&CONTEXT, database.clone());
14+
seaography::register_entities!(builder, [baker, bakery, cake, cake_baker,]);
15+
builder
16+
.set_depth_limit(depth)
17+
.set_complexity_limit(complexity)
18+
.schema_builder()
19+
.data(database)
20+
.finish()
2821
}

examples/seaography_example/migration/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Bakery Schema
22

3+
```sql
4+
CREATE DATABASE bakery;
5+
GRANT ALL PRIVILEGES ON bakery.* TO sea;
6+
```
7+
38
Assume the database is named `bakery`:
49

510
```sh

0 commit comments

Comments
 (0)