2022-10-04 12:06:00 +02:00
|
|
|
use async_graphql::{EmptySubscription, Schema};
|
|
|
|
use axum::{routing::get, Extension, Router};
|
|
|
|
use como_gql::{
|
|
|
|
graphql::{MutationRoot, QueryRoot},
|
|
|
|
graphql_handler, graphql_playground,
|
|
|
|
};
|
2022-10-04 11:06:48 +02:00
|
|
|
use como_infrastructure::register::ServiceRegister;
|
|
|
|
|
|
|
|
pub struct GraphQLController;
|
|
|
|
|
|
|
|
impl GraphQLController {
|
2022-10-04 12:06:00 +02:00
|
|
|
pub fn new_router(service_register: ServiceRegister) -> Router {
|
|
|
|
let schema = Schema::build(QueryRoot, MutationRoot, EmptySubscription)
|
|
|
|
.data(service_register)
|
|
|
|
.finish();
|
|
|
|
|
|
|
|
Router::new()
|
|
|
|
.route("/", get(graphql_playground).post(graphql_handler))
|
|
|
|
.layer(Extension(schema))
|
2022-10-04 11:06:48 +02:00
|
|
|
}
|
|
|
|
}
|