Skip to content

Commit fec998d

Browse files
authored
Update chrono crate scalars according to graphql-scalars.dev (#1010)
- remove `scalar-naivetime` feature - disable `chrono` feature by default
1 parent 5bbc73a commit fec998d

File tree

11 files changed

+781
-268
lines changed

11 files changed

+781
-268
lines changed

docs/book/content/types/scalars.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ Juniper has built-in support for a few additional types from common third party
3535
crates. They are enabled via features that are on by default.
3636

3737
* uuid::Uuid
38-
* chrono::DateTime
38+
* chrono::{DateTime, NaiveDate, NaiveDateTime, NaiveTime}
39+
* chrono_tz::Tz;
3940
* time::{Date, OffsetDateTime, PrimitiveDateTime, Time, UtcOffset}
4041
* url::Url
4142
* bson::oid::ObjectId

examples/actix_subscriptions/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ authors = ["Mihai Dinculescu <mihai.dinculescu@outlook.com>"]
66
publish = false
77

88
[dependencies]
9-
actix-web = "4.0.0-beta.12"
10-
actix-cors = "0.6.0-beta.4"
9+
actix-web = "4.0"
10+
actix-cors = "0.6"
1111
futures = "0.3"
1212
env_logger = "0.9"
1313
serde = "1.0"

examples/actix_subscriptions/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ async fn main() -> std::io::Result<()> {
136136
.route(web::get().to(graphql)),
137137
)
138138
.service(web::resource("/playground").route(web::get().to(playground)))
139-
.default_service(web::route().to(|| {
139+
.default_service(web::to(|| async {
140140
HttpResponse::Found()
141141
.append_header((header::LOCATION, "/playground"))
142142
.finish()

juniper/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
- Mirror `#[derive(GraphQLScalar)]` macro.
3030
- Support usage on type aliases in case `#[derive(GraphQLScalar)]` isn't applicable because of [orphan rules](https://doc.rust-lang.org/reference/items/implementations.html#orphan-rules).
3131
- Rename `ScalarValue::as_boolean` to `ScalarValue::as_bool`. ([#1025](https://github.com/graphql-rust/juniper/pull/1025))
32+
- Change [`chrono` crate](https://docs.rs/chrono) GraphQL scalars according to the [graphql-scalars.dev](https://graphql-scalars.dev). ([#1010](https://github.com/graphql-rust/juniper/pull/1010))
33+
- Disable `chrono` feature by default. ([#1010](https://github.com/graphql-rust/juniper/pull/1010))
34+
- Remove `scalar-naivetime` feature. ([#1010](https://github.com/graphql-rust/juniper/pull/1010))
3235

3336
## Features
3437

juniper/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,13 @@ travis-ci = { repository = "graphql-rust/juniper" }
2121
[features]
2222
default = [
2323
"bson",
24-
"chrono",
2524
"schema-language",
2625
"url",
2726
"uuid",
2827
]
28+
chrono-clock = ["chrono", "chrono/clock"]
2929
expose-test-schema = ["anyhow", "serde_json"]
3030
graphql-parser-integration = ["graphql-parser"]
31-
scalar-naivetime = []
3231
schema-language = ["graphql-parser-integration"]
3332

3433
[dependencies]

juniper/src/integrations/bson.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//! GraphQL support for [bson](https://github.com/mongodb/bson-rust) types.
22
3-
use chrono::prelude::*;
4-
53
use crate::{graphql_scalar, InputValue, ScalarValue, Value};
64

75
#[graphql_scalar(with = object_id, parse_token(String))]
@@ -30,17 +28,16 @@ mod utc_date_time {
3028
use super::*;
3129

3230
pub(super) fn to_output<S: ScalarValue>(v: &UtcDateTime) -> Value<S> {
33-
Value::scalar((*v).to_chrono().to_rfc3339())
31+
Value::scalar((*v).to_rfc3339_string())
3432
}
3533

3634
pub(super) fn from_input<S: ScalarValue>(v: &InputValue<S>) -> Result<UtcDateTime, String> {
3735
v.as_string_value()
3836
.ok_or_else(|| format!("Expected `String`, found: {}", v))
3937
.and_then(|s| {
40-
s.parse::<DateTime<Utc>>()
38+
UtcDateTime::parse_rfc3339_str(s)
4139
.map_err(|e| format!("Failed to parse `UtcDateTime`: {}", e))
4240
})
43-
.map(UtcDateTime::from_chrono)
4441
}
4542
}
4643

0 commit comments

Comments
 (0)