Skip to content

Commit

Permalink
Corrections and adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
tyranron committed Aug 15, 2024
1 parent df17a80 commit 4579114
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
5 changes: 4 additions & 1 deletion juniper/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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])
- 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:
- `chrono::NaiveDateTime`.
- `time::PrimitiveDateTime`.
Expand All @@ -29,6 +29,8 @@ All user visible changes to `juniper` crate will be documented in this file. Thi
- `url::Url`.
- Renamed `Uuid` scalar to `UUID` in types:
- `uuid::Uuid`.
- Renamed `ObjectId` scalar to `ObjectID` in types: ([#1277])
- `bson::oid::ObjectId`.

### Added

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



Expand Down
11 changes: 8 additions & 3 deletions juniper/src/integrations/bson.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,28 @@
//!
//! | Rust type | Format | GraphQL scalar |
//! |-------------------|-------------------|------------------|
//! | [`oid::ObjectId`] | HEX string | `ObjectId` |
//! | [`oid::ObjectId`] | HEX string | [`ObjectID`][s1] |
//! | [`DateTime`] | [RFC 3339] string | [`DateTime`][s4] |
//!
//! [`DateTime`]: bson::DateTime
//! [`ObjectId`]: bson::oid::ObjectId
//! [`oid::ObjectId`]: bson::oid::ObjectId
//! [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
use crate::{graphql_scalar, InputValue, ScalarValue, Value};

/// [BSON ObjectId][0] represented as a HEX string.
///
/// [`ObjectID` scalar][1] compliant.
///
/// See also [`bson::oid::ObjectId`][2] for details.
///
/// [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
#[graphql_scalar(
name = "ObjectID",
with = object_id,
parse_token(String),
specified_by_url = "https://graphql-scalars.dev/docs/scalars/object-id",
Expand All @@ -38,7 +43,7 @@ mod object_id {
v.as_string_value()
.ok_or_else(|| format!("Expected `String`, found: {v}"))
.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}"))
})
}
}
Expand Down

0 comments on commit 4579114

Please sign in to comment.