eb941e509a
Co-authored-by: tyranron <tyranron@gmail.com> Co-authored-by: Christian Legnitto <LegNeato@users.noreply.github.com>
48 lines
1.3 KiB
Rust
48 lines
1.3 KiB
Rust
#![feature(decl_macro, proc_macro_hygiene)]
|
|
|
|
use rocket::{response::content, State};
|
|
|
|
use juniper::{
|
|
tests::{model::Database, schema::Query},
|
|
EmptyMutation, EmptySubscription, RootNode,
|
|
};
|
|
|
|
type Schema = RootNode<'static, Query, EmptyMutation<Database>, EmptySubscription<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_sync(&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_sync(&schema, &context)
|
|
}
|
|
|
|
fn main() {
|
|
rocket::ignite()
|
|
.manage(Database::new())
|
|
.manage(Schema::new(
|
|
Query,
|
|
EmptyMutation::<Database>::new(),
|
|
EmptySubscription::<Database>::new(),
|
|
))
|
|
.mount(
|
|
"/",
|
|
rocket::routes![graphiql, get_graphql_handler, post_graphql_handler],
|
|
)
|
|
.launch();
|
|
}
|