From 969f10020e4ad6c8379c0d973f7c945e523bca17 Mon Sep 17 00:00:00 2001 From: Daniel Wiesenberg Date: Mon, 31 Aug 2020 16:26:12 +0200 Subject: [PATCH 1/5] Add async Rocket integration --- Cargo.toml | 3 +- async-graphql-rocket/Cargo.toml | 22 ++++ async-graphql-rocket/src/lib.rs | 202 ++++++++++++++++++++++++++++++++ 3 files changed, 226 insertions(+), 1 deletion(-) create mode 100644 async-graphql-rocket/Cargo.toml create mode 100644 async-graphql-rocket/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index 9e40d29a..d8eb058c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -62,6 +62,7 @@ members = [ "async-graphql-actix-web", "async-graphql-warp", "async-graphql-tide", - # "async-graphql-lambda", + "async-graphql-rocket", +# "async-graphql-lambda", "benchmark", ] diff --git a/async-graphql-rocket/Cargo.toml b/async-graphql-rocket/Cargo.toml new file mode 100644 index 00000000..fafde900 --- /dev/null +++ b/async-graphql-rocket/Cargo.toml @@ -0,0 +1,22 @@ +[package] +name = "async-graphql-rocket" +version = "1.17.18" +authors = ["Daniel Wiesenberg "] +edition = "2018" +description = "async-graphql for Rocket.rs" +publish = true +license = "MIT/Apache-2.0" +documentation = "https://docs.rs/async-graphql/" +homepage = "https://github.com/async-graphql/async-graphql" +repository = "https://github.com/async-graphql/async-graphql" +keywords = ["futures", "async", "graphql", "rocket"] +categories = ["network-programming", "asynchronous"] + +[dependencies] +async-graphql = { path = "..", version = "1.17.18" } +rocket = { git = "https://github.com/SergioBenitez/Rocket/", default-features = false } +log = "0.4.11" +yansi = "0.5.0" +tokio-util = { version = "0.3.1", default-features = false, features = ["compat"] } +serde_json = "1.0.57" +serde_urlencoded = "0.6.1" diff --git a/async-graphql-rocket/src/lib.rs b/async-graphql-rocket/src/lib.rs new file mode 100644 index 00000000..e1361941 --- /dev/null +++ b/async-graphql-rocket/src/lib.rs @@ -0,0 +1,202 @@ +//! Async-graphql integration with Rocket + +#![warn(missing_docs)] +#![forbid(unsafe_code)] + +use async_graphql::{ + IntoQueryBuilder, IntoQueryBuilderOpts, QueryBuilder, QueryResponse, Schema, Variables, ObjectType, SubscriptionType +}; +use log::{error, info}; +use rocket::{ + Request, Response, State, + data::{Data, ToByteUnit}, + fairing::{AdHoc, Fairing}, + http::{ContentType, Header, Status, hyper::header::CACHE_CONTROL}, + request::{self, FromQuery, Outcome}, + response::{self, Responder, ResponseBuilder}, data::{self, FromData} +}; +use std::{io::Cursor, sync::Arc}; +use tokio_util::compat::Tokio02AsyncReadCompatExt; +use yansi::Paint; + + + +pub struct GraphQL; + +impl GraphQL +{ + pub fn fairing(schema: Schema) -> impl Fairing + where + Q: ObjectType + Send + Sync + 'static, + M: ObjectType + Send + Sync + 'static, + S: SubscriptionType + Send + Sync + 'static + { + GraphQL::attach(schema, Default::default()) + } + + pub fn fairing_with_opts(schema: Schema, opts: IntoQueryBuilderOpts) -> impl Fairing + where + Q: ObjectType + Send + Sync + 'static, + M: ObjectType + Send + Sync + 'static, + S: SubscriptionType + Send + Sync + 'static + { + GraphQL::attach(schema, opts) + } + + fn attach(schema: Schema, opts: IntoQueryBuilderOpts) -> impl Fairing + where + Q: ObjectType + Send + Sync + 'static, + M: ObjectType + Send + Sync + 'static, + S: SubscriptionType + Send + Sync + 'static + { + AdHoc::on_attach("GraphQL", move |rocket| async move { + let emoji = if cfg!(windows) {""} else {"📄 "}; + info!("{}{}", Paint::masked(emoji), Paint::magenta(format!("GraphQL {}:", Paint::blue(""))).wrap()); + + Ok(rocket.manage(schema) + .manage(Arc::new(opts)) + ) + }) + } +} + +pub struct GQLRequest(pub QueryBuilder); + +impl GQLRequest { + pub async fn execute(self, schema: &Schema) -> Result + where + Q: ObjectType + Send + Sync + 'static, + M: ObjectType + Send + Sync + 'static, + S: SubscriptionType + Send + Sync + 'static + { + self.0.execute(schema) + .await + .map(GQLResponse) + .map_err(|e| { + error!("{}", e); + Status::BadRequest + }) + } +} + +impl<'q> FromQuery<'q> for GQLRequest { + type Error = String; + + fn from_query(query_items: request::Query) -> Result { + let mut query = None; + let mut operation_name = None; + let mut variables = None; + + for query_item in query_items { + let (key, value) = query_item.key_value(); + match key.as_str() { + "query" => { + if query.is_some() { + return Err(r#"Multiple parameters named \"query\" found. Only one parameter by that name is allowed."#.to_string()); + } else { + query = value.url_decode() + .map_err(|e| e.to_string())? + .into(); + } + } + "operation_name" => { + if operation_name.is_some() { + return Err(r#"Multiple parameters named \"operation_name\" found. Only one parameter by that name is allowed."#.to_string()); + } else { + operation_name = value.url_decode() + .map_err(|e| e.to_string())? + .into(); + } + } + "variables" => { + if variables.is_some() { + return Err(r#"Multiple parameters named \"variables\" found. Only one parameter by that name is allowed."#.to_string()); + } else { + let decoded= value.url_decode() + .map_err(|e| e.to_string())?; + let json_value = serde_json::from_str::(&decoded) + .map_err(|e| e.to_string())?; + variables = Variables::parse_from_json(json_value) + .map_err(|e| e.to_string())? + .into(); + } + } + _ => { + return Err(format!(r#"Extra parameter named \"{}\" found. Extra parameters are not allowed."#, key)); + } + } + } + + if let Some(query_source) = query { + let mut builder = QueryBuilder::new(query_source); + + if let Some(variables) = variables { + builder = builder.variables(variables); + } + + if let Some(operation_name) = operation_name { + builder = builder.operation_name(operation_name); + } + + Ok(GQLRequest(builder)) + } else { + Err(r#"Parameter "query" missing from request."#.to_string()) + } + } +} + +#[rocket::async_trait] +impl FromData for GQLRequest { + type Error = String; + + async fn from_data(req: &Request<'_>, data: Data) -> data::Outcome { + let opts = match req.guard::>>().await { + Outcome::Success(opts) => opts, + Outcome::Failure(_) => return data::Outcome::Failure((Status::InternalServerError, "Missing IntoQueryBuilderOpts in State".to_string())), + Outcome::Forward(()) => unreachable!(), + }; + + let stream = data.open(100.kibibytes()); + let builder = (req.headers().get_one("Content-Type"), stream.compat()) + .into_query_builder_opts(&opts) + .await; + + match builder { + Ok(builder) => data::Outcome::Success(GQLRequest(builder)), + Err(e) => data::Outcome::Failure((Status::BadRequest, format!("{}", e))), + } + } +} + +pub struct GQLResponse(pub QueryResponse); + +impl<'r> Responder<'r, 'static> for GQLResponse { + fn respond_to(self, _: &'r Request<'_>) -> response::Result<'static> { + let gql_resp = async_graphql::http::GQLResponse(Ok(self.0)); + let body = serde_json::to_string(&gql_resp).unwrap(); + + Response::build() + .header(ContentType::new("application", "json")) + .status(Status::Ok) + .sized_body(body.len(), Cursor::new(body)) + .cache_control(&gql_resp.0) + .ok() + } +} + +/// Extension trait, to allow the use of `cache_control` with for example `ResponseBuilder`. +pub trait CacheControl{ + /// Add the `async-graphql::query::QueryResponse` cache control value as header to the Rocket response. + fn cache_control(&mut self, resp: &async_graphql::Result) -> &mut Self; +} + +impl<'r> CacheControl for ResponseBuilder<'r> { + fn cache_control(&mut self, resp: &async_graphql::Result) -> &mut ResponseBuilder<'r> { + match resp { + Ok(resp) if resp.cache_control.value().is_some() => { + self.header(Header::new(CACHE_CONTROL.as_str(), resp.cache_control.value().unwrap())) + } + _ => self, + } + } +} From b07602d4992c771838a131cf65aa47c41ca4172c Mon Sep 17 00:00:00 2001 From: Daniel Wiesenberg Date: Thu, 3 Sep 2020 19:51:45 +0200 Subject: [PATCH 2/5] Add docs for Rocket integration --- async-graphql-rocket/Cargo.toml | 7 +-- async-graphql-rocket/src/lib.rs | 99 +++++++++++++++++++++++++++++++-- 2 files changed, 96 insertions(+), 10 deletions(-) diff --git a/async-graphql-rocket/Cargo.toml b/async-graphql-rocket/Cargo.toml index fafde900..9e1b28a4 100644 --- a/async-graphql-rocket/Cargo.toml +++ b/async-graphql-rocket/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "async-graphql-rocket" -version = "1.17.18" +version = "1.17.21" authors = ["Daniel Wiesenberg "] edition = "2018" description = "async-graphql for Rocket.rs" @@ -13,10 +13,9 @@ keywords = ["futures", "async", "graphql", "rocket"] categories = ["network-programming", "asynchronous"] [dependencies] -async-graphql = { path = "..", version = "1.17.18" } -rocket = { git = "https://github.com/SergioBenitez/Rocket/", default-features = false } +async-graphql = { path = "..", version = "1.17.21" } +rocket = { git = "https://github.com/SergioBenitez/Rocket/", rev = "dc2c6ec", default-features = false } #TODO: Change to Cargo crate, when Rocket 0.5.0 is released log = "0.4.11" yansi = "0.5.0" tokio-util = { version = "0.3.1", default-features = false, features = ["compat"] } serde_json = "1.0.57" -serde_urlencoded = "0.6.1" diff --git a/async-graphql-rocket/src/lib.rs b/async-graphql-rocket/src/lib.rs index e1361941..2afdadc4 100644 --- a/async-graphql-rocket/src/lib.rs +++ b/async-graphql-rocket/src/lib.rs @@ -20,11 +20,63 @@ use tokio_util::compat::Tokio02AsyncReadCompatExt; use yansi::Paint; - +/// Contains the fairing functions, to attach GraphQL with the desired `Schema`, and optionally +/// `QueryBuilderOpts`, to Rocket. +/// +/// # Examples +/// **[Full Example]()** +/// +/// ```rust,no_run +/// +/// use async_graphql::*; +/// use async_graphql_rocket::{GQLRequest, GraphQL, GQLResponse}; +/// use rocket::{response::content, routes, State, http::Status}; +/// +/// type ExampleSchema = Schema; +/// struct QueryRoot; +/// +/// #[Object] +/// impl QueryRoot { +/// #[field(desc = "Returns the sum of a and b")] +/// async fn add(&self, a: i32, b: i32) -> i32 { +/// a + b +/// } +/// } +/// +/// #[rocket::post("/?")] +/// async fn graphql_query(schema: State<'_, ExampleSchema>, query: GQLRequest) -> Result { +/// query.execute(&schema) +/// .await +/// } +/// +/// #[rocket::post("/", data = "", format = "application/json")] +/// async fn graphql_request(schema: State<'_, ExampleSchema>, request: GQLRequest) -> Result { +/// request.execute(&schema) +/// .await +/// } +/// +/// #[rocket::launch] +/// fn rocket() -> rocket::Rocket { +/// let schema = Schema::new(QueryRoot, EmptyMutation, EmptySubscription); +/// rocket::ignite() +/// .attach(GraphQL::fairing(schema)) +/// .mount("/", routes![graphql_query, graphql_request]) +/// } +/// ``` pub struct GraphQL; impl GraphQL { + /// Fairing with default `QueryBuilderOpts`. You just need to pass in your `Schema` and then can + /// attach the `Fairing` to Rocket. + /// + /// # Examples + /// + /// ```rust,no_run + /// rocket::ignite() + /// .attach(GraphQL::fairing(schema)) + /// .mount("/", routes![graphql_query, graphql_request]) + /// ``` pub fn fairing(schema: Schema) -> impl Fairing where Q: ObjectType + Send + Sync + 'static, @@ -34,6 +86,17 @@ impl GraphQL GraphQL::attach(schema, Default::default()) } + /// Fairing to which you need to pass `QueryBuilderOpts` and your `Schema`. Then you can + /// attach the `Fairing` to Rocket. + /// + /// # Examples + /// + /// ```rust,no_run + /// let opts: IntoQueryBuilderOpts = Default::default(); + /// rocket::ignite() + /// .attach(GraphQL::fairing_with_opts(schema, opts)) + /// .mount("/", routes![graphql_query, graphql_request]) + /// ``` pub fn fairing_with_opts(schema: Schema, opts: IntoQueryBuilderOpts) -> impl Fairing where Q: ObjectType + Send + Sync + 'static, @@ -60,9 +123,29 @@ impl GraphQL } } +/// Implements `FromQuery` and `FromData`, so that it can be used as parameter in a +/// Rocket route. +/// +/// # Examples +/// +/// ```rust,no_run +/// #[rocket::post("/?")] +/// async fn graphql_query(schema: State<'_, ExampleSchema>, query: GQLRequest) -> Result { +/// query.execute(&schema) +/// .await +/// } +/// +/// #[rocket::post("/", data = "", format = "application/json")] +/// async fn graphql_request(schema: State<'_, ExampleSchema>, request: GQLRequest) -> Result { +/// request.execute(&schema) +/// .await +/// } +/// ``` pub struct GQLRequest(pub QueryBuilder); impl GQLRequest { + /// Mimics `async_graphqlquery::QueryBuilder.execute()`. + /// Executes the query, always return a complete result. pub async fn execute(self, schema: &Schema) -> Result where Q: ObjectType + Send + Sync + 'static, @@ -92,7 +175,7 @@ impl<'q> FromQuery<'q> for GQLRequest { match key.as_str() { "query" => { if query.is_some() { - return Err(r#"Multiple parameters named \"query\" found. Only one parameter by that name is allowed."#.to_string()); + return Err(r#"Multiple parameters named "query" found. Only one parameter by that name is allowed."#.to_string()); } else { query = value.url_decode() .map_err(|e| e.to_string())? @@ -101,7 +184,7 @@ impl<'q> FromQuery<'q> for GQLRequest { } "operation_name" => { if operation_name.is_some() { - return Err(r#"Multiple parameters named \"operation_name\" found. Only one parameter by that name is allowed."#.to_string()); + return Err(r#"Multiple parameters named "operation_name" found. Only one parameter by that name is allowed."#.to_string()); } else { operation_name = value.url_decode() .map_err(|e| e.to_string())? @@ -110,7 +193,7 @@ impl<'q> FromQuery<'q> for GQLRequest { } "variables" => { if variables.is_some() { - return Err(r#"Multiple parameters named \"variables\" found. Only one parameter by that name is allowed."#.to_string()); + return Err(r#"Multiple parameters named "variables" found. Only one parameter by that name is allowed."#.to_string()); } else { let decoded= value.url_decode() .map_err(|e| e.to_string())?; @@ -122,7 +205,7 @@ impl<'q> FromQuery<'q> for GQLRequest { } } _ => { - return Err(format!(r#"Extra parameter named \"{}\" found. Extra parameters are not allowed."#, key)); + return Err(format!(r#"Extra parameter named "{}" found. Extra parameters are not allowed."#, key)); } } } @@ -156,7 +239,8 @@ impl FromData for GQLRequest { Outcome::Forward(()) => unreachable!(), }; - let stream = data.open(100.kibibytes()); + let limit = req.limits().get("graphql"); + let stream = data.open(limit.unwrap_or_else(|| 128.kibibytes())); let builder = (req.headers().get_one("Content-Type"), stream.compat()) .into_query_builder_opts(&opts) .await; @@ -168,6 +252,9 @@ impl FromData for GQLRequest { } } +/// Wrapper around `async-graphql::query::QueryResponse` for implementing the trait +/// `rocket::response::responder::Responder`, so that `GQLResponse` can directly be returned +/// from a Rocket Route function. pub struct GQLResponse(pub QueryResponse); impl<'r> Responder<'r, 'static> for GQLResponse { From fdfda1a4467cf2a98d0547a18dfb98a81ee10521 Mon Sep 17 00:00:00 2001 From: Daniel Wiesenberg Date: Fri, 4 Sep 2020 11:50:24 +0200 Subject: [PATCH 3/5] Run cargo fmt --- async-graphql-rocket/src/lib.rs | 87 ++++++++++++++++++--------------- 1 file changed, 48 insertions(+), 39 deletions(-) diff --git a/async-graphql-rocket/src/lib.rs b/async-graphql-rocket/src/lib.rs index 2afdadc4..ccb7f3a5 100644 --- a/async-graphql-rocket/src/lib.rs +++ b/async-graphql-rocket/src/lib.rs @@ -4,22 +4,23 @@ #![forbid(unsafe_code)] use async_graphql::{ - IntoQueryBuilder, IntoQueryBuilderOpts, QueryBuilder, QueryResponse, Schema, Variables, ObjectType, SubscriptionType + IntoQueryBuilder, IntoQueryBuilderOpts, ObjectType, QueryBuilder, QueryResponse, Schema, + SubscriptionType, Variables, }; use log::{error, info}; use rocket::{ - Request, Response, State, + data::{self, FromData}, data::{Data, ToByteUnit}, fairing::{AdHoc, Fairing}, - http::{ContentType, Header, Status, hyper::header::CACHE_CONTROL}, + http::{hyper::header::CACHE_CONTROL, ContentType, Header, Status}, request::{self, FromQuery, Outcome}, - response::{self, Responder, ResponseBuilder}, data::{self, FromData} + response::{self, Responder, ResponseBuilder}, + Request, Response, State, }; use std::{io::Cursor, sync::Arc}; use tokio_util::compat::Tokio02AsyncReadCompatExt; use yansi::Paint; - /// Contains the fairing functions, to attach GraphQL with the desired `Schema`, and optionally /// `QueryBuilderOpts`, to Rocket. /// @@ -65,8 +66,7 @@ use yansi::Paint; /// ``` pub struct GraphQL; -impl GraphQL -{ +impl GraphQL { /// Fairing with default `QueryBuilderOpts`. You just need to pass in your `Schema` and then can /// attach the `Fairing` to Rocket. /// @@ -81,7 +81,7 @@ impl GraphQL where Q: ObjectType + Send + Sync + 'static, M: ObjectType + Send + Sync + 'static, - S: SubscriptionType + Send + Sync + 'static + S: SubscriptionType + Send + Sync + 'static, { GraphQL::attach(schema, Default::default()) } @@ -97,11 +97,14 @@ impl GraphQL /// .attach(GraphQL::fairing_with_opts(schema, opts)) /// .mount("/", routes![graphql_query, graphql_request]) /// ``` - pub fn fairing_with_opts(schema: Schema, opts: IntoQueryBuilderOpts) -> impl Fairing + pub fn fairing_with_opts( + schema: Schema, + opts: IntoQueryBuilderOpts, + ) -> impl Fairing where Q: ObjectType + Send + Sync + 'static, M: ObjectType + Send + Sync + 'static, - S: SubscriptionType + Send + Sync + 'static + S: SubscriptionType + Send + Sync + 'static, { GraphQL::attach(schema, opts) } @@ -110,15 +113,17 @@ impl GraphQL where Q: ObjectType + Send + Sync + 'static, M: ObjectType + Send + Sync + 'static, - S: SubscriptionType + Send + Sync + 'static + S: SubscriptionType + Send + Sync + 'static, { AdHoc::on_attach("GraphQL", move |rocket| async move { - let emoji = if cfg!(windows) {""} else {"📄 "}; - info!("{}{}", Paint::masked(emoji), Paint::magenta(format!("GraphQL {}:", Paint::blue(""))).wrap()); + let emoji = if cfg!(windows) { "" } else { "📄 " }; + info!( + "{}{}", + Paint::masked(emoji), + Paint::magenta(format!("GraphQL {}:", Paint::blue(""))).wrap() + ); - Ok(rocket.manage(schema) - .manage(Arc::new(opts)) - ) + Ok(rocket.manage(schema).manage(Arc::new(opts))) }) } } @@ -150,15 +155,12 @@ impl GQLRequest { where Q: ObjectType + Send + Sync + 'static, M: ObjectType + Send + Sync + 'static, - S: SubscriptionType + Send + Sync + 'static + S: SubscriptionType + Send + Sync + 'static, { - self.0.execute(schema) - .await - .map(GQLResponse) - .map_err(|e| { - error!("{}", e); - Status::BadRequest - }) + self.0.execute(schema).await.map(GQLResponse).map_err(|e| { + error!("{}", e); + Status::BadRequest + }) } } @@ -177,26 +179,21 @@ impl<'q> FromQuery<'q> for GQLRequest { if query.is_some() { return Err(r#"Multiple parameters named "query" found. Only one parameter by that name is allowed."#.to_string()); } else { - query = value.url_decode() - .map_err(|e| e.to_string())? - .into(); + query = value.url_decode().map_err(|e| e.to_string())?.into(); } } "operation_name" => { if operation_name.is_some() { return Err(r#"Multiple parameters named "operation_name" found. Only one parameter by that name is allowed."#.to_string()); } else { - operation_name = value.url_decode() - .map_err(|e| e.to_string())? - .into(); + operation_name = value.url_decode().map_err(|e| e.to_string())?.into(); } } "variables" => { if variables.is_some() { return Err(r#"Multiple parameters named "variables" found. Only one parameter by that name is allowed."#.to_string()); } else { - let decoded= value.url_decode() - .map_err(|e| e.to_string())?; + let decoded = value.url_decode().map_err(|e| e.to_string())?; let json_value = serde_json::from_str::(&decoded) .map_err(|e| e.to_string())?; variables = Variables::parse_from_json(json_value) @@ -205,7 +202,10 @@ impl<'q> FromQuery<'q> for GQLRequest { } } _ => { - return Err(format!(r#"Extra parameter named "{}" found. Extra parameters are not allowed."#, key)); + return Err(format!( + r#"Extra parameter named "{}" found. Extra parameters are not allowed."#, + key + )); } } } @@ -235,7 +235,12 @@ impl FromData for GQLRequest { async fn from_data(req: &Request<'_>, data: Data) -> data::Outcome { let opts = match req.guard::>>().await { Outcome::Success(opts) => opts, - Outcome::Failure(_) => return data::Outcome::Failure((Status::InternalServerError, "Missing IntoQueryBuilderOpts in State".to_string())), + Outcome::Failure(_) => { + return data::Outcome::Failure(( + Status::InternalServerError, + "Missing IntoQueryBuilderOpts in State".to_string(), + )) + } Outcome::Forward(()) => unreachable!(), }; @@ -272,17 +277,21 @@ impl<'r> Responder<'r, 'static> for GQLResponse { } /// Extension trait, to allow the use of `cache_control` with for example `ResponseBuilder`. -pub trait CacheControl{ +pub trait CacheControl { /// Add the `async-graphql::query::QueryResponse` cache control value as header to the Rocket response. fn cache_control(&mut self, resp: &async_graphql::Result) -> &mut Self; } impl<'r> CacheControl for ResponseBuilder<'r> { - fn cache_control(&mut self, resp: &async_graphql::Result) -> &mut ResponseBuilder<'r> { + fn cache_control( + &mut self, + resp: &async_graphql::Result, + ) -> &mut ResponseBuilder<'r> { match resp { - Ok(resp) if resp.cache_control.value().is_some() => { - self.header(Header::new(CACHE_CONTROL.as_str(), resp.cache_control.value().unwrap())) - } + Ok(resp) if resp.cache_control.value().is_some() => self.header(Header::new( + CACHE_CONTROL.as_str(), + resp.cache_control.value().unwrap(), + )), _ => self, } } From aeaf3c7811d2e8ef756344a682676c7dc391b3ec Mon Sep 17 00:00:00 2001 From: Daniel Wiesenberg Date: Fri, 4 Sep 2020 12:01:16 +0200 Subject: [PATCH 4/5] Make Clippy happy --- async-graphql-rocket/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/async-graphql-rocket/src/lib.rs b/async-graphql-rocket/src/lib.rs index ccb7f3a5..9e558121 100644 --- a/async-graphql-rocket/src/lib.rs +++ b/async-graphql-rocket/src/lib.rs @@ -12,7 +12,7 @@ use rocket::{ data::{self, FromData}, data::{Data, ToByteUnit}, fairing::{AdHoc, Fairing}, - http::{hyper::header::CACHE_CONTROL, ContentType, Header, Status}, + http::{ContentType, Header, Status}, request::{self, FromQuery, Outcome}, response::{self, Responder, ResponseBuilder}, Request, Response, State, @@ -289,7 +289,7 @@ impl<'r> CacheControl for ResponseBuilder<'r> { ) -> &mut ResponseBuilder<'r> { match resp { Ok(resp) if resp.cache_control.value().is_some() => self.header(Header::new( - CACHE_CONTROL.as_str(), + "cache-control", resp.cache_control.value().unwrap(), )), _ => self, From b119fbe2df727c9a8359b78a8ec272c54dfc3386 Mon Sep 17 00:00:00 2001 From: Daniel Wiesenberg Date: Fri, 4 Sep 2020 12:48:41 +0200 Subject: [PATCH 5/5] Fix docs --- async-graphql-rocket/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/async-graphql-rocket/src/lib.rs b/async-graphql-rocket/src/lib.rs index 9e558121..41e148b1 100644 --- a/async-graphql-rocket/src/lib.rs +++ b/async-graphql-rocket/src/lib.rs @@ -29,7 +29,7 @@ use yansi::Paint; /// /// ```rust,no_run /// -/// use async_graphql::*; +/// use async_graphql::{EmptyMutation, EmptySubscription, Schema}; /// use async_graphql_rocket::{GQLRequest, GraphQL, GQLResponse}; /// use rocket::{response::content, routes, State, http::Status}; /// @@ -72,7 +72,7 @@ impl GraphQL { /// /// # Examples /// - /// ```rust,no_run + /// ```rust,no_run,ignore /// rocket::ignite() /// .attach(GraphQL::fairing(schema)) /// .mount("/", routes![graphql_query, graphql_request]) @@ -91,7 +91,7 @@ impl GraphQL { /// /// # Examples /// - /// ```rust,no_run + /// ```rust,no_run,ignore /// let opts: IntoQueryBuilderOpts = Default::default(); /// rocket::ignite() /// .attach(GraphQL::fairing_with_opts(schema, opts)) @@ -133,7 +133,7 @@ impl GraphQL { /// /// # Examples /// -/// ```rust,no_run +/// ```rust,no_run,ignore /// #[rocket::post("/?")] /// async fn graphql_query(schema: State<'_, ExampleSchema>, query: GQLRequest) -> Result { /// query.execute(&schema)