Skip to content

Commit

Permalink
Add feature
Browse files Browse the repository at this point in the history
  • Loading branch information
c410-f3r committed May 20, 2020
1 parent b22535a commit a7ba335
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions juniper/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ default = [
"url",
"uuid",
]
scalar-naivetime = []

[dependencies]
juniper_codegen = { version = "0.14.2", path = "../juniper_codegen" }
Expand Down
34 changes: 34 additions & 0 deletions juniper/src/integrations/chrono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
| | | precise enough for nanoseconds. |
| | | Values will be truncated to microsecond |
| | | resolution. |
| `NaiveTime` | H:M:S | Optional. Use the `scalar-naivetime` |
| | | feature. |
*/
#![allow(clippy::needless_lifetimes)]
Expand Down Expand Up @@ -99,6 +101,7 @@ where
}
}

#[cfg(feature = "scalar-naivetime")]
#[crate::graphql_scalar_internal(description = "NaiveTime")]
impl<S> GraphQLScalar for NaiveTime
where
Expand Down Expand Up @@ -218,6 +221,7 @@ mod test {
}

#[test]
#[cfg(feature = "scalar-naivetime")]
fn naivetime_from_input_value() {
let input: crate::InputValue<DefaultScalarValue>;
input = InputValue::scalar("21:12:19".to_string());
Expand Down Expand Up @@ -259,6 +263,7 @@ mod integration_test {
struct Root;

#[crate::graphql_object_internal]
#[cfg(feature = "scalar-naivetime")]
impl Root {
fn exampleNaiveDate() -> NaiveDate {
NaiveDate::from_ymd(2015, 3, 14)
Expand All @@ -277,6 +282,24 @@ mod integration_test {
}
}

#[crate::graphql_object_internal]
#[cfg(not(feature = "scalar-naivetime"))]
impl Root {
fn exampleNaiveDate() -> NaiveDate {
NaiveDate::from_ymd(2015, 3, 14)
}
fn exampleNaiveDateTime() -> NaiveDateTime {
NaiveDate::from_ymd(2016, 7, 8).and_hms(9, 10, 11)
}
fn exampleDateTimeFixedOffset() -> DateTime<FixedOffset> {
DateTime::parse_from_rfc3339("1996-12-19T16:39:57-08:00").unwrap()
}
fn exampleDateTimeUtc() -> DateTime<Utc> {
Utc.timestamp(61, 0)
}
}

#[cfg(feature = "scalar-naivetime")]
let doc = r#"
{
exampleNaiveDate,
Expand All @@ -287,6 +310,16 @@ mod integration_test {
}
"#;

#[cfg(not(feature = "scalar-naivetime"))]
let doc = r#"
{
exampleNaiveDate,
exampleNaiveDateTime,
exampleDateTimeFixedOffset,
exampleDateTimeUtc,
}
"#;

let schema = RootNode::new(
Root,
EmptyMutation::<()>::new(),
Expand All @@ -305,6 +338,7 @@ mod integration_test {
vec![
("exampleNaiveDate", Value::scalar("2015-03-14")),
("exampleNaiveDateTime", Value::scalar(1_467_969_011.0)),
#[cfg(feature = "scalar-naivetime")]
("exampleNaiveTime", Value::scalar("16:07:08")),
(
"exampleDateTimeFixedOffset",
Expand Down

0 comments on commit a7ba335

Please sign in to comment.