Expose Star Wars schema in example server

This commit is contained in:
Magnus Hallin 2016-09-18 16:30:15 +02:00
parent c9f9233681
commit 89b3c4c776
4 changed files with 9 additions and 28 deletions

View file

@ -37,7 +37,7 @@ script:
script:
- cargo build --verbose
- cargo build --verbose --features iron-handlers
- cargo test --verbose --features iron-handlers
- cargo test --verbose --features "iron-handlers expose-test-schema"
before_deploy:
- rm -rf target/package/
@ -45,7 +45,7 @@ before_deploy:
after_success:
- |
travis-cargo coverage --no-sudo -- --features iron-handlers
travis-cargo coverage --no-sudo -- --features "iron-handlers expose-test-schema"
./kcov/build/src/kcov --verify --coveralls-id=$TRAVIS_JOB_ID --exclude-pattern=/.cargo target/kcov target/debug/juniper-*
- |

View file

@ -13,6 +13,7 @@ keywords = ["graphql", "server", "iron", "http", "web"]
default = []
nightly = []
iron-handlers = ["iron"]
expose-test-schema = []
[dependencies]
rustc-serialize = "0.3.19"

View file

@ -11,15 +11,16 @@ use logger::Logger;
use iron::prelude::*;
use juniper::FieldResult;
use juniper::iron_handlers::{GraphQLHandler, GraphiQLHandler};
use juniper::tests::model::Database;
fn context_factory(_: &mut Request) -> () {
()
fn context_factory(_: &mut Request) -> Database {
Database::new()
}
fn main() {
let mut mount = Mount::new();
let graphql_endpoint = GraphQLHandler::new(context_factory, Query { }, Mutation { });
let graphql_endpoint = GraphQLHandler::new(context_factory, Database::new(), ());
let graphiql_endpoint = GraphiQLHandler::new("/graphql");
mount.mount("/", graphiql_endpoint);
@ -35,24 +36,3 @@ fn main() {
println!("GraphQL server started on {}", host);
Iron::new(chain).http(host.as_str()).unwrap();
}
struct Query {}
struct Mutation {}
graphql_object!(Query: () as "Query" |&self| {
field dummy() -> FieldResult<&str> {
Ok("Dummy field")
}
field error() -> FieldResult<&str> {
Err("Can't do it".to_owned())
}
});
graphql_object!(<CtxT> Mutation: CtxT as "Mutation" |&self| {
field print(value: String) -> FieldResult<String> {
println!("Printing text according to mutation");
println!("{}", value);
Ok(value)
}
});

View file

@ -185,8 +185,8 @@ mod schema;
pub mod validation;
mod integrations;
#[cfg(test)]
mod tests;
#[cfg(all(test, not(feature="expose-test-schema")))] mod tests;
#[cfg(feature="expose-test-schema")] pub mod tests;
use std::collections::HashMap;