2017-12-02 08:59:23 -06:00
|
|
|
#![feature(plugin)]
|
|
|
|
#![plugin(rocket_codegen)]
|
|
|
|
|
|
|
|
extern crate juniper;
|
|
|
|
extern crate juniper_rocket;
|
2018-01-13 05:25:55 -06:00
|
|
|
extern crate rocket;
|
2017-12-02 08:59:23 -06:00
|
|
|
|
|
|
|
use rocket::response::content;
|
|
|
|
use rocket::State;
|
|
|
|
|
|
|
|
use juniper::tests::model::Database;
|
|
|
|
use juniper::{EmptyMutation, RootNode};
|
|
|
|
|
|
|
|
type Schema = RootNode<'static, Database, EmptyMutation<Database>>;
|
|
|
|
|
|
|
|
#[get("/")]
|
|
|
|
fn graphiql() -> content::Html<String> {
|
|
|
|
juniper_rocket::graphiql_source("/graphql")
|
|
|
|
}
|
|
|
|
|
|
|
|
#[get("/graphql?<request>")]
|
|
|
|
fn get_graphql_handler(
|
|
|
|
context: State<Database>,
|
|
|
|
request: juniper_rocket::GraphQLRequest,
|
|
|
|
schema: State<Schema>,
|
|
|
|
) -> juniper_rocket::GraphQLResponse {
|
|
|
|
request.execute(&schema, &context)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[post("/graphql", data = "<request>")]
|
|
|
|
fn post_graphql_handler(
|
|
|
|
context: State<Database>,
|
|
|
|
request: juniper_rocket::GraphQLRequest,
|
|
|
|
schema: State<Schema>,
|
|
|
|
) -> juniper_rocket::GraphQLResponse {
|
|
|
|
request.execute(&schema, &context)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
rocket::ignite()
|
|
|
|
.manage(Database::new())
|
|
|
|
.manage(Schema::new(
|
|
|
|
Database::new(),
|
|
|
|
EmptyMutation::<Database>::new(),
|
|
|
|
))
|
|
|
|
.mount(
|
|
|
|
"/",
|
|
|
|
routes![graphiql, get_graphql_handler, post_graphql_handler],
|
|
|
|
)
|
|
|
|
.launch();
|
|
|
|
}
|