pub mod handler;
pub mod query;
pub mod schema;
pub mod service;
pub use handler::*;
pub use query::*;
pub use schema::*;
use actix_web::HttpRequest;
use actix_web::HttpResponse;
use actix_web::Responder;
use async_graphql::http::{playground_source, GraphQLPlaygroundConfig};
use async_graphql::Schema;
use async_graphql_actix_web::{GraphQLRequest, GraphQLResponse};
use crate::core::auth0::Requestor;
use crate::core::request2::Render;
pub fn build(
ctx: actix_web::web::Data<crate::server::AppContext>,
) -> Schema<Query, Mutation, async_graphql::EmptySubscription> {
async_graphql::Schema::build(
crate::graphql::Query::default(),
crate::graphql::handler::Mutation,
async_graphql::EmptySubscription,
)
.data(ctx)
.finish()
}
pub async fn graphql(
schema: actix_web::web::Data<GenericGraphqlSchema>,
gql_request: GraphQLRequest,
requestor: actix_web::web::ReqData<Requestor>,
) -> GraphQLResponse {
let request = gql_request.into_inner();
let requestor = requestor.into_inner();
schema.execute(request.data(requestor)).await.into()
}
pub async fn graphiql(request: HttpRequest) -> impl Responder {
let ctx = tera::Context::new();
request.render(200, "graphiql/graphiql_index.html", ctx)
}
pub async fn graphql_playground() -> HttpResponse {
HttpResponse::Ok()
.content_type("text/html; charset=utf-8")
.body(playground_source(GraphQLPlaygroundConfig::new("/graphql")))
}