diff --git a/juniper_rocket/CHANGELOG.md b/juniper_rocket/CHANGELOG.md index 5d6305c2..1e9f2e9f 100644 --- a/juniper_rocket/CHANGELOG.md +++ b/juniper_rocket/CHANGELOG.md @@ -1,5 +1,14 @@ # [master] +### Rocket updated to v0.4 + +[Rocket](https://rocket.rs) integration now requires Rocket `0.4.0`. This is due +to changes with the way Rocket handles form parsing. Before this update, it was +impossible to leverage Rocket integration with Rocket beyond 0.3.x. + +Check out [Rocket's Changelog](https://github.com/SergioBenitez/Rocket/blob/v0.4/CHANGELOG.md) +for more details on the 0.4 release. + # juniper_rocket [0.1.3] 2018-09-13 - Add `juniper-0.10.0` compatibility. diff --git a/juniper_rocket/Cargo.toml b/juniper_rocket/Cargo.toml index f08611fd..b2450ebc 100644 --- a/juniper_rocket/Cargo.toml +++ b/juniper_rocket/Cargo.toml @@ -16,8 +16,7 @@ serde_json = { version = "1.0.2" } serde_derive = { version = "1.0.2" } juniper = { version = ">=0.9, 0.10.0" , default-features = false, path = "../juniper"} -rocket = { version = "0.3.9" } -rocket_codegen = { version = "0.3.9" } +rocket = { version = "0.4.0" } [dev-dependencies.juniper] version = "0.10.0" diff --git a/juniper_rocket/examples/rocket_server.rs b/juniper_rocket/examples/rocket_server.rs index 28dbb29d..ef9c7010 100644 --- a/juniper_rocket/examples/rocket_server.rs +++ b/juniper_rocket/examples/rocket_server.rs @@ -1,9 +1,8 @@ -#![feature(plugin)] -#![plugin(rocket_codegen)] +#![feature(decl_macro, proc_macro_hygiene)] extern crate juniper; extern crate juniper_rocket; -extern crate rocket; +#[macro_use] extern crate rocket; use rocket::response::content; use rocket::State; diff --git a/juniper_rocket/src/lib.rs b/juniper_rocket/src/lib.rs index a5aa9f90..9c624a51 100644 --- a/juniper_rocket/src/lib.rs +++ b/juniper_rocket/src/lib.rs @@ -36,8 +36,7 @@ Check the LICENSE file for details. */ -#![feature(plugin)] -#![plugin(rocket_codegen)] +#![feature(decl_macro, proc_macro_hygiene)] extern crate juniper; extern crate rocket; @@ -48,9 +47,9 @@ extern crate serde_derive; use std::error::Error; use std::io::{Cursor, Read}; -use rocket::data::{FromData, Outcome as FromDataOutcome}; -use rocket::http::{ContentType, Status}; -use rocket::request::{FormItems, FromForm}; +use rocket::data::{FromDataSimple, Outcome as FromDataOutcome}; +use rocket::http::{ContentType, RawStr, Status}; +use rocket::request::{FormItems, FromForm, FromFormValue}; use rocket::response::{content, Responder, Response}; use rocket::Data; use rocket::Outcome::{Failure, Forward, Success}; @@ -181,14 +180,14 @@ impl GraphQLResponse { /// # Examples /// /// ``` - /// # #![feature(plugin)] - /// # #![plugin(rocket_codegen)] + /// # #![feature(decl_macro, proc_macro_hygiene)] /// # /// # extern crate juniper; /// # extern crate juniper_rocket; - /// # extern crate rocket; + /// # #[macro_use] extern crate rocket; /// # /// # use rocket::http::Cookies; + /// # use rocket::request::Form; /// # use rocket::response::content; /// # use rocket::State; /// # @@ -197,11 +196,11 @@ impl GraphQLResponse { /// # /// # type Schema = RootNode<'static, Database, EmptyMutation>; /// # - /// #[get("/graphql?")] + /// #[get("/graphql?")] /// fn get_graphql_handler( /// mut cookies: Cookies, /// context: State, - /// request: juniper_rocket::GraphQLRequest, + /// request: Form, /// schema: State, /// ) -> juniper_rocket::GraphQLResponse { /// if cookies.get_private("user_id").is_none() { @@ -240,7 +239,8 @@ where let mut operation_name = None; let mut variables = None; - for (key, value) in form_items { + for form_item in form_items { + let (key, value) = form_item.key_value(); // Note: we explicitly decode in the match arms to save work rather // than decoding every form item blindly. match key.as_str() { @@ -299,7 +299,19 @@ where } } -impl FromData for GraphQLRequest +impl<'v, S> FromFormValue<'v> for GraphQLRequest + where S: ScalarValue +{ + type Error = String; + + fn from_form_value(form_value: &'v RawStr) -> Result { + let mut form_items = FormItems::from(form_value); + + Self::from_form(&mut form_items, true) + } +} + +impl FromDataSimple for GraphQLRequest where S: ScalarValue, { @@ -447,7 +459,8 @@ mod fromform_tests { #[cfg(test)] mod tests { - use rocket; + use rocket::{self, get, post, routes}; + use rocket::request::Form; use rocket::http::ContentType; use rocket::local::{Client, LocalRequest}; use rocket::Rocket; @@ -460,10 +473,10 @@ mod tests { type Schema = RootNode<'static, Database, EmptyMutation>; - #[get("/?")] + #[get("/?")] fn get_graphql_handler( context: State, - request: super::GraphQLRequest, + request: Form, schema: State, ) -> super::GraphQLResponse { request.execute(&schema, &context) @@ -512,8 +525,8 @@ mod tests { )).mount("/", routes![post_graphql_handler, get_graphql_handler]) } - fn make_test_response<'r>(request: &LocalRequest<'r>) -> http_tests::TestResponse { - let mut response = request.cloned_dispatch(); + fn make_test_response(request: &LocalRequest) -> http_tests::TestResponse { + let mut response = request.clone().dispatch(); let status_code = response.status().code as i32; let content_type = response .content_type() @@ -525,9 +538,9 @@ mod tests { .into_string(); http_tests::TestResponse { - status_code: status_code, - body: body, - content_type: content_type, + status_code, + body, + content_type, } } }