1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
use futures::Stream;
use crate::{FieldError, GraphQLValue, IntoFieldError, ScalarValue};
pub trait IntoFieldResult<T, S> {
type Item;
fn into_result(self) -> Result<T, FieldError<S>>;
}
impl<T, E, S> IntoFieldResult<T, S> for Result<T, E>
where
T: IntoFieldResult<T, S>,
E: IntoFieldError<S>,
{
type Item = T::Item;
fn into_result(self) -> Result<T, FieldError<S>> {
self.map_err(E::into_field_error)
}
}
impl<T, S> IntoFieldResult<T, S> for T
where
T: Stream,
{
type Item = T::Item;
fn into_result(self) -> Result<T, FieldError<S>> {
Ok(self)
}
}
pub struct StreamItem;
pub struct StreamResult;
pub struct ResultStreamItem;
pub struct ResultStreamResult;
pub trait ExtractTypeFromStream<T, S>
where
S: ScalarValue,
{
type Item: GraphQLValue<S>;
}
impl<T, I, S> ExtractTypeFromStream<StreamItem, S> for T
where
T: futures::Stream<Item = I>,
I: GraphQLValue<S>,
S: ScalarValue,
{
type Item = I;
}
impl<Ty, T, E, S> ExtractTypeFromStream<StreamResult, S> for Ty
where
Ty: futures::Stream<Item = Result<T, E>>,
T: GraphQLValue<S>,
S: ScalarValue,
{
type Item = T;
}
impl<T, I, E, S> ExtractTypeFromStream<ResultStreamItem, S> for Result<T, E>
where
T: futures::Stream<Item = I>,
I: GraphQLValue<S>,
S: ScalarValue,
{
type Item = I;
}
impl<T, E, I, ER, S> ExtractTypeFromStream<ResultStreamResult, S> for Result<T, E>
where
T: futures::Stream<Item = Result<I, ER>>,
I: GraphQLValue<S>,
S: ScalarValue,
{
type Item = I;
}