Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
3 contributors

Users who have contributed to this file

@theduke @ELD @andy128k
45 lines (37 sloc) 1.14 KB
#![feature(decl_macro, proc_macro_hygiene)]
use rocket::response::content;
use rocket::State;
use juniper::tests::model::Database;
use juniper::tests::schema::Query;
use juniper::{EmptyMutation, RootNode};
type Schema = RootNode<'static, Query, EmptyMutation<Database>>;
#[rocket::get("/")]
fn graphiql() -> content::Html<String> {
juniper_rocket::graphiql_source("/graphql")
}
#[rocket::get("/graphql?<request>")]
fn get_graphql_handler(
context: State<Database>,
request: juniper_rocket::GraphQLRequest,
schema: State<Schema>,
) -> juniper_rocket::GraphQLResponse {
request.execute(&schema, &context)
}
#[rocket::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(Query, EmptyMutation::<Database>::new()))
.mount(
"/",
rocket::routes![graphiql, get_graphql_handler, post_graphql_handler],
)
.launch();
}
You can’t perform that action at this time.