2016-09-11 11:41:29 -05:00
|
|
|
extern crate iron;
|
|
|
|
extern crate mount;
|
|
|
|
extern crate logger;
|
2017-04-30 21:07:36 -05:00
|
|
|
extern crate serde;
|
2017-05-18 03:31:53 -05:00
|
|
|
extern crate juniper;
|
2016-09-11 11:41:29 -05:00
|
|
|
|
2016-09-18 08:40:38 -05:00
|
|
|
use std::env;
|
|
|
|
|
2016-09-11 11:41:29 -05:00
|
|
|
use mount::Mount;
|
|
|
|
use logger::Logger;
|
|
|
|
use iron::prelude::*;
|
2016-12-22 09:25:39 -06:00
|
|
|
use juniper::EmptyMutation;
|
2016-09-11 11:41:29 -05:00
|
|
|
use juniper::iron_handlers::{GraphQLHandler, GraphiQLHandler};
|
2016-09-18 09:30:15 -05:00
|
|
|
use juniper::tests::model::Database;
|
2016-09-11 11:41:29 -05:00
|
|
|
|
2016-09-18 09:30:15 -05:00
|
|
|
fn context_factory(_: &mut Request) -> Database {
|
|
|
|
Database::new()
|
2016-09-11 11:41:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let mut mount = Mount::new();
|
|
|
|
|
2016-12-22 09:25:39 -06:00
|
|
|
let graphql_endpoint = GraphQLHandler::new(
|
|
|
|
context_factory,
|
|
|
|
Database::new(),
|
|
|
|
EmptyMutation::<Database>::new(),
|
|
|
|
);
|
2016-09-11 11:41:29 -05:00
|
|
|
let graphiql_endpoint = GraphiQLHandler::new("/graphql");
|
|
|
|
|
2016-09-18 08:55:30 -05:00
|
|
|
mount.mount("/", graphiql_endpoint);
|
2016-09-11 11:41:29 -05:00
|
|
|
mount.mount("/graphql", graphql_endpoint);
|
|
|
|
|
2017-01-24 23:43:39 -06:00
|
|
|
let (logger_before, logger_after) = Logger::new(None);
|
2017-02-04 03:30:46 -06:00
|
|
|
|
2017-01-24 23:43:39 -06:00
|
|
|
let mut chain = Chain::new(mount);
|
|
|
|
chain.link_before(logger_before);
|
|
|
|
chain.link_after(logger_after);
|
2016-09-11 11:41:29 -05:00
|
|
|
|
2016-09-18 08:40:38 -05:00
|
|
|
let host = env::var("LISTEN").unwrap_or("0.0.0.0:8080".to_owned());
|
2016-09-11 11:41:29 -05:00
|
|
|
println!("GraphQL server started on {}", host);
|
2016-09-18 08:40:38 -05:00
|
|
|
Iron::new(chain).http(host.as_str()).unwrap();
|
2016-09-11 11:41:29 -05:00
|
|
|
}
|