From 5bb705bdf3837facc0f1f4689ce8c59890c2e7c2 Mon Sep 17 00:00:00 2001 From: Sunli Date: Mon, 14 Sep 2020 09:46:22 +0800 Subject: [PATCH] 2.0.0-alpha.5 --- .github/workflows/code-coverage.yml | 2 +- Cargo.toml | 6 ++--- benchmark/Cargo.toml | 2 +- benchmark/chat/Cargo.toml | 2 +- benchmark/simple/Cargo.toml | 2 +- derive/Cargo.toml | 4 ++-- integrations/actix-web/Cargo.toml | 4 ++-- integrations/actix-web/src/subscription.rs | 6 ++--- integrations/rocket/Cargo.toml | 4 ++-- integrations/tide/Cargo.toml | 4 ++-- integrations/warp/Cargo.toml | 4 ++-- integrations/warp/src/lib.rs | 9 ++++---- parser/Cargo.toml | 2 +- src/http/multipart.rs | 4 ++-- src/lib.rs | 8 +++---- src/resolver_utils/enum.rs | 14 +++++++----- src/resolver_utils/mod.rs | 2 +- src/response.rs | 5 +---- src/schema.rs | 7 ++---- src/types/empty_subscription.rs | 4 +--- src/types/external/mod.rs | 10 ++++----- src/types/merged_object.rs | 26 ++++++++-------------- src/types/mod.rs | 8 +++---- src/types/query_root.rs | 4 ++-- tests/field_features.rs | 5 ++++- 25 files changed, 67 insertions(+), 81 deletions(-) diff --git a/.github/workflows/code-coverage.yml b/.github/workflows/code-coverage.yml index 79aede5f..5005bf37 100644 --- a/.github/workflows/code-coverage.yml +++ b/.github/workflows/code-coverage.yml @@ -21,7 +21,7 @@ jobs: - name: Run cargo-tarpaulin uses: actions-rs/tarpaulin@v0.1 with: - version: '0.11.0' + version: '0.14.3' args: --out Xml --all --all-features - name: Upload to codecov.io uses: codecov/codecov-action@v1.0.2 diff --git a/Cargo.toml b/Cargo.toml index 51295c00..79923f7a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "async-graphql" -version = "2.0.0-alpha.4" +version = "2.0.0-alpha.5" authors = ["sunli "] edition = "2018" description = "A GraphQL server library implemented in Rust" @@ -17,8 +17,8 @@ readme = "README.md" default = ["bson", "url", "chrono-tz"] [dependencies] -async-graphql-derive = { path = "derive", version = "2.0.0-alpha.4" } -async-graphql-parser = { path = "parser", version = "2.0.0-alpha.4" } +async-graphql-derive = { path = "derive", version = "2.0.0-alpha.5" } +async-graphql-parser = { path = "parser", version = "2.0.0-alpha.5" } async-stream = "0.3" async-trait = "0.1.30" diff --git a/benchmark/Cargo.toml b/benchmark/Cargo.toml index a42b5cc5..f7e2e874 100644 --- a/benchmark/Cargo.toml +++ b/benchmark/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "graphql-benchmark" -version = "2.0.0-alpha.4" +version = "2.0.0-alpha.5" authors = ["sunli "] edition = "2018" diff --git a/benchmark/chat/Cargo.toml b/benchmark/chat/Cargo.toml index 2a3ee9d8..dcc3f453 100644 --- a/benchmark/chat/Cargo.toml +++ b/benchmark/chat/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "chat" -version = "2.0.0-alpha.4" +version = "2.0.0-alpha.5" authors = ["Ivan Plesskih "] edition = "2018" diff --git a/benchmark/simple/Cargo.toml b/benchmark/simple/Cargo.toml index 8ed688b2..15e5490d 100644 --- a/benchmark/simple/Cargo.toml +++ b/benchmark/simple/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "simple" -version = "2.0.0-alpha.4" +version = "2.0.0-alpha.5" authors = ["Ivan Plesskih "] edition = "2018" diff --git a/derive/Cargo.toml b/derive/Cargo.toml index 09f223f9..771c3240 100644 --- a/derive/Cargo.toml +++ b/derive/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "async-graphql-derive" -version = "2.0.0-alpha.4" +version = "2.0.0-alpha.5" authors = ["sunli "] edition = "2018" description = "Macros for async-graphql" @@ -16,7 +16,7 @@ categories = ["network-programming", "asynchronous"] proc-macro = true [dependencies] -async-graphql-parser = { path = "../parser", version = "2.0.0-alpha.4" } +async-graphql-parser = { path = "../parser", version = "2.0.0-alpha.5" } proc-macro2 = "1.0.6" syn = { version = "1.0.20", features = ["full", "extra-traits"] } quote = "1.0.3" diff --git a/integrations/actix-web/Cargo.toml b/integrations/actix-web/Cargo.toml index 5cb89c96..4bb9cc0b 100644 --- a/integrations/actix-web/Cargo.toml +++ b/integrations/actix-web/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "async-graphql-actix-web" -version = "2.0.0-alpha.4" +version = "2.0.0-alpha.5" authors = ["sunli "] edition = "2018" description = "async-graphql for actix-web" @@ -13,7 +13,7 @@ keywords = ["futures", "async", "graphql"] categories = ["network-programming", "asynchronous"] [dependencies] -async-graphql = { path = "../..", version = "2.0.0-alpha.4" } +async-graphql = { path = "../..", version = "2.0.0-alpha.5" } actix-web = "3.0.0" actix-web-actors = "3.0.0" actix = "0.10.0" diff --git a/integrations/actix-web/src/subscription.rs b/integrations/actix-web/src/subscription.rs index 49643232..acb50aba 100644 --- a/integrations/actix-web/src/subscription.rs +++ b/integrations/actix-web/src/subscription.rs @@ -66,10 +66,8 @@ where fn started(&mut self, ctx: &mut Self::Context) { self.hb(ctx); if let Some(initializer) = self.initializer.take() { - let (sink, stream) = async_graphql::http::websocket::create_with_initializer( - &self.schema, - initializer, - ); + let (sink, stream) = + async_graphql::http::websocket::create_with_initializer(&self.schema, initializer); ctx.add_stream(stream); self.sink = Some(sink); } else { diff --git a/integrations/rocket/Cargo.toml b/integrations/rocket/Cargo.toml index 5490b6b1..09ab131a 100644 --- a/integrations/rocket/Cargo.toml +++ b/integrations/rocket/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "async-graphql-rocket" -version = "2.0.0-alpha.4" +version = "2.0.0-alpha.5" authors = ["Daniel Wiesenberg "] edition = "2018" description = "async-graphql for Rocket.rs" @@ -14,7 +14,7 @@ keywords = ["futures", "async", "graphql", "rocket"] categories = ["network-programming", "asynchronous"] [dependencies] -async-graphql = { path = "../..", version = "2.0.0-alpha.4" } +async-graphql = { path = "../..", version = "2.0.0-alpha.5" } 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" diff --git a/integrations/tide/Cargo.toml b/integrations/tide/Cargo.toml index 5e2c33af..59e3fd8f 100644 --- a/integrations/tide/Cargo.toml +++ b/integrations/tide/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "async-graphql-tide" -version = "2.0.0-alpha.4" +version = "2.0.0-alpha.5" authors = ["vkill "] edition = "2018" description = "async-graphql for tide" @@ -13,7 +13,7 @@ keywords = ["futures", "async", "graphql"] categories = ["network-programming", "asynchronous"] [dependencies] -async-graphql = { path = "../..", version = "2.0.0-alpha.4" } +async-graphql = { path = "../..", version = "2.0.0-alpha.5" } tide = "0.13.0" async-trait = "0.1.36" serde_json = "1.0.56" diff --git a/integrations/warp/Cargo.toml b/integrations/warp/Cargo.toml index 479fe225..f6597413 100644 --- a/integrations/warp/Cargo.toml +++ b/integrations/warp/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "async-graphql-warp" -version = "2.0.0-alpha.4" +version = "2.0.0-alpha.5" authors = ["sunli "] edition = "2018" description = "async-graphql for warp" @@ -13,7 +13,7 @@ keywords = ["futures", "async", "graphql"] categories = ["network-programming", "asynchronous"] [dependencies] -async-graphql = { path = "../..", version = "2.0.0-alpha.4" } +async-graphql = { path = "../..", version = "2.0.0-alpha.5" } warp = "0.2.2" futures = "0.3.0" bytes = "0.5.4" diff --git a/integrations/warp/src/lib.rs b/integrations/warp/src/lib.rs index f32d48e6..e4b88fbe 100644 --- a/integrations/warp/src/lib.rs +++ b/integrations/warp/src/lib.rs @@ -199,11 +199,10 @@ where |ws: warp::ws::Ws, schema: Schema, initializer: F| { ws.on_upgrade(move |websocket| { let (mut tx, rx) = websocket.split(); - let (mut stx, srx) = - async_graphql::http::websocket::create_with_initializer( - &schema, - initializer, - ); + let (mut stx, srx) = async_graphql::http::websocket::create_with_initializer( + &schema, + initializer, + ); let mut rx = rx.fuse(); let srx = srx.fuse(); diff --git a/parser/Cargo.toml b/parser/Cargo.toml index 74da9f4b..9bc1039f 100644 --- a/parser/Cargo.toml +++ b/parser/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "async-graphql-parser" -version = "2.0.0-alpha.4" +version = "2.0.0-alpha.5" authors = ["sunli "] edition = "2018" description = "GraphQL query parser for async-graphql" diff --git a/src/http/multipart.rs b/src/http/multipart.rs index ddcc43ff..d0952b79 100644 --- a/src/http/multipart.rs +++ b/src/http/multipart.rs @@ -3,11 +3,11 @@ use bytes::Bytes; use futures::io::AsyncRead; use futures::stream::Stream; use multer::{Constraints, Multipart, SizeLimit}; +use pin_project_lite::pin_project; use std::collections::HashMap; use std::io::{self, Seek, SeekFrom, Write}; use std::pin::Pin; use std::task::{Context, Poll}; -use pin_project_lite::pin_project; /// Options for `receive_multipart`. #[derive(Default, Clone)] @@ -143,7 +143,7 @@ impl Stream for ReaderStream { match futures::ready!(this.reader.poll_read(cx, this.buf)?) { 0 => None, size => Some(Ok(Bytes::copy_from_slice(&this.buf[..size]))), - } + }, ) } } diff --git a/src/lib.rs b/src/lib.rs index 1752d2ef..19016a38 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -112,19 +112,19 @@ mod validation; pub mod extensions; pub mod guard; -pub mod validators; pub mod types; +pub mod validators; #[doc(hidden)] pub mod resolver_utils; #[doc(hidden)] pub use async_graphql_parser as parser; -#[doc(hidden)] -pub use async_trait; #[doc(hidden)] pub use async_stream; #[doc(hidden)] +pub use async_trait; +#[doc(hidden)] pub use futures; #[doc(hidden)] pub use indexmap; @@ -148,8 +148,8 @@ pub use request::Request; pub use response::Response; pub use schema::{Schema, SchemaBuilder, SchemaEnv}; pub use serde_json::Number; -pub use validation::ValidationMode; pub use types::*; +pub use validation::ValidationMode; /// Result type pub type Result = std::result::Result; diff --git a/src/resolver_utils/enum.rs b/src/resolver_utils/enum.rs index f7ad3afc..abb603e7 100644 --- a/src/resolver_utils/enum.rs +++ b/src/resolver_utils/enum.rs @@ -24,16 +24,18 @@ pub fn parse_enum(value: Value) -> InputValueResult { Value::String(s) => s.as_str(), _ => return Err(InputValueError::ExpectedType(value)), }; - + T::items() .iter() .find(|item| item.name == value) .map(|item| item.value) - .ok_or_else(|| InputValueError::Custom(format!( - r#"Enumeration type "{}" does not contain the value "{}""#, - T::type_name(), - value, - ))) + .ok_or_else(|| { + InputValueError::Custom(format!( + r#"Enumeration type "{}" does not contain the value "{}""#, + T::type_name(), + value, + )) + }) } /// Convert the enum value into a GraphQL value. diff --git a/src/resolver_utils/mod.rs b/src/resolver_utils/mod.rs index 2210a754..e667d83b 100644 --- a/src/resolver_utils/mod.rs +++ b/src/resolver_utils/mod.rs @@ -1,7 +1,7 @@ //! Utilities for implementing `OutputValueType::resolve`. -mod object; mod r#enum; +mod object; pub use object::*; pub use r#enum::*; diff --git a/src/response.rs b/src/response.rs index 99c96886..c082e1b1 100644 --- a/src/response.rs +++ b/src/response.rs @@ -47,10 +47,7 @@ impl Response { /// Set the extensions result of the response. #[must_use] pub fn extensions(self, extensions: Option) -> Self { - Self { - extensions, - ..self - } + Self { extensions, ..self } } /// Set the cache control of the response. diff --git a/src/schema.rs b/src/schema.rs index 73035a99..2019f0e0 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -405,9 +405,7 @@ where let data = match &env.document.operation.node.ty { OperationType::Query => resolve_object(&ctx, &self.query).await, - OperationType::Mutation => { - resolve_object_serial(&ctx, &self.mutation).await - } + OperationType::Mutation => resolve_object_serial(&ctx, &self.mutation).await, OperationType::Subscription => { return Error::Query { pos: Pos::default(), @@ -421,8 +419,7 @@ where env.extensions.lock().execution_end(); let extensions = env.extensions.lock().result(); - Response::from_result(data) - .extensions(extensions) + Response::from_result(data).extensions(extensions) } /// Execute an GraphQL query. diff --git a/src/types/empty_subscription.rs b/src/types/empty_subscription.rs index 961908da..9b65402e 100644 --- a/src/types/empty_subscription.rs +++ b/src/types/empty_subscription.rs @@ -1,6 +1,4 @@ -use crate::{ - registry, Context, Error, Pos, QueryError, Result, SubscriptionType, Type, -}; +use crate::{registry, Context, Error, Pos, QueryError, Result, SubscriptionType, Type}; use futures::{stream, Stream}; use std::borrow::Cow; use std::pin::Pin; diff --git a/src/types/external/mod.rs b/src/types/external/mod.rs index 6253253b..e01ea6d5 100644 --- a/src/types/external/mod.rs +++ b/src/types/external/mod.rs @@ -1,14 +1,14 @@ //! Implementations of `Type`, `ScalarType`, etc on external types. -mod string; +mod bool; +mod datetime; +mod floats; +mod integers; mod list; mod optional; -mod bool; -mod integers; -mod floats; +mod string; mod url; mod uuid; -mod datetime; #[cfg(feature = "bson")] mod bson; diff --git a/src/types/merged_object.rs b/src/types/merged_object.rs index b8f76d32..da9bfcf6 100644 --- a/src/types/merged_object.rs +++ b/src/types/merged_object.rs @@ -3,10 +3,9 @@ use crate::registry::{MetaType, Registry}; use crate::resolver_utils::{resolve_object, ObjectType}; use crate::{ CacheControl, Context, ContextSelectionSet, Error, GQLSimpleObject, GQLSubscription, - OutputValueType, Positioned, QueryError, Result, - SubscriptionType, Type, + OutputValueType, Positioned, QueryError, Result, SubscriptionType, Type, }; -use futures::{stream, Stream, StreamExt, future::Either}; +use futures::{future::Either, stream, Stream, StreamExt}; use indexmap::IndexMap; use std::borrow::Cow; use std::pin::Pin; @@ -112,20 +111,13 @@ where ) -> Pin> + Send + 'a>> { let left_stream = self.0.create_field_stream(ctx); let mut right_stream = Some(self.1.create_field_stream(ctx)); - Box::pin( - left_stream - .flat_map(move |res| { - match res { - Err(Error::Query { - err: QueryError::FieldNotFound { .. }, - .. - }) if right_stream.is_some() => { - Either::Right(right_stream.take().unwrap()) - } - other => Either::Left(stream::once(async { other })), - } - }) - ) + Box::pin(left_stream.flat_map(move |res| match res { + Err(Error::Query { + err: QueryError::FieldNotFound { .. }, + .. + }) if right_stream.is_some() => Either::Right(right_stream.take().unwrap()), + other => Either::Left(stream::once(async { other })), + })) } } diff --git a/src/types/mod.rs b/src/types/mod.rs index 30a62bfe..09c94fc2 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -3,24 +3,24 @@ pub mod connection; mod any; -mod json; mod empty_mutation; mod empty_subscription; +mod id; +mod json; mod maybe_undefined; mod merged_object; mod query_root; mod upload; -mod id; mod external; pub use any::Any; -pub use json::{Json, OutputJson}; pub use empty_mutation::EmptyMutation; pub use empty_subscription::EmptySubscription; +pub use id::ID; +pub use json::{Json, OutputJson}; pub use maybe_undefined::MaybeUndefined; pub use merged_object::{MergedObject, MergedObjectSubscriptionTail, MergedObjectTail}; pub use upload::Upload; -pub use id::ID; pub(crate) use query_root::QueryRoot; diff --git a/src/types/query_root.rs b/src/types/query_root.rs index ddea49b9..bc3c98af 100644 --- a/src/types/query_root.rs +++ b/src/types/query_root.rs @@ -2,8 +2,8 @@ use crate::model::{__Schema, __Type}; use crate::parser::types::Field; use crate::resolver_utils::{resolve_object, ObjectType}; use crate::{ - registry, Any, Context, ContextSelectionSet, Error, GQLSimpleObject, OutputValueType, Positioned, - QueryError, Result, Type, + registry, Any, Context, ContextSelectionSet, Error, GQLSimpleObject, OutputValueType, + Positioned, QueryError, Result, Type, }; use indexmap::map::IndexMap; diff --git a/tests/field_features.rs b/tests/field_features.rs index 7be0aaeb..1eae5499 100644 --- a/tests/field_features.rs +++ b/tests/field_features.rs @@ -126,7 +126,10 @@ pub async fn test_field_features() { let mut stream = schema.execute_stream("subscription { values }").boxed(); assert_eq!( - stream.next().await.map(|resp| resp.into_result().unwrap().data), + stream + .next() + .await + .map(|resp| resp.into_result().unwrap().data), Some(serde_json::json!({ "values": 10 }))