@@ -17,6 +17,8 @@ use crate::{
1717 PaginationInfoObjectBuilder , PaginationInputBuilder ,
1818} ;
1919
20+ type MetadataHashMap = std:: collections:: HashMap < String , serde_json:: Value > ;
21+
2022/// The Builder is used to create the Schema for GraphQL
2123///
2224/// You can populate it with the entities, enumerations of your choice
@@ -45,7 +47,7 @@ pub struct Builder {
4547 pub subscriptions : Vec < SubscriptionField > ,
4648
4749 /// holds all entities metadata
48- pub metadata : std :: collections :: HashMap < String , serde_json :: Value > ,
50+ pub metadata : MetadataHashMap ,
4951
5052 /// holds a copy to the database connection
5153 pub connection : sea_orm:: DatabaseConnection ,
@@ -325,32 +327,36 @@ impl Builder {
325327 self
326328 }
327329
328- /// used to consume the builder context and generate a ready to be completed GraphQL schema
329- pub fn schema_builder ( self ) -> SchemaBuilder {
330- let query = self . query ;
331- let mutation = self . mutation ;
332- let subscription = self . subscription ;
333- let schema = self . schema ;
334- let have_subscription = !self . subscriptions . is_empty ( ) ;
330+ #[ cfg( feature = "schema-meta" ) ]
331+ fn register_schema_meta ( & mut self ) {
332+ use crate :: schema;
335333
336- // register queries
337- let query = self
338- . queries
339- . into_iter ( )
340- . fold ( query, |query, field| query. field ( field) ) ;
334+ self . register_custom_output :: < schema:: Table > ( ) ;
335+ self . register_custom_output :: < schema:: Column > ( ) ;
336+ self . register_custom_output :: < schema:: ColumnType > ( ) ;
337+ self . register_custom_output :: < schema:: Array > ( ) ;
338+ self . register_custom_output :: < schema:: Enumeration > ( ) ;
339+
340+ use crate :: GqlOutputModelType ;
341+ use async_graphql:: dynamic:: FieldValue ;
341342
342343 const TABLE_NAME : & str = "table_name" ;
344+ let metadata_hashmap = std:: mem:: take ( & mut self . metadata ) ;
345+
343346 let field = Field :: new (
344- "_sea_orm_entity_metadata " ,
345- TypeRef :: named ( TypeRef :: STRING ) ,
347+ "_seaography_schema_metadata " ,
348+ crate :: schema :: Table :: gql_output_type_ref ( self . context ) ,
346349 move |ctx| {
347- let metadata_hashmap = self . metadata . clone ( ) ;
350+ let metadata_hashmap = metadata_hashmap . clone ( ) ;
348351 FieldFuture :: new ( async move {
349352 let table_name = ctx. args . try_get ( TABLE_NAME ) ?. string ( ) ?;
350353 if let Some ( metadata) = metadata_hashmap. get ( table_name) {
351- Ok ( Some ( async_graphql:: Value :: from_json ( metadata. to_owned ( ) ) ?) )
354+ let table: crate :: schema:: Table = serde_json:: from_value ( metadata. clone ( ) ) ?;
355+ Ok ( Some ( FieldValue :: owned_any ( table) ) )
352356 } else {
353- Ok ( None )
357+ Err ( async_graphql:: Error :: new ( format ! (
358+ "table not found `{table_name}`"
359+ ) ) )
354360 }
355361 } )
356362 } ,
@@ -359,7 +365,26 @@ impl Builder {
359365 TABLE_NAME ,
360366 TypeRef :: named_nn ( TypeRef :: STRING ) ,
361367 ) ) ;
362- let query = query. field ( field) ;
368+
369+ self . queries . push ( field) ;
370+ }
371+
372+ /// used to consume the builder context and generate a ready to be completed GraphQL schema
373+ pub fn schema_builder ( mut self ) -> SchemaBuilder {
374+ #[ cfg( feature = "schema-meta" ) ]
375+ self . register_schema_meta ( ) ;
376+
377+ let query = self . query ;
378+ let mutation = self . mutation ;
379+ let subscription = self . subscription ;
380+ let schema = self . schema ;
381+ let have_subscription = !self . subscriptions . is_empty ( ) ;
382+
383+ // register queries
384+ let query = self
385+ . queries
386+ . into_iter ( )
387+ . fold ( query, |query, field| query. field ( field) ) ;
363388
364389 // register mutations
365390 let mutation = self
0 commit comments