parent
d7c84b16e9
commit
0915c05c6c
4 changed files with 41 additions and 0 deletions
juniper
|
@ -22,11 +22,13 @@ path = "benches/bench.rs"
|
||||||
[features]
|
[features]
|
||||||
nightly = []
|
nightly = []
|
||||||
expose-test-schema = []
|
expose-test-schema = []
|
||||||
|
default = ["uuid"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde = { version = "^1.0.8" }
|
serde = { version = "^1.0.8" }
|
||||||
serde_derive = {version="^1.0.8" }
|
serde_derive = {version="^1.0.8" }
|
||||||
serde_json = { version="^1.0.2", optional = true }
|
serde_json = { version="^1.0.2", optional = true }
|
||||||
|
uuid = { version = "0.5.1", optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
bencher = "^0.1.2"
|
bencher = "^0.1.2"
|
||||||
|
|
|
@ -1 +1,4 @@
|
||||||
pub mod serde;
|
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"))]
|
#[cfg(any(test, feature = "expose-test-schema"))]
|
||||||
extern crate serde_json;
|
extern crate serde_json;
|
||||||
|
|
||||||
|
|
||||||
|
#[cfg(any(test, feature = "uuid"))]
|
||||||
|
extern crate uuid;
|
||||||
|
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
|
Loading…
Add table
Reference in a new issue