Correct GraphQL scalars compliance for third-party crates even more (#1277)
- rename `ObjectId` scalar to `ObjectID` in `bson::oid::ObjectId` type - add missing `@specifiedBy` URLs for `chrono` and `time` crates' types Co-authored-by: Kai Ren <tyranron@gmail.com>
This commit is contained in:
parent
b3a7ffc6a2
commit
681d242823
5 changed files with 21 additions and 7 deletions
|
@ -388,7 +388,7 @@ mod date_scalar {
|
||||||
| [Rust] type | [GraphQL] scalar | [Cargo feature] |
|
| [Rust] type | [GraphQL] scalar | [Cargo feature] |
|
||||||
|-----------------------------|-------------------|------------------|
|
|-----------------------------|-------------------|------------------|
|
||||||
| [`bigdecimal::BigDecimal`] | `BigDecimal` | [`bigdecimal`] |
|
| [`bigdecimal::BigDecimal`] | `BigDecimal` | [`bigdecimal`] |
|
||||||
| [`bson::oid::ObjectId`] | `ObjectId` | [`bson`] |
|
| [`bson::oid::ObjectId`] | [`ObjectID`] | [`bson`] |
|
||||||
| [`bson::DateTime`] | [`DateTime`] | [`bson`] |
|
| [`bson::DateTime`] | [`DateTime`] | [`bson`] |
|
||||||
| [`chrono::NaiveDate`] | [`LocalDate`] | [`chrono`] |
|
| [`chrono::NaiveDate`] | [`LocalDate`] | [`chrono`] |
|
||||||
| [`chrono::NaiveTime`] | [`LocalTime`] | [`chrono`] |
|
| [`chrono::NaiveTime`] | [`LocalTime`] | [`chrono`] |
|
||||||
|
@ -437,6 +437,7 @@ mod date_scalar {
|
||||||
[`LocalDate`]: https://graphql-scalars.dev/docs/scalars/local-date
|
[`LocalDate`]: https://graphql-scalars.dev/docs/scalars/local-date
|
||||||
[`LocalDateTime`]: https://graphql-scalars.dev/docs/scalars/local-date-time
|
[`LocalDateTime`]: https://graphql-scalars.dev/docs/scalars/local-date-time
|
||||||
[`LocalTime`]: https://graphql-scalars.dev/docs/scalars/local-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`]: https://docs.rs/rust_decimal
|
||||||
[`ScalarValue`]: https://docs.rs/juniper/0.16.1/juniper/trait.ScalarValue.html
|
[`ScalarValue`]: https://docs.rs/juniper/0.16.1/juniper/trait.ScalarValue.html
|
||||||
[`serde`]: https://docs.rs/serde
|
[`serde`]: https://docs.rs/serde
|
||||||
|
|
|
@ -14,7 +14,7 @@ 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])
|
- 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])
|
- Bumped up [MSRV] to 1.75. ([#1272])
|
||||||
- Corrected compliance with newer [graphql-scalars.dev] specs: ([#1275])
|
- Corrected compliance with newer [graphql-scalars.dev] specs: ([#1275], [#1277])
|
||||||
- Switched `LocalDateTime` scalars to `yyyy-MM-ddTHH:mm:ss` format in types:
|
- Switched `LocalDateTime` scalars to `yyyy-MM-ddTHH:mm:ss` format in types:
|
||||||
- `chrono::NaiveDateTime`.
|
- `chrono::NaiveDateTime`.
|
||||||
- `time::PrimitiveDateTime`.
|
- `time::PrimitiveDateTime`.
|
||||||
|
@ -29,6 +29,8 @@ All user visible changes to `juniper` crate will be documented in this file. Thi
|
||||||
- `url::Url`.
|
- `url::Url`.
|
||||||
- Renamed `Uuid` scalar to `UUID` in types:
|
- Renamed `Uuid` scalar to `UUID` in types:
|
||||||
- `uuid::Uuid`.
|
- `uuid::Uuid`.
|
||||||
|
- Renamed `ObjectId` scalar to `ObjectID` in types: ([#1277])
|
||||||
|
- `bson::oid::ObjectId`.
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
|
@ -49,6 +51,7 @@ All user visible changes to `juniper` crate will be documented in this file. Thi
|
||||||
[#1272]: /../../pull/1272
|
[#1272]: /../../pull/1272
|
||||||
[#1274]: /../../pull/1274
|
[#1274]: /../../pull/1274
|
||||||
[#1275]: /../../pull/1275
|
[#1275]: /../../pull/1275
|
||||||
|
[#1277]: /../../pull/1277
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,26 +4,31 @@
|
||||||
//!
|
//!
|
||||||
//! | Rust type | Format | GraphQL scalar |
|
//! | Rust type | Format | GraphQL scalar |
|
||||||
//! |-------------------|-------------------|------------------|
|
//! |-------------------|-------------------|------------------|
|
||||||
//! | [`oid::ObjectId`] | HEX string | `ObjectId` |
|
//! | [`oid::ObjectId`] | HEX string | [`ObjectID`][s1] |
|
||||||
//! | [`DateTime`] | [RFC 3339] string | [`DateTime`][s4] |
|
//! | [`DateTime`] | [RFC 3339] string | [`DateTime`][s4] |
|
||||||
//!
|
//!
|
||||||
//! [`DateTime`]: bson::DateTime
|
//! [`DateTime`]: bson::DateTime
|
||||||
//! [`ObjectId`]: bson::oid::ObjectId
|
//! [`oid::ObjectId`]: bson::oid::ObjectId
|
||||||
//! [RFC 3339]: https://datatracker.ietf.org/doc/html/rfc3339#section-5.6
|
//! [RFC 3339]: https://datatracker.ietf.org/doc/html/rfc3339#section-5.6
|
||||||
|
//! [s1]: https://graphql-scalars.dev/docs/scalars/object-id
|
||||||
//! [s4]: https://graphql-scalars.dev/docs/scalars/date-time
|
//! [s4]: https://graphql-scalars.dev/docs/scalars/date-time
|
||||||
|
|
||||||
use crate::{graphql_scalar, InputValue, ScalarValue, Value};
|
use crate::{graphql_scalar, InputValue, ScalarValue, Value};
|
||||||
|
|
||||||
/// [BSON ObjectId][0] represented as a HEX string.
|
/// [BSON ObjectId][0] represented as a HEX string.
|
||||||
///
|
///
|
||||||
|
/// [`ObjectID` scalar][1] compliant.
|
||||||
|
///
|
||||||
/// See also [`bson::oid::ObjectId`][2] for details.
|
/// See also [`bson::oid::ObjectId`][2] for details.
|
||||||
///
|
///
|
||||||
/// [0]: https://www.mongodb.com/docs/manual/reference/bson-types#objectid
|
/// [0]: https://www.mongodb.com/docs/manual/reference/bson-types#objectid
|
||||||
|
/// [1]: https://graphql-scalars.dev/docs/scalars/object-id
|
||||||
/// [2]: https://docs.rs/bson/*/bson/oid/struct.ObjectId.html
|
/// [2]: https://docs.rs/bson/*/bson/oid/struct.ObjectId.html
|
||||||
#[graphql_scalar(
|
#[graphql_scalar(
|
||||||
|
name = "ObjectID",
|
||||||
with = object_id,
|
with = object_id,
|
||||||
parse_token(String),
|
parse_token(String),
|
||||||
specified_by_url = "https://www.mongodb.com/docs/manual/reference/bson-types#objectid",
|
specified_by_url = "https://graphql-scalars.dev/docs/scalars/object-id",
|
||||||
)]
|
)]
|
||||||
type ObjectId = bson::oid::ObjectId;
|
type ObjectId = bson::oid::ObjectId;
|
||||||
|
|
||||||
|
@ -38,7 +43,7 @@ mod object_id {
|
||||||
v.as_string_value()
|
v.as_string_value()
|
||||||
.ok_or_else(|| format!("Expected `String`, found: {v}"))
|
.ok_or_else(|| format!("Expected `String`, found: {v}"))
|
||||||
.and_then(|s| {
|
.and_then(|s| {
|
||||||
ObjectId::parse_str(s).map_err(|e| format!("Failed to parse `ObjectId`: {e}"))
|
ObjectId::parse_str(s).map_err(|e| format!("Failed to parse `ObjectID`: {e}"))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -200,6 +200,7 @@ mod local_date_time {
|
||||||
#[graphql_scalar(
|
#[graphql_scalar(
|
||||||
with = date_time,
|
with = date_time,
|
||||||
parse_token(String),
|
parse_token(String),
|
||||||
|
specified_by_url = "https://graphql-scalars.dev/docs/scalars/date-time",
|
||||||
where(
|
where(
|
||||||
Tz: TimeZone + FromFixedOffset,
|
Tz: TimeZone + FromFixedOffset,
|
||||||
Tz::Offset: fmt::Display,
|
Tz::Offset: fmt::Display,
|
||||||
|
|
|
@ -83,7 +83,11 @@ mod local_date {
|
||||||
///
|
///
|
||||||
/// [1]: https://graphql-scalars.dev/docs/scalars/local-time
|
/// [1]: https://graphql-scalars.dev/docs/scalars/local-time
|
||||||
/// [2]: https://docs.rs/time/*/time/struct.Time.html
|
/// [2]: https://docs.rs/time/*/time/struct.Time.html
|
||||||
#[graphql_scalar(with = local_time, parse_token(String))]
|
#[graphql_scalar(
|
||||||
|
with = local_time,
|
||||||
|
parse_token(String),
|
||||||
|
specified_by_url = "https://graphql-scalars.dev/docs/scalars/local-time",
|
||||||
|
)]
|
||||||
pub type LocalTime = time::Time;
|
pub type LocalTime = time::Time;
|
||||||
|
|
||||||
mod local_time {
|
mod local_time {
|
||||||
|
|
Loading…
Reference in a new issue