Skip to content

Commit

Permalink
Add Jiff date/time types Zoned/TimeZone (#1278)
Browse files Browse the repository at this point in the history
* Enable support for Jiff's Zoned type

* Enable support for Jiff's TimeZone type

* Remove unnecessary feature flag `jiff-tz`

* Avoid panic and allow offset-only time zones to be returned

* Add ZonedDateTime and TimeZone to integration test

* Split TimeZone into TimeZone and UTCOffset for Jiff integration

* Fix capitalization of `UtcOffset`

* Provide TimeZoneOrUtcOffset integration for jiff::tz::TimeZone

* Adjust documentation for newtypes and `TimeZoneOrUtcOffset`

* Use `jiff::tz::Offset` directly in `UtcOffset` newtype

* Remove unnecessary newtype for `UtcOffset` scalar

* Fix parsing of fixed offsets from `TimeZoneOrUtcOffset` scalar

* Add unrelated missing link to books page on scalars

* State necessity for newtype in scalars table in book

* Remove redundant `alloc` feature, is included in `std`

* Implement `Display` for TimeZone newtype

* Rename error enum variant to clarify meaning

* Use concise wording in description of TimeZone

Co-authored-by: Christian Legnitto <LegNeato@users.noreply.github.com>

* Revert extra notes column in scalar table

* Add link to documentation of newtype `TimeZone`

* Remove unused duplicate link reference

* Sort links and group links from the same crate together

---------

Co-authored-by: Christian Legnitto <LegNeato@users.noreply.github.com>
  • Loading branch information
sgoll and LegNeato authored Sep 6, 2024
1 parent eb2079b commit fb1531f
Show file tree
Hide file tree
Showing 4 changed files with 848 additions and 42 deletions.
58 changes: 34 additions & 24 deletions book/src/types/scalars.md
Original file line number Diff line number Diff line change
Expand Up @@ -385,29 +385,35 @@ mod date_scalar {

[Juniper] provides out-of-the-box [GraphQL scalar][0] implementations for some very common [Rust] crates. The types from these crates will be usable in your schemas automatically after enabling the correspondent self-titled [Cargo feature].

| [Rust] type | [GraphQL] scalar | [Cargo feature] |
|-----------------------------|-------------------|------------------|
| [`bigdecimal::BigDecimal`] | `BigDecimal` | [`bigdecimal`] |
| [`bson::oid::ObjectId`] | [`ObjectID`] | [`bson`] |
| [`bson::DateTime`] | [`DateTime`] | [`bson`] |
| [`chrono::NaiveDate`] | [`LocalDate`] | [`chrono`] |
| [`chrono::NaiveTime`] | [`LocalTime`] | [`chrono`] |
| [`chrono::NaiveDateTime`] | [`LocalDateTime`] | [`chrono`] |
| [`chrono::DateTime`] | [`DateTime`] | [`chrono`] |
| [`chrono_tz::Tz`] | [`TimeZone`] | [`chrono-tz`] |
| [`rust_decimal::Decimal`] | `Decimal` | [`rust_decimal`] |
| [`jiff::civil::Date`] | [`LocalDate`] | [`jiff`] |
| [`jiff::civil::Time`] | [`LocalTime`] | [`jiff`] |
| [`jiff::civil::DateTime`] | [`LocalDateTime`] | [`jiff`] |
| [`jiff::Timestamp`] | [`DateTime`] | [`jiff`] |
| [`jiff::Span`] | [`Duration`] | [`jiff`] |
| [`time::Date`] | [`LocalDate`] | [`time`] |
| [`time::Time`] | [`LocalTime`] | [`time`] |
| [`time::PrimitiveDateTime`] | [`LocalDateTime`] | [`time`] |
| [`time::OffsetDateTime`] | [`DateTime`] | [`time`] |
| [`time::UtcOffset`] | [`UtcOffset`] | [`time`] |
| [`url::Url`] | [`URL`] | [`url`] |
| [`uuid::Uuid`] | [`UUID`] | [`uuid`] |
| [Rust] type | [GraphQL] scalar | [Cargo feature] |
|-----------------------------|-----------------------|------------------|
| [`bigdecimal::BigDecimal`] | `BigDecimal` | [`bigdecimal`] |
| [`bson::oid::ObjectId`] | [`ObjectID`] | [`bson`] |
| [`bson::DateTime`] | [`DateTime`] | [`bson`] |
| [`chrono::NaiveDate`] | [`LocalDate`] | [`chrono`] |
| [`chrono::NaiveTime`] | [`LocalTime`] | [`chrono`] |
| [`chrono::NaiveDateTime`] | [`LocalDateTime`] | [`chrono`] |
| [`chrono::DateTime`] | [`DateTime`] | [`chrono`] |
| [`chrono_tz::Tz`] | [`TimeZone`] | [`chrono-tz`] |
| [`rust_decimal::Decimal`] | `Decimal` | [`rust_decimal`] |
| [`jiff::civil::Date`] | [`LocalDate`] | [`jiff`] |
| [`jiff::civil::Time`] | [`LocalTime`] | [`jiff`] |
| [`jiff::civil::DateTime`] | [`LocalDateTime`] | [`jiff`] |
| [`jiff::Timestamp`] | [`DateTime`] | [`jiff`] |
| [`jiff::Zoned`] | `ZonedDateTime` | [`jiff`] |
| [`jiff::tz::TimeZone`] | `TimeZoneOrUtcOffset` | [`jiff`] |
| [`jiff::tz::TimeZone`] | [`TimeZone`] [^n1] | [`jiff`] |
| [`jiff::tz::Offset`] | [`UtcOffset`] | [`jiff`] |
| [`jiff::Span`] | [`Duration`] | [`jiff`] |
| [`time::Date`] | [`LocalDate`] | [`time`] |
| [`time::Time`] | [`LocalTime`] | [`time`] |
| [`time::PrimitiveDateTime`] | [`LocalDateTime`] | [`time`] |
| [`time::OffsetDateTime`] | [`DateTime`] | [`time`] |
| [`time::UtcOffset`] | [`UtcOffset`] | [`time`] |
| [`url::Url`] | [`URL`] | [`url`] |
| [`uuid::Uuid`] | [`UUID`] | [`uuid`] |

[^n1]: Conversion supported via newtype [`integrations::jiff::TimeZone`][10].



Expand All @@ -425,7 +431,6 @@ mod date_scalar {
[`chrono-tz`]: https://docs.rs/chrono-tz
[`chrono_tz::Tz`]: https://docs.rs/chrono-tz/latest/chrono_tz/enum.Tz.html
[`DateTime`]: https://graphql-scalars.dev/docs/scalars/date-time
[`Decimal`]: https://docs.rs/rust_decimal/latest/rust_decimal/struct.Decimal.html
[`Duration`]: https://graphql-scalars.dev/docs/scalars/duration
[`ID`]: https://spec.graphql.org/October2021#sec-ID
[`jiff`]: https://docs.rs/jiff
Expand All @@ -434,11 +439,15 @@ mod date_scalar {
[`jiff::civil::Time`]: https://docs.rs/jiff/latest/jiff/civil/struct.Time.html
[`jiff::Span`]: https://docs.rs/jiff/latest/jiff/struct.Span.html
[`jiff::Timestamp`]: https://docs.rs/jiff/latest/jiff/struct.Timestamp.html
[`jiff::tz::Offset`]: https://docs.rs/jiff/latest/jiff/tz/struct.Offset.html
[`jiff::tz::TimeZone`]: https://docs.rs/jiff/latest/jiff/tz/struct.TimeZone.html
[`jiff::Zoned`]: https://docs.rs/jiff/latest/jiff/struct.Zoned.html
[`LocalDate`]: https://graphql-scalars.dev/docs/scalars/local-date
[`LocalDateTime`]: https://graphql-scalars.dev/docs/scalars/local-date-time
[`LocalTime`]: https://graphql-scalars.dev/docs/scalars/local-time
[`ObjectID`]: https://the-guild.dev/graphql/scalars/docs/scalars/object-id
[`rust_decimal`]: https://docs.rs/rust_decimal
[`rust_decimal::Decimal`]: https://docs.rs/rust_decimal/latest/rust_decimal/struct.Decimal.html
[`ScalarValue`]: https://docs.rs/juniper/0.16.1/juniper/trait.ScalarValue.html
[`serde`]: https://docs.rs/serde
[`time`]: https://docs.rs/time
Expand Down Expand Up @@ -472,3 +481,4 @@ mod date_scalar {
[7]: https://spec.graphql.org/October2021#sec-Value-Resolution
[8]: https://docs.rs/juniper/0.16.1/juniper/derive.GraphQLScalar.html
[9]: https://docs.rs/juniper/0.16.1/juniper/attr.graphql_scalar.html
[10]: https://docs.rs/juniper/0.16.1/juniper/integrations/jiff/struct.TimeZone.html
7 changes: 6 additions & 1 deletion juniper/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@ All user visible changes to `juniper` crate will be documented in this file. Thi

### Added

- [`jiff` crate] integration behind `jiff` [Cargo feature]: ([#1271], [#1270])
- [`jiff` crate] integration behind `jiff` [Cargo feature]: ([#1271], [#1278], [#1270])
- `jiff::civil::Date` as `LocalDate` scalar.
- `jiff::civil::Time` as `LocalTime` scalar.
- `jiff::civil::DateTime` as `LocalDateTime` scalar. ([#1275])
- `jiff::Timestamp` as `DateTime` scalar.
- `jiff::Zoned` as `ZonedDateTime` scalar.
- `jiff::tz::TimeZone` as `TimeZoneOrUtcOffset` scalar.
- `jiff::tz::Offset` as `UtcOffset` scalar.
- `jiff::Span` as `Duration` scalar.

### Changed
Expand All @@ -51,6 +54,8 @@ All user visible changes to `juniper` crate will be documented in this file. Thi
[#1272]: /../../pull/1272
[#1275]: /../../pull/1275
[#1277]: /../../pull/1277
[#1278]: /../../pull/1278
[#1279]: /../../pull/1279
[#1281]: /../../pull/1281


Expand Down
3 changes: 2 additions & 1 deletion juniper/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fnv = "1.0.5"
futures = { version = "0.3.22", features = ["alloc"], default-features = false }
graphql-parser = { version = "0.4", optional = true }
indexmap = { version = "2.0", features = ["serde"] }
jiff = { version = "0.1.5", features = ["alloc"], default-features = false, optional = true }
jiff = { version = "0.1.5", features = ["std"], default-features = false, optional = true }
juniper_codegen = { version = "0.16.0", path = "../juniper_codegen" }
rust_decimal = { version = "1.20", default-features = false, optional = true }
ryu = { version = "1.0", optional = true }
Expand All @@ -78,6 +78,7 @@ void = { version = "1.0.2", optional = true }
[dev-dependencies]
bencher = "0.1.2"
chrono = { version = "0.4.30", features = ["alloc"], default-features = false }
jiff = { version = "0.1.5", features = ["tzdb-bundle-always"], default-features = false }
pretty_assertions = "1.0.0"
serde_json = "1.0.18"
serial_test = "3.0"
Expand Down
Loading

0 comments on commit fb1531f

Please sign in to comment.