From 0edc4c9a119a74c0f94ff499b24eb7b33f862810 Mon Sep 17 00:00:00 2001 From: tyranron Date: Thu, 15 Aug 2024 15:57:35 +0300 Subject: [PATCH] `uuid::Uuid` compliance [skip ci] --- book/src/types/scalars.md | 16 +++++++++------- juniper/CHANGELOG.md | 2 ++ juniper/src/integrations/uuid.rs | 18 ++++++++++++++++-- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/book/src/types/scalars.md b/book/src/types/scalars.md index ce519b4b8..41dd10130 100644 --- a/book/src/types/scalars.md +++ b/book/src/types/scalars.md @@ -387,7 +387,7 @@ mod date_scalar { | [Rust] type | [GraphQL] scalar | [Cargo feature] | |-----------------------------|-------------------|------------------| -| [`BigDecimal`] | `BigDecimal` | [`bigdecimal`] | +| [`bigdecimal::BigDecimal`] | `BigDecimal` | [`bigdecimal`] | | [`bson::oid::ObjectId`] | `ObjectId` | [`bson`] | | [`bson::DateTime`] | `UtcDateTime` | [`bson`] | | [`chrono::NaiveDate`] | [`Date`] | [`chrono`] | @@ -395,7 +395,7 @@ mod date_scalar { | [`chrono::NaiveDateTime`] | [`LocalDateTime`] | [`chrono`] | | [`chrono::DateTime`] | [`DateTime`] | [`chrono`] | | [`chrono_tz::Tz`] | `TimeZone` | [`chrono-tz`] | -| [`Decimal`] | `Decimal` | [`rust_decimal`] | +| [`rust_decimal::Decimal`] | `Decimal` | [`rust_decimal`] | | [`jiff::civil::Date`] | [`LocalDate`] | [`jiff`] | | [`jiff::civil::Time`] | [`LocalTime`] | [`jiff`] | | [`jiff::civil::DateTime`] | [`LocalDateTime`] | [`jiff`] | @@ -406,14 +406,14 @@ mod date_scalar { | [`time::PrimitiveDateTime`] | [`LocalDateTime`] | [`time`] | | [`time::OffsetDateTime`] | [`DateTime`] | [`time`] | | [`time::UtcOffset`] | [`UtcOffset`] | [`time`] | -| [`Url`] | `Url` | [`url`] | -| [`Uuid`] | `Uuid` | [`uuid`] | +| [`url::Url`] | [`URL`] | [`url`] | +| [`uuid::Uuid`] | [`UUID`] | [`uuid`] | [`bigdecimal`]: https://docs.rs/bigdecimal -[`BigDecimal`]: https://docs.rs/bigdecimal/latest/bigdecimal/struct.BigDecimal.html +[`bigdecimal::BigDecimal`]: https://docs.rs/bigdecimal/latest/bigdecimal/struct.BigDecimal.html [`bson`]: https://docs.rs/bson [`bson::DateTime`]: https://docs.rs/bson/latest/bson/struct.DateTime.html [`bson::oid::ObjectId`]: https://docs.rs/bson/latest/bson/oid/struct.ObjectId.html @@ -448,10 +448,12 @@ mod date_scalar { [`time::UtcOffset`]: https://docs.rs/time/latest/time/struct.UtcOffset.html [`time::OffsetDateTime`]: https://docs.rs/time/latest/time/struct.OffsetDateTime.html [`url`]: https://docs.rs/url -[`Url`]: https://docs.rs/url/latest/url/struct.Url.html +[`url::Url`]: https://docs.rs/url/latest/url/struct.Url.html +[`URL`]: https://graphql-scalars.dev/docs/scalars/url [`UtcOffset`]: https://graphql-scalars.dev/docs/scalars/utc-offset [`uuid`]: https://docs.rs/uuid -[`Uuid`]: https://docs.rs/uuid/latest/uuid/struct.Uuid.html +[`uuid::Uuid`]: https://docs.rs/uuid/latest/uuid/struct.Uuid.html +[`UUID`]: https://graphql-scalars.dev/docs/scalars/uuid [Cargo feature]: https://doc.rust-lang.org/cargo/reference/features.html [GraphQL]: https://graphql.org [Juniper]: https://docs.rs/juniper diff --git a/juniper/CHANGELOG.md b/juniper/CHANGELOG.md index f677308f6..38e01a797 100644 --- a/juniper/CHANGELOG.md +++ b/juniper/CHANGELOG.md @@ -20,6 +20,8 @@ All user visible changes to `juniper` crate will be documented in this file. Thi - `time::PrimitiveDateTime`. - Renamed `Url` scalar to `URL` in types: - `url::Url`. + - Renamed `Uuid` scalar to `UUID` in types: + - `uuid::Uuid`. ### Added diff --git a/juniper/src/integrations/uuid.rs b/juniper/src/integrations/uuid.rs index 4fed7f5fa..bafcc4ae9 100644 --- a/juniper/src/integrations/uuid.rs +++ b/juniper/src/integrations/uuid.rs @@ -4,7 +4,21 @@ use crate::{graphql_scalar, InputValue, ScalarValue, Value}; -#[graphql_scalar(with = uuid_scalar, parse_token(String))] +/// [Universally Unique Identifier][0] (UUID). +/// +/// [`UUID` scalar][1] compliant. +/// +/// See also [`uuid::Uuid`][2] for details. +/// +/// [0]: https://en.wikipedia.org/wiki/Universally_unique_identifier +/// [1]: https://graphql-scalars.dev/docs/scalars/uuid +/// [2]: https://docs.rs/uuid/*/uuid/struct.Uuid.html +#[graphql_scalar( + name = "UUID", + with = uuid_scalar, + parse_token(String), + specified_by_url = "https://graphql-scalars.dev/docs/scalars/uuid", +)] type Uuid = uuid::Uuid; mod uuid_scalar { @@ -17,7 +31,7 @@ mod uuid_scalar { pub(super) fn from_input(v: &InputValue) -> Result { v.as_string_value() .ok_or_else(|| format!("Expected `String`, found: {v}")) - .and_then(|s| Uuid::parse_str(s).map_err(|e| format!("Failed to parse `Uuid`: {e}"))) + .and_then(|s| Uuid::parse_str(s).map_err(|e| format!("Failed to parse `UUID`: {e}"))) } }