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