Remove and feature-gate dependencies

This commit is contained in:
Koxiaet 2020-09-14 19:38:41 +01:00
parent 3ccc61ba0f
commit a3ad1aac30
7 changed files with 45 additions and 24 deletions

View File

@ -14,7 +14,9 @@ categories = ["network-programming", "asynchronous"]
readme = "README.md"
[features]
default = ["bson", "url", "chrono-tz"]
default = ["apollo_tracing", "bson", "chrono", "chrono-tz", "log", "multipart", "tracing", "url"]
apollo_tracing = ["chrono"]
multipart = ["multer", "bytes", "tempfile"]
[dependencies]
async-graphql-derive = { path = "derive", version = "2.0.0-alpha.6" }
@ -22,33 +24,30 @@ async-graphql-parser = { path = "parser", version = "2.0.0-alpha.6" }
async-stream = "0.3"
async-trait = "0.1.30"
bytes = "0.5.4"
chrono = "0.4.10"
fnv = "1.0.6"
futures = "0.3.5"
http = "0.2.1"
httparse = "1.3.4"
indexmap = "1.3.2"
itertools = "0.9.0"
log = "0.4.8"
multer = "1.2.2"
once_cell = "1.3.1"
parking_lot = "0.10.0"
pin-project-lite = "0.1.7"
regex = "1.3.5"
serde = { version = "1.0.104", features = ["derive"] }
serde_json = "1.0.48"
slab = "0.4.2"
spin = "0.5.2"
tempfile = "3.1.0"
thiserror = "1.0.11"
tracing = "0.1.13"
pin-project-lite = "0.1.7"
uuid = { version = "0.8.1", features = ["v4", "serde"] }
# Feature optional dependencies
bson = { version = "1.0.0", optional = true }
url = { version = "2.1.1", optional = true }
chrono = { version = "0.4.15", optional = true }
chrono-tz = { version = "0.5.1", optional = true }
log = { version = "0.4.11", optional = true }
tracing = { version = "0.1.19", optional = true }
url = { version = "2.1.1", optional = true }
bytes = { version = "0.5.4", optional = true }
multer = { version = "1.2.2", optional = true }
tempfile = { version = "3.1.0", optional = true }
[dev-dependencies]
async-std = { version = "1.5.0", features = ["attributes"] }

View File

@ -330,6 +330,7 @@ pub enum ParseRequestError {
/// The request's multipart data was invalid.
#[error("Invalid multipart data")]
#[cfg(feature = "multipart")]
InvalidMultipart(multer::Error),
/// Missing "operators" part for multipart request.
@ -353,6 +354,7 @@ pub enum ParseRequestError {
PayloadTooLarge,
}
#[cfg(feature = "multipart")]
impl From<multer::Error> for ParseRequestError {
fn from(err: multer::Error) -> Self {
match err {

View File

@ -46,8 +46,11 @@ impl Serialize for ResolveStat {
/// Apollo tracing extension for performance tracing
///
/// Apollo Tracing works by including data in the extensions field of the GraphQL response, which is reserved by the GraphQL spec for extra information that a server wants to return. That way, you have access to performance traces alongside the data returned by your query.
/// Its already supported by `Apollo Engine`, and were excited to see what other kinds of integrations people can build on top of this format.
/// Apollo Tracing works by including data in the extensions field of the GraphQL response, which is
/// reserved by the GraphQL spec for extra information that a server wants to return. That way, you
/// have access to performance traces alongside the data returned by your query.
/// It's already supported by `Apollo Engine`, and we're excited to see what other kinds of
/// integrations people can build on top of this format.
pub struct ApolloTracing {
start_time: DateTime<Utc>,
end_time: DateTime<Utc>,

View File

@ -1,14 +1,20 @@
//! Extensions for schema
#[cfg(feature = "apollo_tracing")]
mod apollo_tracing;
#[cfg(feature = "log")]
mod logger;
#[cfg(feature = "tracing")]
mod tracing;
use crate::context::{QueryPathNode, ResolveId};
use crate::{Context, Result, Variables};
#[cfg(feature = "apollo_tracing")]
pub use self::apollo_tracing::ApolloTracing;
#[cfg(feature = "log")]
pub use self::logger::Logger;
#[cfg(feature = "tracing")]
pub use self::tracing::Tracing;
use crate::parser::types::ExecutableDocument;
use crate::Error;

View File

@ -1,11 +1,13 @@
//! A helper module that supports HTTP
mod graphiql_source;
#[cfg(feature = "multipart")]
mod multipart;
mod playground_source;
pub mod websocket;
pub use graphiql_source::graphiql_source;
#[cfg(feature = "multipart")]
pub use multipart::{receive_multipart, MultipartOptions};
pub use playground_source::{playground_source, GraphQLPlaygroundConfig};
@ -19,14 +21,15 @@ pub async fn receive_body(
body: impl AsyncRead + Send + 'static,
opts: MultipartOptions,
) -> Result<Request, ParseRequestError> {
#[cfg(feature = "multipart")]
if let Some(Ok(boundary)) = content_type.map(multer::parse_boundary) {
receive_multipart(body, boundary, opts).await
} else {
let mut data = Vec::new();
futures::pin_mut!(body);
body.read_to_end(&mut data)
.await
.map_err(ParseRequestError::Io)?;
Ok(serde_json::from_slice::<Request>(&data).map_err(ParseRequestError::InvalidRequest)?)
return receive_multipart(body, boundary, opts).await;
}
let mut data = Vec::new();
futures::pin_mut!(body);
body.read_to_end(&mut data)
.await
.map_err(ParseRequestError::Io)?;
Ok(serde_json::from_slice::<Request>(&data).map_err(ParseRequestError::InvalidRequest)?)
}

View File

@ -1,6 +1,9 @@
use crate::{GQLScalar, InputValueError, InputValueResult, ScalarType, Value};
use bson::{oid::ObjectId, DateTime as UtcDateTime};
use bson::oid::ObjectId;
#[cfg(feature = "chrono")]
use chrono::{DateTime, Utc};
#[cfg(feature = "chrono")]
use bson::DateTime as UtcDateTime;
#[GQLScalar(internal)]
impl ScalarType for ObjectId {
@ -16,6 +19,7 @@ impl ScalarType for ObjectId {
}
}
#[cfg(feature = "chrono")]
#[GQLScalar(internal, name = "DateTime")]
impl ScalarType for UtcDateTime {
fn parse(value: Value) -> InputValueResult<Self> {

View File

@ -14,6 +14,10 @@ mod uuid;
#[cfg(feature = "bson")]
mod bson;
#[cfg(feature = "chrono")]
mod datetime;
#[cfg(feature = "chrono")]
mod naive_time;
#[cfg(feature = "chrono_tz")]
mod chrono_tz;
#[cfg(feature = "url")]