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.
42 lines
1.1 KiB
Rust
42 lines
1.1 KiB
Rust
extern crate iron;
|
|
extern crate juniper;
|
|
extern crate juniper_iron;
|
|
extern crate logger;
|
|
extern crate mount;
|
|
extern crate serde;
|
|
|
|
use std::env;
|
|
|
|
use iron::prelude::*;
|
|
use juniper::{
|
|
tests::{model::Database, schema::Query},
|
|
EmptyMutation,
|
|
};
|
|
use juniper_iron::{GraphQLHandler, GraphiQLHandler};
|
|
use logger::Logger;
|
|
use mount::Mount;
|
|
|
|
fn context_factory(_: &mut Request) -> IronResult<Database> {
|
|
Ok(Database::new())
|
|
}
|
|
|
|
fn main() {
|
|
let mut mount = Mount::new();
|
|
|
|
let graphql_endpoint =
|
|
GraphQLHandler::new(context_factory, Query, EmptyMutation::<Database>::new());
|
|
let graphiql_endpoint = GraphiQLHandler::new("/graphql");
|
|
|
|
mount.mount("/", graphiql_endpoint);
|
|
mount.mount("/graphql", graphql_endpoint);
|
|
|
|
let (logger_before, logger_after) = Logger::new(None);
|
|
|
|
let mut chain = Chain::new(mount);
|
|
chain.link_before(logger_before);
|
|
chain.link_after(logger_after);
|
|
|
|
let host = env::var("LISTEN").unwrap_or_else(|_| "0.0.0.0:8080".to_owned());
|
|
println!("GraphQL server started on {}", host);
|
|
Iron::new(chain).http(host.as_str()).unwrap();
|
|
}
|