Skip to content

Commit 348f94d

Browse files
committed
Leverage derive_more::From and derive_more::Into
1 parent 6036544 commit 348f94d

File tree

15 files changed

+116
-127
lines changed

15 files changed

+116
-127
lines changed

juniper/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ bson = { version = "2.4", optional = true }
5151
chrono = { version = "0.4.30", features = ["alloc"], default-features = false, optional = true }
5252
chrono-tz = { version = "0.10", default-features = false, optional = true }
5353
compact_str = "0.9"
54-
derive_more = { version = "2.0", features = ["debug", "display", "error"] }
54+
derive_more = { version = "2.0", features = ["debug", "display", "error", "from", "into"] }
5555
fnv = "1.0.5"
5656
futures = { version = "0.3.22", features = ["alloc"], default-features = false }
5757
graphql-parser = { version = "0.4", optional = true }

juniper/src/executor_tests/enums.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::{
22
GraphQLEnum,
3-
GraphQLError::ValidationError,
43
executor::Variables,
54
graphql_value, graphql_vars,
65
parser::SourcePosition,
@@ -99,10 +98,11 @@ async fn does_not_accept_string_literals() {
9998

10099
assert_eq!(
101100
error,
102-
ValidationError(vec![RuleError::new(
101+
RuleError::new(
103102
r#"Invalid value for argument "color", reason: Invalid value ""RED"" for enum "Color""#,
104103
&[SourcePosition::new(18, 0, 18)],
105-
)])
104+
)
105+
.into(),
106106
);
107107
}
108108

@@ -138,10 +138,11 @@ async fn does_not_accept_incorrect_enum_name_in_variables() {
138138

139139
assert_eq!(
140140
error,
141-
ValidationError(vec![RuleError::new(
141+
RuleError::new(
142142
r#"Variable "$color" got invalid value. Invalid value for enum "Color"."#,
143143
&[SourcePosition::new(8, 0, 8)],
144-
)]),
144+
)
145+
.into(),
145146
);
146147
}
147148

@@ -162,9 +163,10 @@ async fn does_not_accept_incorrect_type_in_variables() {
162163

163164
assert_eq!(
164165
error,
165-
ValidationError(vec![RuleError::new(
166+
RuleError::new(
166167
r#"Variable "$color" got invalid value. Expected "Color", found not a string or enum."#,
167168
&[SourcePosition::new(8, 0, 8)],
168-
)]),
169+
)
170+
.into(),
169171
);
170172
}

juniper/src/executor_tests/variables.rs

Lines changed: 50 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::{
2-
GraphQLError::ValidationError,
32
GraphQLInputObject, GraphQLScalar, InputValue, ScalarValue, Value,
43
executor::Variables,
54
graphql_object, graphql_value, graphql_vars,
@@ -281,10 +280,11 @@ async fn variable_error_on_nested_non_null() {
281280

282281
assert_eq!(
283282
error,
284-
ValidationError(vec![RuleError::new(
283+
RuleError::new(
285284
r#"Variable "$input" got invalid value. In field "c": Expected "String!", found null."#,
286285
&[SourcePosition::new(8, 0, 8)],
287-
)]),
286+
)
287+
.into(),
288288
);
289289
}
290290

@@ -305,10 +305,10 @@ async fn variable_error_on_incorrect_type() {
305305

306306
assert_eq!(
307307
error,
308-
ValidationError(vec![RuleError::new(
308+
RuleError::new(
309309
r#"Variable "$input" got invalid value. Expected "TestInputObject", found not an object."#,
310310
&[SourcePosition::new(8, 0, 8)],
311-
)]),
311+
).into(),
312312
);
313313
}
314314

@@ -334,10 +334,11 @@ async fn variable_error_on_omit_non_null() {
334334

335335
assert_eq!(
336336
error,
337-
ValidationError(vec![RuleError::new(
337+
RuleError::new(
338338
r#"Variable "$input" got invalid value. In field "c": Expected "String!", found null."#,
339339
&[SourcePosition::new(8, 0, 8)],
340-
)]),
340+
)
341+
.into(),
341342
);
342343
}
343344

@@ -363,7 +364,7 @@ async fn variable_multiple_errors_with_nesting() {
363364

364365
assert_eq!(
365366
error,
366-
ValidationError(vec![
367+
vec![
367368
RuleError::new(
368369
r#"Variable "$input" got invalid value. In field "na": In field "c": Expected "String!", found null."#,
369370
&[SourcePosition::new(8, 0, 8)],
@@ -372,7 +373,7 @@ async fn variable_multiple_errors_with_nesting() {
372373
r#"Variable "$input" got invalid value. In field "nb": Expected "String!", found null."#,
373374
&[SourcePosition::new(8, 0, 8)],
374375
),
375-
]),
376+
].into(),
376377
);
377378
}
378379

@@ -400,10 +401,11 @@ async fn variable_error_on_additional_field() {
400401

401402
assert_eq!(
402403
error,
403-
ValidationError(vec![RuleError::new(
404+
RuleError::new(
404405
r#"Variable "$input" got invalid value. In field "extra": Unknown field."#,
405406
&[SourcePosition::new(8, 0, 8)],
406-
)]),
407+
)
408+
.into(),
407409
);
408410
}
409411

@@ -510,10 +512,11 @@ async fn does_not_allow_non_nullable_input_to_be_omitted_in_variable() {
510512

511513
assert_eq!(
512514
error,
513-
ValidationError(vec![RuleError::new(
515+
RuleError::new(
514516
r#"Variable "$value" of required type "String!" was not provided."#,
515517
&[SourcePosition::new(8, 0, 8)],
516-
)]),
518+
)
519+
.into(),
517520
);
518521
}
519522

@@ -534,10 +537,11 @@ async fn does_not_allow_non_nullable_input_to_be_set_to_null_in_variable() {
534537

535538
assert_eq!(
536539
error,
537-
ValidationError(vec![RuleError::new(
540+
RuleError::new(
538541
r#"Variable "$value" of required type "String!" was not provided."#,
539542
&[SourcePosition::new(8, 0, 8)],
540-
)]),
543+
)
544+
.into(),
541545
);
542546
}
543547

@@ -632,10 +636,11 @@ async fn does_not_allow_non_null_lists_to_be_null() {
632636

633637
assert_eq!(
634638
error,
635-
ValidationError(vec![RuleError::new(
639+
RuleError::new(
636640
r#"Variable "$input" of required type "[String]!" was not provided."#,
637641
&[SourcePosition::new(8, 0, 8)],
638-
)]),
642+
)
643+
.into(),
639644
);
640645
}
641646

@@ -715,10 +720,10 @@ async fn does_not_allow_lists_of_non_null_to_contain_null() {
715720

716721
assert_eq!(
717722
error,
718-
ValidationError(vec![RuleError::new(
723+
RuleError::new(
719724
r#"Variable "$input" got invalid value. In element #1: Expected "String!", found null."#,
720725
&[SourcePosition::new(8, 0, 8)],
721-
)]),
726+
).into(),
722727
);
723728
}
724729

@@ -739,10 +744,10 @@ async fn does_not_allow_non_null_lists_of_non_null_to_contain_null() {
739744

740745
assert_eq!(
741746
error,
742-
ValidationError(vec![RuleError::new(
747+
RuleError::new(
743748
r#"Variable "$input" got invalid value. In element #1: Expected "String!", found null."#,
744749
&[SourcePosition::new(8, 0, 8)],
745-
)]),
750+
).into(),
746751
);
747752
}
748753

@@ -763,10 +768,11 @@ async fn does_not_allow_non_null_lists_of_non_null_to_be_null() {
763768

764769
assert_eq!(
765770
error,
766-
ValidationError(vec![RuleError::new(
771+
RuleError::new(
767772
r#"Variable "$input" of required type "[String!]!" was not provided."#,
768773
&[SourcePosition::new(8, 0, 8)],
769-
)]),
774+
)
775+
.into(),
770776
);
771777
}
772778

@@ -915,11 +921,12 @@ async fn does_not_allow_missing_required_field() {
915921

916922
assert_eq!(
917923
error,
918-
ValidationError(vec![RuleError::new(
924+
RuleError::new(
919925
"Invalid value for argument \"arg\", \
920926
reason: \"ExampleInputObject\" is missing fields: \"b\"",
921927
&[SourcePosition::new(20, 0, 20)],
922-
)]),
928+
)
929+
.into(),
923930
);
924931
}
925932

@@ -940,12 +947,13 @@ async fn does_not_allow_null_in_required_field() {
940947

941948
assert_eq!(
942949
error,
943-
ValidationError(vec![RuleError::new(
950+
RuleError::new(
944951
"Invalid value for argument \"arg\", \
945952
reason: Error on \"ExampleInputObject\" field \"b\": \
946953
\"null\" specified for not nullable type \"Int!\"",
947954
&[SourcePosition::new(20, 0, 20)],
948-
)]),
955+
)
956+
.into(),
949957
);
950958
}
951959

@@ -966,10 +974,11 @@ async fn does_not_allow_missing_variable_for_required_field() {
966974

967975
assert_eq!(
968976
error,
969-
ValidationError(vec![RuleError::new(
977+
RuleError::new(
970978
r#"Variable "$var" of required type "Int!" was not provided."#,
971979
&[SourcePosition::new(8, 0, 8)],
972-
)]),
980+
)
981+
.into(),
973982
);
974983
}
975984

@@ -990,10 +999,11 @@ async fn does_not_allow_null_variable_for_required_field() {
990999

9911000
assert_eq!(
9921001
error,
993-
ValidationError(vec![RuleError::new(
1002+
RuleError::new(
9941003
r#"Variable "$var" of required type "Int!" was not provided."#,
9951004
&[SourcePosition::new(8, 0, 8)],
996-
)]),
1005+
)
1006+
.into(),
9971007
);
9981008
}
9991009

@@ -1091,11 +1101,12 @@ mod integers {
10911101

10921102
assert_eq!(
10931103
error,
1094-
ValidationError(vec![RuleError::new(
1104+
RuleError::new(
10951105
"Variable \"$var\" got invalid value. Expected input scalar `Int`. \
10961106
Got: `10`. Details: Expected `Int`, found: 10.",
10971107
&[SourcePosition::new(8, 0, 8)],
1098-
)]),
1108+
)
1109+
.into(),
10991110
);
11001111
}
11011112

@@ -1116,12 +1127,13 @@ mod integers {
11161127

11171128
assert_eq!(
11181129
error,
1119-
ValidationError(vec![RuleError::new(
1130+
RuleError::new(
11201131
"Variable \"$var\" got invalid value. \
11211132
Expected input scalar `Int`. Got: `\"10\"`. \
11221133
Details: Expected `Int`, found: \"10\".",
11231134
&[SourcePosition::new(8, 0, 8)],
1124-
)]),
1135+
)
1136+
.into(),
11251137
);
11261138
}
11271139
}
@@ -1176,12 +1188,13 @@ mod floats {
11761188

11771189
assert_eq!(
11781190
error,
1179-
ValidationError(vec![RuleError::new(
1191+
RuleError::new(
11801192
"Variable \"$var\" got invalid value. \
11811193
Expected input scalar `Float`. Got: `\"10\"`. \
11821194
Details: Expected `Float`, found: \"10\".",
11831195
&[SourcePosition::new(8, 0, 8)],
1184-
)]),
1196+
)
1197+
.into(),
11851198
);
11861199
}
11871200
}

juniper/src/integrations/jiff.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
5353
use std::str;
5454

55-
use derive_more::with_trait::{Debug, Display, Error};
55+
use derive_more::with_trait::{Debug, Display, Error, Into};
5656

5757
use crate::{InputValue, ScalarValue, Value, graphql_scalar};
5858

@@ -443,7 +443,7 @@ pub enum TimeZoneParsingError {
443443
parse_token(String),
444444
specified_by_url = "https://graphql-scalars.dev/docs/scalars/time-zone",
445445
)]
446-
#[derive(Clone, Debug, Display, Eq, PartialEq)]
446+
#[derive(Clone, Debug, Display, Eq, Into, PartialEq)]
447447
#[display("{}", _0.iana_name().expect("failed to display `TimeZone`: no IANA name"))]
448448
pub struct TimeZone(jiff::tz::TimeZone);
449449

@@ -468,12 +468,6 @@ impl str::FromStr for TimeZone {
468468
}
469469
}
470470

471-
impl From<TimeZone> for jiff::tz::TimeZone {
472-
fn from(value: TimeZone) -> Self {
473-
value.0
474-
}
475-
}
476-
477471
mod time_zone {
478472
use super::*;
479473

0 commit comments

Comments
 (0)