Skip to content

Commit e7984a8

Browse files
committed
Fix tests
1 parent ea5f9fa commit e7984a8

File tree

7 files changed

+99
-105
lines changed

7 files changed

+99
-105
lines changed

juniper/src/value/scalar.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ pub trait ScalarValue:
522522
/// Boolean(bool),
523523
/// }
524524
///
525-
/// // Custom implementation of `ScalarValue::from_displayable()` method for specializing
525+
/// // Custom implementation of `ScalarValue::from_displayable()` method for specializing
526526
/// // an efficient conversions from `ArcStr` into `MyScalarValue`.
527527
/// fn from_arcstr<Str: Display + Any + ?Sized>(s: &Str) -> MyScalarValue {
528528
/// use juniper::AnyExt as _; // allows downcasting directly on types without `dyn`
@@ -531,7 +531,7 @@ pub trait ScalarValue:
531531
/// MyScalarValue::String(s.clone()) // `Clone`ing `ArcStr` is cheap
532532
/// } else {
533533
/// // We do not override `ScalarValue::from_displayable_non_static()` here,
534-
/// // since `arcstr` crate doesn't provide API for efficient conversion into
534+
/// // since `arcstr` crate doesn't provide API for efficient conversion into
535535
/// // an `ArcStr` for any `Display`able type, unfortunately.
536536
/// // The closest possible way is to use `arcstr::format!("{s}")` expression.
537537
/// // However, it actually expands to `ArcStr::from(fmt::format(format_args!("{s}")))`,

tests/codegen/fail/scalar/type_alias/attr_invalid_url.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use juniper::{graphql_scalar, Scalar, ScalarValue, Value};
1+
use juniper::{graphql_scalar, Scalar, ScalarValue};
22

33
struct ScalarSpecifiedByUrl;
44

