use rocket::response::content::RawHtml; use rocket::State; use juniper::EmptySubscription; use juniper_rocket::{GraphQLRequest, GraphQLResponse}; use crate::appwrite::APVariables; use crate::db::Database; #[derive(Default, Debug)] pub struct Context { pub db: Database, pub appwrite: APVariables, } impl juniper::Context for Context {} mod query; use query::Query; mod mutation; use mutation::Mutation; type Schema = juniper::RootNode<'static, Query, Mutation, EmptySubscription>; pub fn create_schema() -> Schema { Schema::new(Query {}, Mutation {}, EmptySubscription::default()) } #[rocket::get("/")] pub fn graphiql() -> RawHtml { let graphql_endpoint_url = "/graphql"; juniper_rocket::graphiql_source(graphql_endpoint_url, None) } #[rocket::get("/graphql?")] pub async fn get_graphql_handler( context: &State, request: GraphQLRequest, schema: &State, ) -> GraphQLResponse { request.execute(schema, context).await } #[allow(clippy::needless_pass_by_value)] #[rocket::post("/graphql", data = "")] pub async fn post_graphql_handler( context: &State, request: GraphQLRequest, schema: &State, ) -> GraphQLResponse { request.execute(schema, context).await }