2019-06-08 16:15:14 +02:00
|
|
|
//! The root handlers
|
|
|
|
|
2019-07-10 20:54:43 +02:00
|
|
|
use crate::graphql::Schema;
|
|
|
|
use crate::DbConn;
|
2019-06-08 16:15:14 +02:00
|
|
|
|
2019-07-10 20:54:43 +02:00
|
|
|
use juniper_rocket::{playground_source, GraphQLRequest, GraphQLResponse};
|
|
|
|
use rocket::response::content::Html;
|
|
|
|
use rocket::{get, post, State};
|
2019-06-08 16:15:14 +02:00
|
|
|
|
2019-07-10 20:54:43 +02:00
|
|
|
/// Presents the main web application.
|
2019-06-08 16:15:14 +02:00
|
|
|
///
|
2019-07-10 20:54:43 +02:00
|
|
|
/// FIXME: Not implemented yet.
|
2019-06-08 16:15:14 +02:00
|
|
|
#[get("/")]
|
|
|
|
pub fn index() {
|
|
|
|
unimplemented!()
|
|
|
|
}
|
2019-07-10 20:54:43 +02:00
|
|
|
|
|
|
|
/// 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)
|
|
|
|
}
|