835dee1a8e
style: Enable rustfmt merge_imports and format This commit enables the rustfmt merge_imports setting and formats the whole code base accordingly. Note that the setting is not stable yet, but will be with Rust 1.38. In the meantime, running fmt on stable will just leave the changes alone so no problems should occur.
44 lines
1.1 KiB
Rust
44 lines
1.1 KiB
Rust
#![feature(decl_macro, proc_macro_hygiene)]
|
|
|
|
use rocket::{response::content, State};
|
|
|
|
use juniper::{
|
|
tests::{model::Database, schema::Query},
|
|
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();
|
|
}
|