From a7ba3357563dc09a65042abe33060cc74431a6f2 Mon Sep 17 00:00:00 2001 From: Caio Date: Wed, 20 May 2020 09:02:28 -0300 Subject: [PATCH] Add feature --- juniper/Cargo.toml | 1 + juniper/src/integrations/chrono.rs | 34 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/juniper/Cargo.toml b/juniper/Cargo.toml index 202b03c0a..69e970a61 100644 --- a/juniper/Cargo.toml +++ b/juniper/Cargo.toml @@ -31,6 +31,7 @@ default = [ "url", "uuid", ] +scalar-naivetime = [] [dependencies] juniper_codegen = { version = "0.14.2", path = "../juniper_codegen" } diff --git a/juniper/src/integrations/chrono.rs b/juniper/src/integrations/chrono.rs index 6582bc60c..0d5a16962 100644 --- a/juniper/src/integrations/chrono.rs +++ b/juniper/src/integrations/chrono.rs @@ -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)] @@ -99,6 +101,7 @@ where } } +#[cfg(feature = "scalar-naivetime")] #[crate::graphql_scalar_internal(description = "NaiveTime")] impl GraphQLScalar for NaiveTime where @@ -218,6 +221,7 @@ mod test { } #[test] + #[cfg(feature = "scalar-naivetime")] fn naivetime_from_input_value() { let input: crate::InputValue; input = InputValue::scalar("21:12:19".to_string()); @@ -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) @@ -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 { + DateTime::parse_from_rfc3339("1996-12-19T16:39:57-08:00").unwrap() + } + fn exampleDateTimeUtc() -> DateTime { + Utc.timestamp(61, 0) + } + } + + #[cfg(feature = "scalar-naivetime")] let doc = r#" { exampleNaiveDate, @@ -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(), @@ -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",