Expose Star Wars schema in example server
This commit is contained in:
parent
c9f9233681
commit
89b3c4c776
4 changed files with 9 additions and 28 deletions
|
@ -37,7 +37,7 @@ script:
|
||||||
script:
|
script:
|
||||||
- cargo build --verbose
|
- cargo build --verbose
|
||||||
- cargo build --verbose --features iron-handlers
|
- cargo build --verbose --features iron-handlers
|
||||||
- cargo test --verbose --features iron-handlers
|
- cargo test --verbose --features "iron-handlers expose-test-schema"
|
||||||
|
|
||||||
before_deploy:
|
before_deploy:
|
||||||
- rm -rf target/package/
|
- rm -rf target/package/
|
||||||
|
@ -45,7 +45,7 @@ before_deploy:
|
||||||
|
|
||||||
after_success:
|
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-*
|
./kcov/build/src/kcov --verify --coveralls-id=$TRAVIS_JOB_ID --exclude-pattern=/.cargo target/kcov target/debug/juniper-*
|
||||||
|
|
||||||
- |
|
- |
|
||||||
|
|
|
@ -13,6 +13,7 @@ keywords = ["graphql", "server", "iron", "http", "web"]
|
||||||
default = []
|
default = []
|
||||||
nightly = []
|
nightly = []
|
||||||
iron-handlers = ["iron"]
|
iron-handlers = ["iron"]
|
||||||
|
expose-test-schema = []
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rustc-serialize = "0.3.19"
|
rustc-serialize = "0.3.19"
|
||||||
|
|
|
@ -11,15 +11,16 @@ use logger::Logger;
|
||||||
use iron::prelude::*;
|
use iron::prelude::*;
|
||||||
use juniper::FieldResult;
|
use juniper::FieldResult;
|
||||||
use juniper::iron_handlers::{GraphQLHandler, GraphiQLHandler};
|
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() {
|
fn main() {
|
||||||
let mut mount = Mount::new();
|
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");
|
let graphiql_endpoint = GraphiQLHandler::new("/graphql");
|
||||||
|
|
||||||
mount.mount("/", graphiql_endpoint);
|
mount.mount("/", graphiql_endpoint);
|
||||||
|
@ -35,24 +36,3 @@ fn main() {
|
||||||
println!("GraphQL server started on {}", host);
|
println!("GraphQL server started on {}", host);
|
||||||
Iron::new(chain).http(host.as_str()).unwrap();
|
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)
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
|
@ -185,8 +185,8 @@ mod schema;
|
||||||
pub mod validation;
|
pub mod validation;
|
||||||
mod integrations;
|
mod integrations;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(all(test, not(feature="expose-test-schema")))] mod tests;
|
||||||
mod tests;
|
#[cfg(feature="expose-test-schema")] pub mod tests;
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue