Make uuid to optional dependent.

This commit is contained in:
Sunli 2020-09-25 15:40:04 +08:00
parent b316c30416
commit 5eef10a1c4
5 changed files with 13 additions and 14 deletions

View File

@ -14,7 +14,7 @@ categories = ["network-programming", "asynchronous"]
readme = "README.md"
[features]
default = ["apollo_tracing", "bson", "chrono", "chrono-tz", "log", "multipart", "tracing", "url", "unblock"]
default = ["apollo_tracing", "uuid", "bson", "chrono", "chrono-tz", "log", "multipart", "tracing", "url", "unblock"]
apollo_tracing = ["chrono"]
multipart = ["multer", "bytes", "tempfile"]
unblock = ["blocking"]
@ -38,9 +38,9 @@ serde = { version = "1.0.104", features = ["derive"] }
serde_json = "1.0.48"
spin = "0.5.2"
thiserror = "1.0.11"
uuid = { version = "0.8.1", features = ["v4", "serde"] }
# Feature optional dependencies
uuid = { version = "0.8.1", optional = true, features = ["v4", "serde"] }
bson = { version = "1.0.0", optional = true }
chrono = { version = "0.4.15", optional = true }
chrono-tz = { version = "0.5.1", optional = true }

View File

@ -4,12 +4,10 @@ use crate::{Error, Variables};
use itertools::Itertools;
use log::{error, info, trace};
use std::borrow::Cow;
use uuid::Uuid;
/// Logger extension
#[cfg_attr(feature = "nightly", doc(cfg(feature = "log")))]
pub struct Logger {
id: Uuid,
enabled: bool,
query: String,
variables: Variables,
@ -18,7 +16,6 @@ pub struct Logger {
impl Default for Logger {
fn default() -> Self {
Self {
id: Uuid::new_v4(),
enabled: true,
query: String::new(),
variables: Default::default(),
@ -44,29 +41,28 @@ impl Extension for Logger {
return;
}
info!(target: "async-graphql", "[Query] id: \"{}\", query: \"{}\", variables: {}", self.id, &self.query, self.variables);
info!(target: "async-graphql", "[Query] query: \"{}\", variables: {}", &self.query, self.variables);
}
fn resolve_start(&mut self, info: &ResolveInfo<'_>) {
if !self.enabled {
return;
}
trace!(target: "async-graphql", "[ResolveStart] id: \"{}\", path: \"{}\"", self.id, info.path_node);
trace!(target: "async-graphql", "[ResolveStart] path: \"{}\"", info.path_node);
}
fn resolve_end(&mut self, info: &ResolveInfo<'_>) {
if !self.enabled {
return;
}
trace!(target: "async-graphql", "[ResolveEnd] id: \"{}\", path: \"{}\"", self.id, info.path_node);
trace!(target: "async-graphql", "[ResolveEnd] path: \"{}\"", info.path_node);
}
fn error(&mut self, err: &Error) {
match err {
Error::Parse(err) => {
error!(
target: "async-graphql", "[ParseError] id: \"{}\", {}query: \"{}\", variables: {}, {}",
self.id,
target: "async-graphql", "[ParseError] {}query: \"{}\", variables: {}, {}",
if let Some(pos) = err.positions().next() {
// TODO: Make this more efficient
format!("pos: [{}:{}], ", pos.line, pos.column)
@ -92,9 +88,9 @@ impl Extension for Logger {
} else {
String::new()
};
error!(target: "async-graphql", "[QueryError] id: \"{}\", path: \"{}\", pos: [{}:{}], query: \"{}\", variables: {}, {}", self.id, path, pos.line, pos.column, self.query, self.variables, err)
error!(target: "async-graphql", "[QueryError] path: \"{}\", pos: [{}:{}], query: \"{}\", variables: {}, {}", path, pos.line, pos.column, self.query, self.variables, err)
} else {
error!(target: "async-graphql", "[QueryError] id: \"{}\", pos: [{}:{}], query: \"{}\", variables: {}, {}", self.id, pos.line, pos.column, self.query, self.variables, err)
error!(target: "async-graphql", "[QueryError] pos: [{}:{}], query: \"{}\", variables: {}, {}", pos.line, pos.column, self.query, self.variables, err)
}
}
Error::Rule { errors } => {
@ -104,7 +100,7 @@ impl Extension for Logger {
.iter()
.map(|pos| format!("{}:{}", pos.line, pos.column))
.join(", ");
error!(target: "async-graphql", "[ValidationError] id: \"{}\", pos: [{}], query: \"{}\", variables: {}, {}", self.id, locations, self.query, self.variables, error.message)
error!(target: "async-graphql", "[ValidationError] pos: [{}], query: \"{}\", variables: {}, {}", locations, self.query, self.variables, error.message)
}
}
}

View File

@ -106,6 +106,7 @@
//! - `chrono`: Integrate with the [`chrono` crate](https://crates.io/crates/chrono).
//! - `chrono-tz`: Integrate with the [`chrono-tz` crate](https://crates.io/crates/chrono-tz).
//! - `url`: Integrate with the [`url` crate](https://crates.io/crates/url).
//! - `uuid`: Integrate with the [`uuid` crate](https://crates.io/crates/uuid).
#![warn(missing_docs)]
#![allow(clippy::trivially_copy_pass_by_ref)]

View File

@ -9,7 +9,6 @@ mod list;
mod non_zero_integers;
mod optional;
mod string;
mod uuid;
#[cfg(feature = "bson")]
mod bson;
@ -21,3 +20,5 @@ mod datetime;
mod naive_time;
#[cfg(feature = "url")]
mod url;
#[cfg(feature = "uuid")]
mod uuid;

View File

@ -55,6 +55,7 @@ macro_rules! try_from_integers {
try_from_integers!(i8, i16, i32, i64, i128, u8, u16, u32, u64, u128, isize, usize);
#[cfg(feature = "uuid")]
impl TryFrom<ID> for uuid::Uuid {
type Error = uuid::Error;