Skip to content

Commit 681d242

Browse files
sgolltyranron
andauthored
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 <[email protected]>
1 parent b3a7ffc commit 681d242

File tree

5 files changed

+21
-7
lines changed

5 files changed

+21
-7
lines changed

book/src/types/scalars.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ mod date_scalar {
388388
| [Rust] type | [GraphQL] scalar | [Cargo feature] |
389389
|-----------------------------|-------------------|------------------|
390390
| [`bigdecimal::BigDecimal`] | `BigDecimal` | [`bigdecimal`] |
391-
| [`bson::oid::ObjectId`] | `ObjectId` | [`bson`] |
391+
| [`bson::oid::ObjectId`] | [`ObjectID`] | [`bson`] |
392392
| [`bson::DateTime`] | [`DateTime`] | [`bson`] |
393393
| [`chrono::NaiveDate`] | [`LocalDate`] | [`chrono`] |
394394
| [`chrono::NaiveTime`] | [`LocalTime`] | [`chrono`] |
@@ -437,6 +437,7 @@ mod date_scalar {
437437
[`LocalDate`]: https://graphql-scalars.dev/docs/scalars/local-date
438438
[`LocalDateTime`]: https://graphql-scalars.dev/docs/scalars/local-date-time
439439
[`LocalTime`]: https://graphql-scalars.dev/docs/scalars/local-time
440+
[`ObjectID`]: https://the-guild.dev/graphql/scalars/docs/scalars/object-id
440441
[`rust_decimal`]: https://docs.rs/rust_decimal
441442
[`ScalarValue`]: https://docs.rs/juniper/0.16.1/juniper/trait.ScalarValue.html
442443
[`serde`]: https://docs.rs/serde

juniper/CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ All user visible changes to `juniper` crate will be documented in this file. Thi
1414

1515
- Upgraded [`chrono-tz` crate] integration to [0.9 version](https://github.com/chronotope/chrono-tz/releases/tag/v0.9.0). ([#1252])
1616
- Bumped up [MSRV] to 1.75. ([#1272])
17-
- Corrected compliance with newer [graphql-scalars.dev] specs: ([#1275])
17+
- Corrected compliance with newer [graphql-scalars.dev] specs: ([#1275], [#1277])
1818
- Switched `LocalDateTime` scalars to `yyyy-MM-ddTHH:mm:ss` format in types:
1919
- `chrono::NaiveDateTime`.
2020
- `time::PrimitiveDateTime`.
@@ -29,6 +29,8 @@ All user visible changes to `juniper` crate will be documented in this file. Thi
2929
- `url::Url`.
3030
- Renamed `Uuid` scalar to `UUID` in types:
3131
- `uuid::Uuid`.
32+
- Renamed `ObjectId` scalar to `ObjectID` in types: ([#1277])
33+
- `bson::oid::ObjectId`.
3234

3335
### Added
3436

@@ -49,6 +51,7 @@ All user visible changes to `juniper` crate will be documented in this file. Thi
4951
[#1272]: /../../pull/1272
5052
[#1274]: /../../pull/1274
5153
[#1275]: /../../pull/1275
54+
[#1277]: /../../pull/1277
5255

5356

5457

juniper/src/integrations/bson.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,31 @@
44
//!
55
//! | Rust type | Format | GraphQL scalar |
66
//! |-------------------|-------------------|------------------|
7-
//! | [`oid::ObjectId`] | HEX string | `ObjectId` |
7+
//! | [`oid::ObjectId`] | HEX string | [`ObjectID`][s1] |
88
//! | [`DateTime`] | [RFC 3339] string | [`DateTime`][s4] |
99
//!
1010
//! [`DateTime`]: bson::DateTime
11-
//! [`ObjectId`]: bson::oid::ObjectId
11+
//! [`oid::ObjectId`]: bson::oid::ObjectId
1212
//! [RFC 3339]: https://datatracker.ietf.org/doc/html/rfc3339#section-5.6
13+
//! [s1]: https://graphql-scalars.dev/docs/scalars/object-id
1314
//! [s4]: https://graphql-scalars.dev/docs/scalars/date-time
1415
1516
use crate::{graphql_scalar, InputValue, ScalarValue, Value};
1617

1718
/// [BSON ObjectId][0] represented as a HEX string.
1819
///
20+
/// [`ObjectID` scalar][1] compliant.
21+
///
1922
/// See also [`bson::oid::ObjectId`][2] for details.
2023
///
2124
/// [0]: https://www.mongodb.com/docs/manual/reference/bson-types#objectid
25+
/// [1]: https://graphql-scalars.dev/docs/scalars/object-id
2226
/// [2]: https://docs.rs/bson/*/bson/oid/struct.ObjectId.html
2327
#[graphql_scalar(
28+
name = "ObjectID",
2429
with = object_id,
2530
parse_token(String),
26-
specified_by_url = "https://www.mongodb.com/docs/manual/reference/bson-types#objectid",
31+
specified_by_url = "https://graphql-scalars.dev/docs/scalars/object-id",
2732
)]
2833
type ObjectId = bson::oid::ObjectId;
2934

@@ -38,7 +43,7 @@ mod object_id {
3843
v.as_string_value()
3944
.ok_or_else(|| format!("Expected `String`, found: {v}"))
4045
.and_then(|s| {
41-
ObjectId::parse_str(s).map_err(|e| format!("Failed to parse `ObjectId`: {e}"))
46+
ObjectId::parse_str(s).map_err(|e| format!("Failed to parse `ObjectID`: {e}"))
4247
})
4348
}
4449
}

juniper/src/integrations/chrono.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ mod local_date_time {
200200
#[graphql_scalar(
201201
with = date_time,
202202
parse_token(String),
203+
specified_by_url = "https://graphql-scalars.dev/docs/scalars/date-time",
203204
where(
204205
Tz: TimeZone + FromFixedOffset,
205206
Tz::Offset: fmt::Display,

juniper/src/integrations/time.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,11 @@ mod local_date {
8383
///
8484
/// [1]: https://graphql-scalars.dev/docs/scalars/local-time
8585
/// [2]: https://docs.rs/time/*/time/struct.Time.html
86-
#[graphql_scalar(with = local_time, parse_token(String))]
86+
#[graphql_scalar(
87+
with = local_time,
88+
parse_token(String),
89+
specified_by_url = "https://graphql-scalars.dev/docs/scalars/local-time",
90+
)]
8791
pub type LocalTime = time::Time;
8892

8993
mod local_time {

0 commit comments

Comments
 (0)