stoptime-rs/src/handlers.rs

45 lines
1017 B
Rust

//! The request handlers.
use crate::graphql::Schema;
use crate::DbConn;
use juniper_rocket::{playground_source, GraphQLRequest, GraphQLResponse};
use rocket::response::content::Html;
use rocket::{get, post, State};
/// Presents the main web application.
///
/// FIXME: Not implemented yet.
#[get("/")]
pub fn index() {
unimplemented!()
}
/// Presents a playground GraphQL web application.
///
/// This can be used to test the GraphQL backend.
#[get("/graphql/playground")]
pub fn graphql_playground() -> Html<String> {
playground_source("/graphql")
}
/// Handles a GraphQL GET request.
#[get("/graphql?<request>")]
pub fn graphql_get(
request: GraphQLRequest,
conn: DbConn,
schema: State<Schema>,
) -> GraphQLResponse {
request.execute(&schema, &conn)
}
/// Handles a GraphQL POST request.
#[post("/graphql", data = "<request>")]
pub fn graphql_post(
request: GraphQLRequest,
conn: DbConn,
schema: State<Schema>,
) -> GraphQLResponse {
request.execute(&schema, &conn)
}