Skip to content

Commit

Permalink
url::Url compliance [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
tyranron committed Aug 15, 2024
1 parent 97556a3 commit 32c3296
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 11 deletions.
4 changes: 3 additions & 1 deletion juniper/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ All user visible changes to `juniper` crate will be documented in this file. Thi
- Upgraded [`chrono-tz` crate] integration to [0.9 version](https://github.com/chronotope/chrono-tz/releases/tag/v0.9.0). ([#1252])
- Bumped up [MSRV] to 1.75. ([#1272])
- Corrected compliance with newer [graphql-scalars.dev] specs: ([#1275])
- Switched `LocalDateTime` scalars to `yyyy-MM-ddTHH:mm:ss` format:
- Switched `LocalDateTime` scalars to `yyyy-MM-ddTHH:mm:ss` format in types:
- `chrono::NaiveDateTime`.
- `time::PrimitiveDateTime`.
- Renamed `Url` scalar to `URL` in types:
- `url::Url`.

### Added

Expand Down
6 changes: 5 additions & 1 deletion juniper/src/integrations/chrono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,11 @@ mod local_time {
///
/// [1]: https://graphql-scalars.dev/docs/scalars/local-date-time
/// [2]: https://docs.rs/chrono/latest/chrono/naive/struct.NaiveDateTime.html
#[graphql_scalar(with = local_date_time, parse_token(String))]
#[graphql_scalar(
with = local_date_time,
parse_token(String),
specified_by_url = "https://graphql-scalars.dev/docs/scalars/local-date-time",
)]
pub type LocalDateTime = chrono::NaiveDateTime;

mod local_date_time {
Expand Down
10 changes: 5 additions & 5 deletions juniper/src/integrations/jiff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use crate::{graphql_scalar, InputValue, ScalarValue, Value};
/// See also [`jiff::civil::Date`][2] for details.
///
/// [1]: https://graphql-scalars.dev/docs/scalars/local-date
/// [2]: https://docs.rs/jiff/latest/jiff/civil/struct.Date.html
/// [2]: https://docs.rs/jiff/*/jiff/civil/struct.Date.html
#[graphql_scalar(
with = local_date,
parse_token(String),
Expand Down Expand Up @@ -91,7 +91,7 @@ mod local_date {
/// See also [`jiff::civil::Time`][2] for details.
///
/// [1]: https://graphql-scalars.dev/docs/scalars/local-time
/// [2]: https://docs.rs/jiff/latest/jiff/civil/struct.Time.html
/// [2]: https://docs.rs/jiff/*/jiff/civil/struct.Time.html
#[graphql_scalar(
with = local_time,
parse_token(String),
Expand Down Expand Up @@ -162,7 +162,7 @@ mod local_time {
/// See also [`jiff::civil::DateTime`][2] for details.
///
/// [1]: https://graphql-scalars.dev/docs/scalars/local-date-time
/// [2]: https://docs.rs/jiff/latest/jiff/civil/struct.DateTime.html
/// [2]: https://docs.rs/jiff/*/jiff/civil/struct.DateTime.html
#[graphql_scalar(
with = local_date_time,
parse_token(String),
Expand Down Expand Up @@ -207,7 +207,7 @@ mod local_date_time {
/// See also [`jiff::Timestamp`][2] for details.
///
/// [1]: https://graphql-scalars.dev/docs/scalars/date-time
/// [2]: https://docs.rs/jiff/latest/jiff/struct.Timestamp.html
/// [2]: https://docs.rs/jiff/*/jiff/struct.Timestamp.html
#[graphql_scalar(
with = date_time,
parse_token(String),
Expand Down Expand Up @@ -252,7 +252,7 @@ mod date_time {
/// See also [`jiff::Span`][2] for details.
///
/// [1]: https://graphql-scalars.dev/docs/scalars/duration
/// [2]: https://docs.rs/jiff/latest/jiff/struct.Span.html
/// [2]: https://docs.rs/jiff/*/jiff/struct.Span.html
#[graphql_scalar(
with = duration,
parse_token(String),
Expand Down
6 changes: 5 additions & 1 deletion juniper/src/integrations/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,11 @@ mod local_time {
///
/// [1]: https://graphql-scalars.dev/docs/scalars/local-date-time
/// [2]: https://docs.rs/time/*/time/struct.PrimitiveDateTime.html
#[graphql_scalar(with = local_date_time, parse_token(String))]
#[graphql_scalar(
with = local_date_time,
parse_token(String),
specified_by_url = "https://graphql-scalars.dev/docs/scalars/local-date-time",
)]
pub type LocalDateTime = time::PrimitiveDateTime;

mod local_date_time {
Expand Down
21 changes: 18 additions & 3 deletions juniper/src/integrations/url.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
//! GraphQL support for [url](https://github.com/servo/rust-url) types.
//! GraphQL support for [`url`] crate types.
use crate::{graphql_scalar, InputValue, ScalarValue, Value};

#[graphql_scalar(with = url_scalar, parse_token(String))]
/// [Standard URL][0] format as specified in [RFC 3986].
///
/// [`URL` scalar][1] compliant.
///
/// See also [`url::Url`][2] for details.
///
/// [0]: http://url.spec.whatwg.org
/// [1]: https://graphql-scalars.dev/docs/scalars/url
/// [2]: https://docs.rs/url/*/url/struct.Url.html
/// [RFC 3986]: https://datatracker.ietf.org/doc/html/rfc3986
#[graphql_scalar(
name = "URL",
with = url_scalar,
parse_token(String),
specified_by_url = "https://graphql-scalars.dev/docs/scalars/url",
)]
type Url = url::Url;

mod url_scalar {
Expand All @@ -15,7 +30,7 @@ mod url_scalar {
pub(super) fn from_input<S: ScalarValue>(v: &InputValue<S>) -> Result<Url, String> {
v.as_string_value()
.ok_or_else(|| format!("Expected `String`, found: {v}"))
.and_then(|s| Url::parse(s).map_err(|e| format!("Failed to parse `Url`: {e}")))
.and_then(|s| Url::parse(s).map_err(|e| format!("Failed to parse `URL`: {e}")))
}
}

Expand Down

0 comments on commit 32c3296

Please sign in to comment.