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