diff --git a/juniper_iron/CHANGELOG.md b/juniper_iron/CHANGELOG.md index 3faf475b..a71e67f3 100644 --- a/juniper_iron/CHANGELOG.md +++ b/juniper_iron/CHANGELOG.md @@ -1,3 +1,9 @@ +## [0.2.0] - 2018-05-10 + +### Changed + +* (**breaking**) `context_factory` should return `IronResult` instead of `Context` now. + ## [0.1.2] - 2018-02-10 ### Changed diff --git a/juniper_iron/examples/iron_server.rs b/juniper_iron/examples/iron_server.rs index 6ef250fa..884a9646 100644 --- a/juniper_iron/examples/iron_server.rs +++ b/juniper_iron/examples/iron_server.rs @@ -14,8 +14,8 @@ use juniper::EmptyMutation; use juniper_iron::{GraphQLHandler, GraphiQLHandler}; use juniper::tests::model::Database; -fn context_factory(_: &mut Request) -> Database { - Database::new() +fn context_factory(_: &mut Request) -> IronResult { + Ok(Database::new()) } fn main() { diff --git a/juniper_iron/src/lib.rs b/juniper_iron/src/lib.rs index 559ecf21..b6968d0a 100644 --- a/juniper_iron/src/lib.rs +++ b/juniper_iron/src/lib.rs @@ -62,8 +62,8 @@ use juniper::{Context, EmptyMutation}; // This function is executed for every request. Here, we would realistically // provide a database connection or similar. For this example, we'll be // creating the database from scratch. -fn context_factory(_: &mut Request) -> Database { - Database { +fn context_factory(_: &mut Request) -> IronResult { + Ok(Database { users: vec![ ( "1000".to_owned(), User { id: "1000".to_owned(), name: "Robin".to_owned(), @@ -72,7 +72,7 @@ fn context_factory(_: &mut Request) -> Database { id: "1001".to_owned(), name: "Max".to_owned(), friend_ids: vec!["1000".to_owned()] } ), ].into_iter().collect() - } + }) } impl Context for Database {} @@ -190,7 +190,7 @@ impl<'a> GraphQLBatchResponse<'a> { /// mapping. pub struct GraphQLHandler<'a, CtxFactory, Query, Mutation, CtxT> where - CtxFactory: Fn(&mut Request) -> CtxT + Send + Sync + 'static, + CtxFactory: Fn(&mut Request) -> IronResult + Send + Sync + 'static, CtxT: 'static, Query: GraphQLType + Send + Sync + 'static, Mutation: GraphQLType + Send + Sync + 'static, @@ -234,7 +234,7 @@ fn parse_variable_param(params: Option>) -> IronResult GraphQLHandler<'a, CtxFactory, Query, Mutation, CtxT> where - CtxFactory: Fn(&mut Request) -> CtxT + Send + Sync + 'static, + CtxFactory: Fn(&mut Request) -> IronResult + Send + Sync + 'static, CtxT: 'static, Query: GraphQLType + Send + Sync + 'static, Mutation: GraphQLType + Send + Sync + 'static, @@ -307,14 +307,14 @@ impl GraphiQLHandler { impl<'a, CtxFactory, Query, Mutation, CtxT> Handler for GraphQLHandler<'a, CtxFactory, Query, Mutation, CtxT> where - CtxFactory: Fn(&mut Request) -> CtxT + Send + Sync + 'static, + CtxFactory: Fn(&mut Request) -> IronResult + Send + Sync + 'static, CtxT: 'static, Query: GraphQLType + Send + Sync + 'static, Mutation: GraphQLType + Send + Sync + 'static, 'a: 'static, { fn handle(&self, mut req: &mut Request) -> IronResult { - let context = (self.context_factory)(req); + let context = (self.context_factory)(req)?; let graphql_request = match req.method { method::Get => self.handle_get(&mut req)?, @@ -439,8 +439,8 @@ mod tests { http_tests::run_http_test_suite(&integration); } - fn context_factory(_: &mut Request) -> Database { - Database::new() + fn context_factory(_: &mut Request) -> IronResult { + Ok(Database::new()) } fn make_test_response(response: IronResult) -> http_tests::TestResponse {