use juniper::{ tests::fixtures::starwars::schema::{Database, Query}, EmptyMutation, EmptySubscription, RootNode, }; use rocket::{response::content, State}; type Schema = RootNode<'static, Query, EmptyMutation, EmptySubscription>; #[rocket::get("/")] fn graphiql() -> content::RawHtml { juniper_rocket::graphiql_source("/graphql", None) } #[rocket::get("/graphql?")] fn get_graphql_handler( context: &State, request: juniper_rocket::GraphQLRequest, schema: &State, ) -> juniper_rocket::GraphQLResponse { request.execute_sync(schema, context) } #[rocket::post("/graphql", data = "")] fn post_graphql_handler( context: &State, request: juniper_rocket::GraphQLRequest, schema: &State, ) -> juniper_rocket::GraphQLResponse { request.execute_sync(schema, context) } #[rocket::main] async fn main() { let _ = rocket::build() .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"); }