Skip to content

Commit 5d1e9e0

Browse files
committed
misc fixes etc
1 parent 5bc4737 commit 5d1e9e0

File tree

4 files changed

+101
-12
lines changed

4 files changed

+101
-12
lines changed

cynic-codegen/src/scalar_derive/snapshots/cynic_codegen__scalar_derive__tests__snapshot_scalar_derive.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
source: cynic-codegen/src/scalar_derive/tests.rs
33
expression: "format_code(format!(\"{}\", tokens))"
4+
snapshot_kind: text
45
---
56
#[automatically_derived]
67
impl cynic::serde::Serialize for DateTime {
@@ -31,9 +32,9 @@ impl cynic::schema::IsScalar<schema::DateTime> for DateTime {
3132
}
3233
}
3334
#[automatically_derived]
34-
impl cynic::schema::IsOutputScalar<schema::DateTime> for DateTime {
35+
impl<'de> cynic::schema::IsOutputScalar<'de, schema::DateTime> for DateTime {
3536
type SchemaType = schema::DateTime;
36-
fn deserialize<'de, D>(deserializer: D) -> Result<Self, D::Error>
37+
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
3738
where
3839
D: cynic::serde::Deserializer<'de>,
3940
{
@@ -45,4 +46,3 @@ impl schema::variable::Variable for DateTime {
4546
const TYPE: cynic::variables::VariableType = cynic::variables::VariableType::Named("DateTime");
4647
}
4748
cynic :: impl_coercions ! (DateTime [] [] , schema :: DateTime);
48-

cynic/src/schema.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,25 +60,38 @@ pub trait HasArgument<ArgumentMarker> {
6060

6161
// TODO: Think about the names of the scalar traits....
6262

63-
/// Indicates that a type is a scalar that maps to the given schema scalar.
63+
/// Indicates that a type can be used as a graphql scalar in input position
6464
///
65-
/// Note that this type is actually implemented on the users types.
65+
/// This should be implemented for any scalar types that need to be used as arguments
66+
/// or appear on fields of input objects.
67+
///
68+
/// The SchemaType generic parameter should be set to a marker type from the users schema module -
69+
/// this indicates which scalar(s) this type represents in a graphql schema.
6670
pub trait IsScalar<SchemaType> {
6771
/// The schema marker type this scalar represents.
6872
type SchemaType;
6973

70-
// TODO: serialize should maybe be on an OutputScalar trait
74+
/// Serializes Self using the provided Serializer
7175
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
7276
where
7377
S: Serializer;
7478
}
7579

7680
// TODO: serialize should maybe be on an InputScalar trait
7781
// or maybe just ScalarSerialize/ScalarDeserialize? not sure...
82+
83+
/// Indicates that a type can be used as a graphql scalar in output position
84+
///
85+
/// This should be implemented for any scalars that are used as fields in types implementing
86+
/// QueryFragment.
87+
///
88+
/// The SchemaType generic parameter should be set to a marker type from the users schema module -
89+
/// this indicates which scalar(s) this type represents in a graphql schema.
7890
pub trait IsOutputScalar<'de, SchemaType>: Sized {
7991
/// The schema marker type this scalar represents.
8092
type SchemaType;
8193

94+
/// Deserializes Self using the provided Deserializer
8295
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
8396
where
8497
D: Deserializer<'de>;

tests/ui-tests/tests/cases/flatten-fail.stderr

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,50 @@ note: required by a bound in `SelectionBuilder::<'a, SchemaType, VariablesFields
3636
| FieldType: FlattensInto<Flattened>,
3737
| ^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `SelectionBuilder::<'a, SchemaType, VariablesFields>::select_flattened_field`
3838

39+
error[E0277]: the trait bound `i32: IsOutputScalar<'_, std::string::String>` is not satisfied
40+
--> tests/cases/flatten-fail.rs:3:10
41+
|
42+
3 | #[derive(cynic::QueryFragment, Debug, PartialEq)]
43+
| ^^^^^^^^^^^^^^^^^^^^ the trait `IsOutputScalar<'_, std::string::String>` is not implemented for `i32`, which is required by `Flattened<ScalarDeserialize<Vec<i32>, std::option::Option<Vec<std::option::Option<std::string::String>>>>>: Deserialize<'de>`
44+
|
45+
= help: the trait `IsOutputScalar<'_, i32>` is implemented for `i32`
46+
= help: for that trait implementation, expected `i32`, found `std::string::String`
47+
= note: required for `std::option::Option<i32>` to implement `IsOutputScalar<'_, std::option::Option<std::string::String>>`
48+
= note: 2 redundant requirements hidden
49+
= note: required for `std::option::Option<Vec<std::option::Option<i32>>>` to implement `IsOutputScalar<'_, std::option::Option<Vec<std::option::Option<std::string::String>>>>`
50+
= note: required for `Flattened<ScalarDeserialize<Vec<i32>, std::option::Option<Vec<std::option::Option<std::string::String>>>>>` to implement `Deserialize<'de>`
51+
note: required by a bound in `next_value`
52+
--> $CARGO/serde-1.0.210/src/de/mod.rs
53+
|
54+
| fn next_value<V>(&mut self) -> Result<V, Self::Error>
55+
| ---------- required by a bound in this associated function
56+
| where
57+
| V: Deserialize<'de>,
58+
| ^^^^^^^^^^^^^^^^ required by this bound in `MapAccess::next_value`
59+
= note: this error originates in the derive macro `cynic::QueryFragment` (in Nightly builds, run with -Z macro-backtrace for more info)
60+
61+
error[E0277]: the trait bound `f64: IsOutputScalar<'_, std::string::String>` is not satisfied
62+
--> tests/cases/flatten-fail.rs:3:10
63+
|
64+
3 | #[derive(cynic::QueryFragment, Debug, PartialEq)]
65+
| ^^^^^^^^^^^^^^^^^^^^ the trait `IsOutputScalar<'_, std::string::String>` is not implemented for `f64`, which is required by `Flattened<ScalarDeserialize<std::option::Option<Vec<f64>>, std::option::Option<Vec<std::option::Option<std::string::String>>>>>: Deserialize<'de>`
66+
|
67+
= help: the trait `IsOutputScalar<'_, f64>` is implemented for `f64`
68+
= help: for that trait implementation, expected `f64`, found `std::string::String`
69+
= note: required for `std::option::Option<f64>` to implement `IsOutputScalar<'_, std::option::Option<std::string::String>>`
70+
= note: 2 redundant requirements hidden
71+
= note: required for `std::option::Option<Vec<std::option::Option<f64>>>` to implement `IsOutputScalar<'_, std::option::Option<Vec<std::option::Option<std::string::String>>>>`
72+
= note: required for `Flattened<ScalarDeserialize<std::option::Option<Vec<f64>>, std::option::Option<Vec<std::option::Option<std::string::String>>>>>` to implement `Deserialize<'de>`
73+
note: required by a bound in `next_value`
74+
--> $CARGO/serde-1.0.210/src/de/mod.rs
75+
|
76+
| fn next_value<V>(&mut self) -> Result<V, Self::Error>
77+
| ---------- required by a bound in this associated function
78+
| where
79+
| V: Deserialize<'de>,
80+
| ^^^^^^^^^^^^^^^^ required by this bound in `MapAccess::next_value`
81+
= note: this error originates in the derive macro `cynic::QueryFragment` (in Nightly builds, run with -Z macro-backtrace for more info)
82+
3983
error[E0277]: the trait bound `std::option::Option<Vec<std::option::Option<schema::FilmCharactersEdge>>>: FlattensInto<Vec<std::string::String>>` is not satisfied
4084
--> tests/cases/flatten-fail.rs:19:16
4185
|
Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,42 @@
1-
error[E0277]: the trait bound `u64: IsScalar<i32>` is not satisfied
1+
error[E0277]: the trait bound `u64: IsOutputScalar<'_, i32>` is not satisfied
22
--> tests/cases/wrong-scalar-type.rs:15:21
33
|
44
15 | episode_id: Option<u64>,
5-
| ^^^^^^ the trait `IsScalar<i32>` is not implemented for `u64`, which is required by `std::option::Option<u64>: IsScalar<std::option::Option<i32>>`
5+
| ^^^^^^ the trait `IsOutputScalar<'_, i32>` is not implemented for `u64`, which is required by `std::option::Option<u64>: IsOutputScalar<'_, std::option::Option<i32>>`
66
|
7-
= help: the following other types implement trait `IsScalar<SchemaType>`:
8-
<f64 as IsScalar<f64>>
9-
<i32 as IsScalar<i32>>
10-
= note: required for `std::option::Option<u64>` to implement `IsScalar<std::option::Option<i32>>`
7+
= help: the following other types implement trait `IsOutputScalar<'de, SchemaType>`:
8+
<f64 as IsOutputScalar<'de, f64>>
9+
<i32 as IsOutputScalar<'de, i32>>
10+
= note: required for `std::option::Option<u64>` to implement `IsOutputScalar<'_, std::option::Option<i32>>`
11+
12+
error[E0277]: the trait bound `u64: IsOutputScalar<'_, i32>` is not satisfied
13+
--> tests/cases/wrong-scalar-type.rs:15:21
14+
|
15+
15 | episode_id: Option<u64>,
16+
| ^^^^^^^^^^^ the trait `IsOutputScalar<'_, i32>` is not implemented for `u64`, which is required by `std::option::Option<u64>: IsOutputScalar<'_, std::option::Option<i32>>`
17+
|
18+
= help: the following other types implement trait `IsOutputScalar<'de, SchemaType>`:
19+
<f64 as IsOutputScalar<'de, f64>>
20+
<i32 as IsOutputScalar<'de, i32>>
21+
= note: required for `std::option::Option<u64>` to implement `IsOutputScalar<'_, std::option::Option<i32>>`
22+
23+
error[E0277]: the trait bound `u64: IsOutputScalar<'_, i32>` is not satisfied
24+
--> tests/cases/wrong-scalar-type.rs:12:14
25+
|
26+
12 | #[derive(cynic::QueryFragment, Debug)]
27+
| ^^^^^^^^^^^^^^^^^^^^ the trait `IsOutputScalar<'_, i32>` is not implemented for `u64`, which is required by `ScalarDeserialize<std::option::Option<u64>, std::option::Option<i32>>: Deserialize<'de>`
28+
|
29+
= help: the following other types implement trait `IsOutputScalar<'de, SchemaType>`:
30+
<f64 as IsOutputScalar<'de, f64>>
31+
<i32 as IsOutputScalar<'de, i32>>
32+
= note: required for `std::option::Option<u64>` to implement `IsOutputScalar<'_, std::option::Option<i32>>`
33+
= note: required for `ScalarDeserialize<std::option::Option<u64>, std::option::Option<i32>>` to implement `Deserialize<'de>`
34+
note: required by a bound in `next_value`
35+
--> $CARGO/serde-1.0.210/src/de/mod.rs
36+
|
37+
| fn next_value<V>(&mut self) -> Result<V, Self::Error>
38+
| ---------- required by a bound in this associated function
39+
| where
40+
| V: Deserialize<'de>,
41+
| ^^^^^^^^^^^^^^^^ required by this bound in `MapAccess::next_value`
42+
= note: this error originates in the derive macro `cynic::QueryFragment` (in Nightly builds, run with -Z macro-backtrace for more info)

0 commit comments

Comments
 (0)