Make uuid
to optional dependent.
This commit is contained in:
parent
b316c30416
commit
5eef10a1c4
|
@ -14,7 +14,7 @@ categories = ["network-programming", "asynchronous"]
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
|
||||||
[features]
|
[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"]
|
apollo_tracing = ["chrono"]
|
||||||
multipart = ["multer", "bytes", "tempfile"]
|
multipart = ["multer", "bytes", "tempfile"]
|
||||||
unblock = ["blocking"]
|
unblock = ["blocking"]
|
||||||
|
@ -38,9 +38,9 @@ serde = { version = "1.0.104", features = ["derive"] }
|
||||||
serde_json = "1.0.48"
|
serde_json = "1.0.48"
|
||||||
spin = "0.5.2"
|
spin = "0.5.2"
|
||||||
thiserror = "1.0.11"
|
thiserror = "1.0.11"
|
||||||
uuid = { version = "0.8.1", features = ["v4", "serde"] }
|
|
||||||
|
|
||||||
# Feature optional dependencies
|
# Feature optional dependencies
|
||||||
|
uuid = { version = "0.8.1", optional = true, features = ["v4", "serde"] }
|
||||||
bson = { version = "1.0.0", optional = true }
|
bson = { version = "1.0.0", optional = true }
|
||||||
chrono = { version = "0.4.15", optional = true }
|
chrono = { version = "0.4.15", optional = true }
|
||||||
chrono-tz = { version = "0.5.1", optional = true }
|
chrono-tz = { version = "0.5.1", optional = true }
|
||||||
|
|
|
@ -4,12 +4,10 @@ use crate::{Error, Variables};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use log::{error, info, trace};
|
use log::{error, info, trace};
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
/// Logger extension
|
/// Logger extension
|
||||||
#[cfg_attr(feature = "nightly", doc(cfg(feature = "log")))]
|
#[cfg_attr(feature = "nightly", doc(cfg(feature = "log")))]
|
||||||
pub struct Logger {
|
pub struct Logger {
|
||||||
id: Uuid,
|
|
||||||
enabled: bool,
|
enabled: bool,
|
||||||
query: String,
|
query: String,
|
||||||
variables: Variables,
|
variables: Variables,
|
||||||
|
@ -18,7 +16,6 @@ pub struct Logger {
|
||||||
impl Default for Logger {
|
impl Default for Logger {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
id: Uuid::new_v4(),
|
|
||||||
enabled: true,
|
enabled: true,
|
||||||
query: String::new(),
|
query: String::new(),
|
||||||
variables: Default::default(),
|
variables: Default::default(),
|
||||||
|
@ -44,29 +41,28 @@ impl Extension for Logger {
|
||||||
return;
|
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<'_>) {
|
fn resolve_start(&mut self, info: &ResolveInfo<'_>) {
|
||||||
if !self.enabled {
|
if !self.enabled {
|
||||||
return;
|
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<'_>) {
|
fn resolve_end(&mut self, info: &ResolveInfo<'_>) {
|
||||||
if !self.enabled {
|
if !self.enabled {
|
||||||
return;
|
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) {
|
fn error(&mut self, err: &Error) {
|
||||||
match err {
|
match err {
|
||||||
Error::Parse(err) => {
|
Error::Parse(err) => {
|
||||||
error!(
|
error!(
|
||||||
target: "async-graphql", "[ParseError] id: \"{}\", {}query: \"{}\", variables: {}, {}",
|
target: "async-graphql", "[ParseError] {}query: \"{}\", variables: {}, {}",
|
||||||
self.id,
|
|
||||||
if let Some(pos) = err.positions().next() {
|
if let Some(pos) = err.positions().next() {
|
||||||
// TODO: Make this more efficient
|
// TODO: Make this more efficient
|
||||||
format!("pos: [{}:{}], ", pos.line, pos.column)
|
format!("pos: [{}:{}], ", pos.line, pos.column)
|
||||||
|
@ -92,9 +88,9 @@ impl Extension for Logger {
|
||||||
} else {
|
} else {
|
||||||
String::new()
|
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 {
|
} 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 } => {
|
Error::Rule { errors } => {
|
||||||
|
@ -104,7 +100,7 @@ impl Extension for Logger {
|
||||||
.iter()
|
.iter()
|
||||||
.map(|pos| format!("{}:{}", pos.line, pos.column))
|
.map(|pos| format!("{}:{}", pos.line, pos.column))
|
||||||
.join(", ");
|
.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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,6 +106,7 @@
|
||||||
//! - `chrono`: Integrate with the [`chrono` crate](https://crates.io/crates/chrono).
|
//! - `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).
|
//! - `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).
|
//! - `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)]
|
#![warn(missing_docs)]
|
||||||
#![allow(clippy::trivially_copy_pass_by_ref)]
|
#![allow(clippy::trivially_copy_pass_by_ref)]
|
||||||
|
|
3
src/types/external/mod.rs
vendored
3
src/types/external/mod.rs
vendored
|
@ -9,7 +9,6 @@ mod list;
|
||||||
mod non_zero_integers;
|
mod non_zero_integers;
|
||||||
mod optional;
|
mod optional;
|
||||||
mod string;
|
mod string;
|
||||||
mod uuid;
|
|
||||||
|
|
||||||
#[cfg(feature = "bson")]
|
#[cfg(feature = "bson")]
|
||||||
mod bson;
|
mod bson;
|
||||||
|
@ -21,3 +20,5 @@ mod datetime;
|
||||||
mod naive_time;
|
mod naive_time;
|
||||||
#[cfg(feature = "url")]
|
#[cfg(feature = "url")]
|
||||||
mod url;
|
mod url;
|
||||||
|
#[cfg(feature = "uuid")]
|
||||||
|
mod uuid;
|
||||||
|
|
|
@ -55,6 +55,7 @@ macro_rules! try_from_integers {
|
||||||
|
|
||||||
try_from_integers!(i8, i16, i32, i64, i128, u8, u16, u32, u64, u128, isize, usize);
|
try_from_integers!(i8, i16, i32, i64, i128, u8, u16, u32, u64, u128, isize, usize);
|
||||||
|
|
||||||
|
#[cfg(feature = "uuid")]
|
||||||
impl TryFrom<ID> for uuid::Uuid {
|
impl TryFrom<ID> for uuid::Uuid {
|
||||||
type Error = uuid::Error;
|
type Error = uuid::Error;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user