Skip to content

Commit 6bb34b9

Browse files
dependabot[bot]tyranrongrantperry
authored
Upgrade 'bson' crate to 2.0 version (#932, #979)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Kai Ren <[email protected]> Co-authored-by: Grant Perry <[email protected]>
1 parent 4c76e93 commit 6bb34b9

File tree

3 files changed

+24
-19
lines changed

3 files changed

+24
-19
lines changed

juniper/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- `#[graphql_object]` and `#[graphql_subscription]` macros expansion now preserves defined `impl` blocks "as is" and reuses defined methods in opaque way. ([#971](https://github.com/graphql-rust/juniper/pull/971)
66
- `rename = "<policy>"` attribute's argument renamed to `rename_all = "<policy>"`. ([#971](https://github.com/graphql-rust/juniper/pull/971)
7+
- Upgrade `bson` feature to [2.0 version of its crate](https://github.com/mongodb/bson-rust/releases/tag/v2.0.0). ([#979](https://github.com/graphql-rust/juniper/pull/979)
78

89
## Features
910

juniper/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ juniper_codegen = { version = "0.15.7", path = "../juniper_codegen" }
3636

3737
anyhow = { version = "1.0.32", optional = true, default-features = false }
3838
async-trait = "0.1.39"
39-
bson = { version = "1.0", optional = true }
39+
bson = { version = "2.0", features = ["chrono-0_4"], optional = true }
4040
chrono = { version = "0.4", default-features = false, optional = true }
4141
chrono-tz = { version = "0.5", default-features = false, optional = true }
4242
fnv = "1.0.3"
@@ -51,6 +51,9 @@ static_assertions = "1.1"
5151
url = { version = "2.0", optional = true }
5252
uuid = { version = "0.8", default-features = false, optional = true }
5353

54+
[target.'cfg(target_arch = "wasm32")'.dependencies]
55+
getrandom = { version = "0.2", features = ["js"] }
56+
5457
[dev-dependencies]
5558
bencher = "0.1.2"
5659
pretty_assertions = "0.7.1"

juniper/src/integrations/bson.rs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ use bson::{oid::ObjectId, DateTime as UtcDateTime};
44
use chrono::prelude::*;
55

66
use crate::{
7+
graphql_scalar,
78
parser::{ParseError, ScalarToken, Token},
89
value::ParseScalarResult,
910
Value,
1011
};
1112

12-
#[crate::graphql_scalar(description = "ObjectId")]
13+
#[graphql_scalar(description = "ObjectId")]
1314
impl<S> GraphQLScalar for ObjectId
1415
where
1516
S: ScalarValue,
@@ -19,37 +20,36 @@ where
1920
}
2021

2122
fn from_input_value(v: &InputValue) -> Option<ObjectId> {
22-
v.as_string_value()
23-
.and_then(|s| ObjectId::with_string(s).ok())
23+
v.as_string_value().and_then(|s| Self::parse_str(s).ok())
2424
}
2525

2626
fn from_str<'a>(value: ScalarToken<'a>) -> ParseScalarResult<'a, S> {
27-
if let ScalarToken::String(value) = value {
28-
Ok(S::from(value.to_owned()))
27+
if let ScalarToken::String(val) = value {
28+
Ok(S::from(val.to_owned()))
2929
} else {
3030
Err(ParseError::UnexpectedToken(Token::Scalar(value)))
3131
}
3232
}
3333
}
3434

35-
#[crate::graphql_scalar(description = "UtcDateTime")]
35+
#[graphql_scalar(description = "UtcDateTime")]
3636
impl<S> GraphQLScalar for UtcDateTime
3737
where
3838
S: ScalarValue,
3939
{
4040
fn resolve(&self) -> Value {
41-
Value::scalar((*self).to_rfc3339())
41+
Value::scalar((*self).to_chrono().to_rfc3339())
4242
}
4343

4444
fn from_input_value(v: &InputValue) -> Option<UtcDateTime> {
4545
v.as_string_value()
4646
.and_then(|s| (s.parse::<DateTime<Utc>>().ok()))
47-
.map(UtcDateTime)
47+
.map(Self::from_chrono)
4848
}
4949

5050
fn from_str<'a>(value: ScalarToken<'a>) -> ParseScalarResult<'a, S> {
51-
if let ScalarToken::String(value) = value {
52-
Ok(S::from(value.to_owned()))
51+
if let ScalarToken::String(val) = value {
52+
Ok(S::from(val.to_owned()))
5353
} else {
5454
Err(ParseError::UnexpectedToken(Token::Scalar(value)))
5555
}
@@ -58,28 +58,29 @@ where
5858

5959
#[cfg(test)]
6060
mod test {
61-
use crate::{value::DefaultScalarValue, InputValue};
6261
use bson::{oid::ObjectId, DateTime as UtcDateTime};
63-
use chrono::prelude::*;
62+
use chrono::{DateTime, Utc};
63+
64+
use crate::{value::DefaultScalarValue, FromInputValue, InputValue};
6465

6566
#[test]
6667
fn objectid_from_input_value() {
6768
let raw = "53e37d08776f724e42000000";
68-
let input: InputValue<DefaultScalarValue> = InputValue::scalar(raw.to_string());
69+
let input = InputValue::<DefaultScalarValue>::scalar(raw.to_string());
6970

70-
let parsed: ObjectId = crate::FromInputValue::from_input_value(&input).unwrap();
71-
let id = ObjectId::with_string(raw).unwrap();
71+
let parsed: ObjectId = FromInputValue::from_input_value(&input).unwrap();
72+
let id = ObjectId::parse_str(raw).unwrap();
7273

7374
assert_eq!(parsed, id);
7475
}
7576

7677
#[test]
7778
fn utcdatetime_from_input_value() {
7879
let raw = "2020-03-23T17:38:32.446+00:00";
79-
let input: InputValue<DefaultScalarValue> = InputValue::scalar(raw.to_string());
80+
let input = InputValue::<DefaultScalarValue>::scalar(raw.to_string());
8081

81-
let parsed: UtcDateTime = crate::FromInputValue::from_input_value(&input).unwrap();
82-
let date_time = UtcDateTime(
82+
let parsed: UtcDateTime = FromInputValue::from_input_value(&input).unwrap();
83+
let date_time = UtcDateTime::from_chrono(
8384
DateTime::parse_from_rfc3339(raw)
8485
.unwrap()
8586
.with_timezone(&Utc),

0 commit comments

Comments
 (0)