zero4rs 2.0.0

zero4rs is a powerful, pragmatic, and extremely fast web framework for Rust
Documentation
pub mod handler;
pub mod query;
// pub mod scalars;
pub mod schema;
pub mod service;

pub use handler::*;
pub use query::*;
// pub use scalars::*;
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()
}

// https://async-graphql.github.io/
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")))
}