#![feature(decl_macro, proc_macro_hygiene)] use juniper::{ tests::fixtures::starwars::{model::Database, schema::Query}, EmptyMutation, EmptySubscription, RootNode, }; use rocket::{response::content, State}; type Schema = RootNode<'static, Query, EmptyMutation, EmptySubscription>; #[rocket::get("/")] fn graphiql() -> content::Html { juniper_rocket_async::graphiql_source("/graphql") } #[rocket::get("/graphql?")] fn get_graphql_handler( context: State, request: juniper_rocket_async::GraphQLRequest, schema: State, ) -> juniper_rocket_async::GraphQLResponse { request.execute_sync(&schema, &context) } #[rocket::post("/graphql", data = "")] fn post_graphql_handler( context: State, request: juniper_rocket_async::GraphQLRequest, schema: State, ) -> juniper_rocket_async::GraphQLResponse { request.execute_sync(&schema, &context) } #[rocket::main] async fn main() { rocket::ignite() .manage(Database::new()) .manage(Schema::new( Query, EmptyMutation::::new(), EmptySubscription::::new(), )) .mount( "/", rocket::routes![graphiql, get_graphql_handler, post_graphql_handler], ) .launch() .await .expect("server to launch"); }