diff --git a/.travis.yml b/.travis.yml index 52b375c4..3c5ba52a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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-* - | diff --git a/Cargo.toml b/Cargo.toml index 5f696653..5b7d9cd8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,7 @@ keywords = ["graphql", "server", "iron", "http", "web"] default = [] nightly = [] iron-handlers = ["iron"] +expose-test-schema = [] [dependencies] rustc-serialize = "0.3.19" diff --git a/examples/server.rs b/examples/server.rs index e021463b..ec8d6c4a 100644 --- a/examples/server.rs +++ b/examples/server.rs @@ -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!( Mutation: CtxT as "Mutation" |&self| { - field print(value: String) -> FieldResult { - println!("Printing text according to mutation"); - println!("{}", value); - Ok(value) - } -}); diff --git a/src/lib.rs b/src/lib.rs index 63004480..e2ec9493 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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;