1
- use async_graphql:: {
2
- dataloader:: DataLoader ,
3
- http:: { playground_source, GraphQLPlaygroundConfig } ,
4
- } ;
1
+ use async_graphql:: http:: { playground_source, GraphQLPlaygroundConfig } ;
5
2
use async_graphql_poem:: GraphQL ;
6
3
use dotenv:: dotenv;
7
- use lazy_static:: lazy_static;
8
4
use poem:: { get, handler, listener:: TcpListener , web:: Html , IntoResponse , Route , Server } ;
9
5
use sea_orm:: Database ;
10
- use sea_orm_seaography_example :: * ;
6
+ use seaography :: { async_graphql , lazy_static } ;
11
7
use std:: env;
12
8
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" ) ) } ) ; }
26
10
27
11
#[ handler]
28
12
async fn graphql_playground ( ) -> impl IntoResponse {
@@ -39,19 +23,9 @@ async fn main() {
39
23
let database = Database :: connect ( & * DATABASE_URL )
40
24
. await
41
25
. 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 ( ) ;
55
29
let app = Route :: new ( ) . at (
56
30
& * ENDPOINT ,
57
31
get ( graphql_playground) . post ( GraphQL :: new ( schema) ) ,
0 commit comments