2020-03-04 06:24:44 +00:00
use crate ::model ::{ __Directive , __Type } ;
2020-03-03 11:15:18 +00:00
use crate ::registry ;
use async_graphql_derive ::Object ;
pub struct __Schema < ' a > {
pub registry : & ' a registry ::Registry ,
pub query_type : & ' a str ,
pub mutation_type : & ' a str ,
}
2020-03-05 06:23:55 +00:00
#[ Object(
internal ,
desc = " A GraphQL Schema defines the capabilities of a GraphQL server. It exposes all available types and directives on the server, as well as the entry points for query, mutation, and subscription operations. "
) ]
impl < ' a > __Schema < ' a > {
#[ field(desc = " A list of all types supported by this server. " ) ]
async fn types ( & self ) -> Vec < __Type < ' a > > {
self . registry
2020-03-04 06:24:44 +00:00
. types
2020-03-03 11:15:18 +00:00
. values ( )
2020-03-04 06:24:44 +00:00
. map ( | ty | __Type ::new_simple ( self . registry , ty ) )
2020-03-05 06:23:55 +00:00
. collect ( )
2020-03-03 11:15:18 +00:00
}
2020-03-05 06:23:55 +00:00
#[ field(
name = " queryType " ,
desc = " The type that query operations will be rooted at. "
) ]
async fn query_type ( & self ) -> __Type < ' a > {
__Type ::new_simple ( self . registry , & self . registry . types [ self . query_type ] )
2020-03-03 11:15:18 +00:00
}
2020-03-05 06:23:55 +00:00
#[ field(
name = " mutationType " ,
desc = " If this server supports mutation, the type that mutation operations will be rooted at. "
) ]
async fn mutation_type ( & self ) -> Option < __Type < ' a > > {
Some ( __Type ::new_simple (
2020-03-04 06:24:44 +00:00
self . registry ,
& self . registry . types [ self . mutation_type ] ,
2020-03-05 06:23:55 +00:00
) )
2020-03-05 00:39:56 +00:00
}
2020-03-05 06:23:55 +00:00
#[ field(
name = " subscriptionType " ,
desc = " If this server support subscription, the type that subscription operations will be rooted at. "
) ]
async fn subscription_type ( & self ) -> Option < __Type < ' a > > {
None
2020-03-04 06:24:44 +00:00
}
2020-03-05 06:23:55 +00:00
#[ field(desc = " A list of all directives supported by this server. " ) ]
async fn directives ( & self ) -> Vec < __Directive < ' a > > {
self . registry
2020-03-04 06:24:44 +00:00
. directives
. iter ( )
. map ( | directive | __Directive {
registry : & self . registry ,
directive ,
} )
2020-03-05 06:23:55 +00:00
. collect ( )
2020-03-03 11:15:18 +00:00
}
}