@@ -13,8 +13,8 @@ type MyScalar = ScalarSpecifiedByUrl;
1313
mod scalar {
1414
use super::*;
1515

16-
pub(super) fn to_output<S: ScalarValue>(_: &ScalarSpecifiedByUrl) -> Value<S> {
17-
Value::scalar(0)
16+
pub(super) fn to_output(_: &ScalarSpecifiedByUrl) -> i32 {
17+
0
1818
}
1919

2020
pub(super) fn from_input(_: &Scalar<impl ScalarValue>) -> ScalarSpecifiedByUrl {

tests/codegen/fail/scalar/type_alias/attr_with_not_all_resolvers.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use juniper::{graphql_scalar, Value};
1+
use juniper::graphql_scalar;
22

33
struct Scalar;
44

@@ -7,8 +7,8 @@ struct Scalar;
77
type CustomScalar = Scalar;
88

99
impl Scalar {
10-
fn to_output(&self) -> Value {
11-
Value::scalar(0)
10+
fn to_output(&self) -> i32 {
11+
0
1212
}
1313
}
1414

tests/integration/tests/codegen_scalar_attr_derive_input.rs

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use std::fmt;
88

99
use chrono::{DateTime, TimeZone, Utc};
1010
use juniper::{
11-
ParseScalarResult, ParseScalarValue, Scalar, ScalarToken, ScalarValue, Value, execute,
12-
graphql_object, graphql_scalar, graphql_value, graphql_vars,
11+
ParseScalarResult, ParseScalarValue, Scalar, ScalarToken, ScalarValue, execute, graphql_object,
12+
graphql_scalar, graphql_value, graphql_vars,
1313
};
1414

1515
use self::common::{
@@ -27,8 +27,8 @@ mod trivial {
2727
struct Counter(i32);
2828

2929
impl Counter {
30-
fn to_output<S: ScalarValue>(&self) -> Value<S> {
31-
Value::scalar(self.0)
30+
fn to_output(&self) -> i32 {
31+
self.0
3232
}
3333

3434
fn from_input(i: i32) -> Self {
@@ -166,8 +166,8 @@ mod transparent_with_resolver {
166166
struct Counter(i32);
167167

168168
impl Counter {
169-
fn to_output<S: ScalarValue>(&self) -> Value<S> {
170-
Value::scalar(self.0 + 1)
169+
fn to_output(&self) -> i32 {
170+
self.0 + 1
171171
}
172172
}
173173

@@ -236,8 +236,8 @@ mod all_custom_resolvers {
236236
#[graphql(parse_token_with = parse_token)]
237237
struct Counter(i32);
238238

239-
fn to_output<S: ScalarValue>(v: &Counter) -> Value<S> {
240-
Value::scalar(v.0)
239+
fn to_output(v: &Counter) -> i32 {
240+
v.0
241241
}
242242

243243
fn parse_token<S: ScalarValue>(value: ScalarToken<'_>) -> ParseScalarResult<S> {
@@ -306,8 +306,8 @@ mod explicit_name {
306306
struct CustomCounter(i32);
307307

308308
impl CustomCounter {
309-
fn to_output<S: ScalarValue>(&self) -> Value<S> {
310-
Value::scalar(self.0)
309+
fn to_output(&self) -> i32 {
310+
self.0
311311
}
312312

313313
fn from_input(i: i32) -> Self {
@@ -381,8 +381,8 @@ mod delegated_parse_token {
381381
struct Counter(i32);
382382

383383
impl Counter {
384-
fn to_output<S: ScalarValue>(&self) -> Value<S> {
385-
Value::scalar(self.0)
384+
fn to_output(&self) -> i32 {
385+
self.0
386386
}
387387

388388
fn from_input(i: i32) -> Self {
@@ -455,10 +455,10 @@ mod multiple_delegated_parse_token {
455455
}
456456

457457
impl StringOrInt {
458-
fn to_output<S: ScalarValue>(&self) -> Value<S> {
458+
fn to_output<S: ScalarValue>(&self) -> S {
459459
match self {
460-
Self::String(s) => Value::scalar(s.to_owned()),
461-
Self::Int(i) => Value::scalar(*i),
460+
Self::String(s) => S::from_displayable(s),
461+
Self::Int(i) => (*i).into(),
462462
}
463463
}
464464

@@ -517,13 +517,12 @@ mod where_attribute {
517517
)]
518518
struct CustomDateTime<Tz: TimeZone>(DateTime<Tz>);
519519

520-
fn to_output<S, Tz>(v: &CustomDateTime<Tz>) -> Value<S>
520+
fn to_output<Tz>(v: &CustomDateTime<Tz>) -> prelude::String
521521
where
522-
S: ScalarValue,
523522
Tz: From<Utc> + TimeZone,
524523
Tz::Offset: fmt::Display,
525524
{
526-
Value::scalar(v.0.to_rfc3339())
525+
v.0.to_rfc3339()
527526
}
528527

529528
fn from_input<Tz>(s: &str) -> prelude::Result<CustomDateTime<Tz>, prelude::Box<str>>
@@ -588,8 +587,8 @@ mod with_self {
588587
struct Counter(i32);
589588

590589
impl Counter {
591-
fn to_output<S: ScalarValue>(&self) -> Value<S> {
592-
Value::scalar(self.0)
590+
fn to_output(&self) -> i32 {
591+
self.0
593592
}
594593

595594
fn from_input(i: i32) -> Self {
@@ -670,13 +669,12 @@ mod with_module {
670669
mod custom_date_time {
671670
use super::*;
672671

673-
pub(super) fn to_output<S, Tz>(v: &CustomDateTime<Tz>) -> Value<S>
672+
pub(super) fn to_output<Tz>(v: &CustomDateTime<Tz>) -> prelude::String
674673
where
675-
S: ScalarValue,
676674
Tz: From<Utc> + TimeZone,
677675
Tz::Offset: fmt::Display,
678676
{
679-
Value::scalar(v.0.to_rfc3339())
677+
v.0.to_rfc3339()
680678
}
681679

682680
pub(super) fn from_input<Tz>(
@@ -745,8 +743,8 @@ mod description_from_doc_comment {
745743
struct Counter(i32);
746744

747745
impl Counter {
748-
fn to_output<S: ScalarValue>(&self) -> Value<S> {
749-
Value::scalar(self.0)
746+
fn to_output(&self) -> i32 {
747+
self.0
750748
}
751749

752750
fn from_input(i: i32) -> Self {
@@ -820,8 +818,8 @@ mod description_from_attribute {
820818
struct Counter(i32);
821819

822820
impl Counter {
823-
fn to_output<S: ScalarValue>(&self) -> Value<S> {
824-
Value::scalar(self.0)
821+
fn to_output(&self) -> i32 {
822+
self.0
825823
}
826824

827825
fn from_input(i: i32) -> Self {
@@ -895,8 +893,8 @@ mod custom_scalar {
895893
struct Counter(i32);
896894

897895
impl Counter {
898-
fn to_output<S: ScalarValue>(&self) -> Value<S> {
899-
Value::scalar(self.0)
896+
fn to_output(&self) -> i32 {
897+
self.0
900898
}
901899

902900
fn from_input(i: i32) -> Self {
@@ -970,8 +968,8 @@ mod generic_scalar {
970968
struct Counter(i32);
971969

972970
impl Counter {
973-
fn to_output<S: ScalarValue>(&self) -> Value<S> {
974-
Value::scalar(self.0)
971+
fn to_output(&self) -> i32 {
972+
self.0
975973
}
976974

977975
fn from_input(i: i32) -> Self {
@@ -1044,8 +1042,8 @@ mod bounded_generic_scalar {
10441042
struct Counter(i32);
10451043

10461044
impl Counter {
1047-
fn to_output<S: ScalarValue>(&self) -> Value<S> {
1048-
Value::scalar(self.0)
1045+
fn to_output(&self) -> i32 {
1046+
self.0
10491047
}
10501048

10511049
fn from_input(i: i32) -> Self {

tests/integration/tests/codegen_scalar_attr_type_alias.rs

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use std::fmt;
66

77
use chrono::{DateTime, TimeZone, Utc};
88
use juniper::{
9-
ParseScalarResult, ParseScalarValue, Scalar, ScalarToken, ScalarValue, Value, execute,
10-
graphql_object, graphql_scalar, graphql_value, graphql_vars,
9+
ParseScalarResult, ParseScalarValue, Scalar, ScalarToken, ScalarValue, execute, graphql_object,
10+
graphql_scalar, graphql_value, graphql_vars,
1111
};
1212

1313
use self::common::{
@@ -33,8 +33,8 @@ mod all_custom_resolvers {
3333
)]
3434
type Counter = CustomCounter;
3535

36-
fn to_output<S: ScalarValue>(v: &Counter) -> Value<S> {
37-
Value::scalar(v.0)
36+
fn to_output(v: &Counter) -> i32 {
37+
v.0
3838
}
3939

4040
fn parse_token<S: ScalarValue>(value: ScalarToken<'_>) -> ParseScalarResult<S> {
@@ -109,8 +109,8 @@ mod explicit_name {
109109
)]
110110
type CounterScalar = CustomCounter;
111111

112-
fn to_output<S: ScalarValue>(v: &CounterScalar) -> Value<S> {
113-
Value::scalar(v.0)
112+
fn to_output(v: &CounterScalar) -> i32 {
113+
v.0
114114
}
115115

116116
fn parse_token<S: ScalarValue>(value: ScalarToken<'_>) -> ParseScalarResult<S> {
@@ -204,8 +204,8 @@ mod delegated_parse_token {
204204
)]
205205
type Counter = CustomCounter;
206206

207-
fn to_output<S: ScalarValue>(v: &Counter) -> Value<S> {
208-
Value::scalar(v.0)
207+
fn to_output(v: &Counter) -> i32 {
208+
v.0
209209
}
210210

211211
struct QueryRoot;
@@ -278,10 +278,10 @@ mod multiple_delegated_parse_token {
278278
)]
279279
type StringOrInt = StringOrIntScalar;
280280

281-
fn to_output<S: ScalarValue>(v: &StringOrInt) -> Value<S> {
281+
fn to_output<S: ScalarValue>(v: &StringOrInt) -> S {
282282
match v {
283-
StringOrInt::String(s) => Value::scalar(s.to_owned()),
284-
StringOrInt::Int(i) => Value::scalar(*i),
283+
StringOrInt::String(s) => S::from_displayable(s),
284+
StringOrInt::Int(i) => (*i).into(),
285285
}
286286
}
287287

@@ -341,13 +341,12 @@ mod where_attribute {
341341
)]
342342
type CustomDateTime<Tz> = CustomDateTimeScalar<Tz>;
343343

344-
fn to_output<S, Tz>(v: &CustomDateTime<Tz>) -> Value<S>
344+
fn to_output<Tz>(v: &CustomDateTime<Tz>) -> prelude::String
345345
where
346-
S: ScalarValue,
347346
Tz: From<Utc> + TimeZone,
348347
Tz::Offset: fmt::Display,
349348
{
350-
Value::scalar(v.0.to_rfc3339())
349+
v.0.to_rfc3339()
351350
}
352351

353352
fn from_input<Tz>(s: &str) -> prelude::Result<CustomDateTime<Tz>, prelude::Box<str>>
@@ -414,8 +413,8 @@ mod with_self {
414413
type Counter = CustomCounter;
415414

416415
impl Counter {
417-
fn to_output<S: ScalarValue>(&self) -> Value<S> {
418-
Value::scalar(self.0)
416+
fn to_output(&self) -> i32 {
417+
self.0
419418
}
420419

421420
fn from_input(i: i32) -> Self {
@@ -498,13 +497,12 @@ mod with_module {
498497
mod custom_date_time {
499498
use super::*;
500499

501-
pub(super) fn to_output<S, Tz>(v: &CustomDateTime<Tz>) -> Value<S>
500+
pub(super) fn to_output<Tz>(v: &CustomDateTime<Tz>) -> prelude::String
502501
where
503-
S: ScalarValue,
504502
Tz: From<Utc> + TimeZone,
505503
Tz::Offset: fmt::Display,
506504
{
507-
Value::scalar(v.0.to_rfc3339())
505+
v.0.to_rfc3339()
508506
}
509507

510508
pub(super) fn from_input<Tz>(
@@ -577,8 +575,8 @@ mod description_from_doc_comment {
577575
mod counter {
578576
use super::*;
579577

580-
pub(super) fn to_output<S: ScalarValue>(v: &Counter) -> Value<S> {
581-
Value::scalar(v.0)
578+
pub(super) fn to_output(v: &Counter) -> i32 {
579+
v.0
582580
}
583581

584582
pub(super) fn from_input(i: i32) -> Counter {
@@ -660,8 +658,8 @@ mod description_from_attribute {
660658
mod counter {
661659
use super::*;
662660

663-
pub(super) fn to_output<S: ScalarValue>(v: &Counter) -> Value<S> {
664-
Value::scalar(v.0)
661+
pub(super) fn to_output(v: &Counter) -> i32 {
662+
v.0
665663
}
666664

667665
pub(super) fn from_input(i: i32) -> Counter {
@@ -743,8 +741,8 @@ mod custom_scalar {
743741
mod counter {
744742
use super::*;
745743

746-
pub(super) fn to_output<S: ScalarValue>(v: &Counter) -> Value<S> {
747-
Value::scalar(v.0)
744+
pub(super) fn to_output(v: &Counter) -> i32 {
745+
v.0
748746
}
749747

750748
pub(super) fn from_input(i: i32) -> Counter {
@@ -826,8 +824,8 @@ mod generic_scalar {
826824
mod counter {
827825
use super::*;
828826

829-
pub(super) fn to_output<S: ScalarValue>(v: &Counter) -> Value<S> {
830-
Value::scalar(v.0)
827+
pub(super) fn to_output(v: &Counter) -> i32 {
828+
v.0
831829
}
832830

833831
pub(super) fn from_input(i: i32) -> Counter {
@@ -909,8 +907,8 @@ mod bounded_generic_scalar {
909907
mod counter {
910908
use super::*;
911909

912-
pub(super) fn to_output<S: ScalarValue>(v: &Counter) -> Value<S> {
913-
Value::scalar(v.0)
910+
pub(super) fn to_output(v: &Counter) -> i32 {
911+
v.0
914912
}
915913

916914
pub(super) fn from_input(i: i32) -> Counter {

0 commit comments

Comments
 (0)