parent
1b18bc9869
commit
01b2dea848
4 changed files with 41 additions and 0 deletions
|
@ -22,11 +22,13 @@ path = "benches/bench.rs"
|
|||
[features]
|
||||
nightly = []
|
||||
expose-test-schema = []
|
||||
default = ["uuid"]
|
||||
|
||||
[dependencies]
|
||||
serde = { version = "^1.0.8" }
|
||||
serde_derive = {version="^1.0.8" }
|
||||
serde_json = { version="^1.0.2", optional = true }
|
||||
uuid = { version = "0.5.1", optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
bencher = "^0.1.2"
|
||||
|
|
|
@ -1 +1,4 @@
|
|||
pub mod serde;
|
||||
|
||||
#[cfg(feature = "uuid")]
|
||||
mod uuid;
|
||||
|
|
32
juniper/src/integrations/uuid.rs
Normal file
32
juniper/src/integrations/uuid.rs
Normal file
|
@ -0,0 +1,32 @@
|
|||
use uuid::Uuid;
|
||||
|
||||
use ::Value;
|
||||
|
||||
graphql_scalar!(Uuid {
|
||||
description: "Uuid"
|
||||
|
||||
resolve(&self) -> Value {
|
||||
Value::string(self.to_string())
|
||||
}
|
||||
|
||||
from_input_value(v: &InputValue) -> Option<Uuid> {
|
||||
v.as_string_value()
|
||||
.and_then(|s| Uuid::parse_str(s).ok())
|
||||
}
|
||||
});
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use uuid::Uuid;
|
||||
|
||||
#[test]
|
||||
fn uuid_from_input_value() {
|
||||
let raw = "123e4567-e89b-12d3-a456-426655440000";
|
||||
let input = ::InputValue::String(raw.to_string());
|
||||
|
||||
let parsed: Uuid = ::FromInputValue::from(&input).unwrap();
|
||||
let id = Uuid::parse_str(raw).unwrap();
|
||||
|
||||
assert_eq!(parsed, id);
|
||||
}
|
||||
}
|
|
@ -121,6 +121,10 @@ extern crate serde_derive;
|
|||
#[cfg(any(test, feature = "expose-test-schema"))]
|
||||
extern crate serde_json;
|
||||
|
||||
|
||||
#[cfg(any(test, feature = "uuid"))]
|
||||
extern crate uuid;
|
||||
|
||||
use std::borrow::Cow;
|
||||
|
||||
#[macro_use]
|
||||
|
|
Loading…
Reference in a new issue