2017-06-14 08:50:27 -05:00
|
|
|
#![feature(plugin)]
|
|
|
|
#![plugin(rocket_codegen)]
|
|
|
|
|
|
|
|
extern crate rocket;
|
|
|
|
extern crate juniper;
|
2017-08-06 09:53:31 -05:00
|
|
|
extern crate juniper_rocket;
|
2017-06-14 08:50:27 -05: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("/")]
|
2017-07-28 03:56:20 -05:00
|
|
|
fn graphiql() -> content::Html<String> {
|
2017-08-06 09:53:31 -05:00
|
|
|
juniper_rocket::graphiql_source("/graphql")
|
2017-06-14 08:50:27 -05:00
|
|
|
}
|
|
|
|
|
2017-06-14 11:21:05 -05:00
|
|
|
#[get("/graphql?<request>")]
|
|
|
|
fn get_graphql_handler(
|
|
|
|
context: State<Database>,
|
2017-08-06 09:53:31 -05:00
|
|
|
request: juniper_rocket::GraphQLRequest,
|
2017-06-14 11:21:05 -05:00
|
|
|
schema: State<Schema>,
|
2017-08-06 09:53:31 -05:00
|
|
|
) -> juniper_rocket::GraphQLResponse {
|
2017-06-14 11:21:05 -05:00
|
|
|
request.execute(&schema, &context)
|
|
|
|
}
|
|
|
|
|
2017-06-14 08:50:27 -05:00
|
|
|
#[post("/graphql", data="<request>")]
|
|
|
|
fn post_graphql_handler(
|
|
|
|
context: State<Database>,
|
2017-08-06 09:53:31 -05:00
|
|
|
request: juniper_rocket::GraphQLRequest,
|
2017-06-14 11:21:05 -05:00
|
|
|
schema: State<Schema>,
|
2017-08-06 09:53:31 -05:00
|
|
|
) -> juniper_rocket::GraphQLResponse {
|
2017-06-14 08:50:27 -05:00
|
|
|
request.execute(&schema, &context)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
rocket::ignite()
|
|
|
|
.manage(Database::new())
|
|
|
|
.manage(Schema::new(Database::new(), EmptyMutation::<Database>::new()))
|
2017-06-14 11:21:05 -05:00
|
|
|
.mount("/", routes![graphiql, get_graphql_handler, post_graphql_handler])
|
2017-06-14 08:50:27 -05:00
|
|
|
.launch();
|
2017-07-28 03:56:20 -05:00
|
|
|
}
|