1
1
use crate :: {
2
2
http:: { GraphQLRequest , GraphQLResponse } ,
3
3
parser:: Spanning ,
4
- types:: base:: { is_excluded, merge_key_into} ,
5
- Arguments , BoxFuture , Executor , FieldError , GraphQLType , Object , ScalarValue , Selection , Value ,
6
- ValuesStream ,
4
+ types:: base:: { is_excluded, merge_key_into, GraphQLType , GraphQLValue } ,
5
+ Arguments , BoxFuture , DefaultScalarValue , Executor , FieldError , Object , ScalarValue , Selection ,
6
+ Value , ValuesStream ,
7
7
} ;
8
8
9
9
/// Global subscription coordinator trait.
@@ -58,23 +58,24 @@ where
58
58
/// server integration crates.
59
59
pub trait SubscriptionConnection < ' a , S > : futures:: Stream < Item = GraphQLResponse < ' a , S > > { }
60
60
61
- /**
62
- This trait adds resolver logic with asynchronous subscription execution logic
63
- on GraphQL types. It should be used with `GraphQLValue` in order to implement
64
- subscription resolvers on GraphQL objects.
65
-
66
- Subscription-related convenience macros expand into an implementation of this
67
- trait and `GraphQLValue` for the given type.
68
-
69
- See trait methods for more detailed explanation on how this trait works.
70
- */
71
- pub trait GraphQLSubscriptionType < S > : GraphQLType < S > + Send + Sync
61
+ /// Extension of [`GraphQLValue`] trait with asynchronous [subscription][1] execution logic.
62
+ /// It should be used with [`GraphQLValue`] in order to implement [subscription][1] resolvers on
63
+ /// [GraphQL objects][2].
64
+ ///
65
+ /// [Subscription][1]-related convenience macros expand into an implementation of this trait and
66
+ /// [`GraphQLValue`] for the given type.
67
+ ///
68
+ /// See trait methods for more detailed explanation on how this trait works.
69
+ ///
70
+ /// [1]: https://spec.graphql.org/June2018/#sec-Subscription
71
+ /// [2]: https://spec.graphql.org/June2018/#sec-Objects
72
+ pub trait GraphQLSubscriptionValue < S = DefaultScalarValue > : GraphQLValue < S > + Send + Sync
72
73
where
73
74
Self :: Context : Send + Sync ,
74
75
Self :: TypeInfo : Send + Sync ,
75
76
S : ScalarValue + Send + Sync ,
76
77
{
77
- /// Resolve into `Value<ValuesStream>`
78
+ /// Resolves into `Value<ValuesStream>`.
78
79
///
79
80
/// ## Default implementation
80
81
///
@@ -169,6 +170,32 @@ where
169
170
}
170
171
}
171
172
173
+ crate :: sa:: assert_obj_safe!( GraphQLSubscriptionValue <Context = ( ) , TypeInfo = ( ) >) ;
174
+
175
+ /// Extension of [`GraphQLType`] trait with asynchronous [subscription][1] execution logic.
176
+ ///
177
+ /// It's automatically implemented for [`GraphQLSubscriptionValue`] and [`GraphQLType`]
178
+ /// implementors, so doesn't require manual or code-generated implementation.
179
+ ///
180
+ /// [1]: https://spec.graphql.org/June2018/#sec-Subscription
181
+ pub trait GraphQLSubscriptionType < S = DefaultScalarValue > :
182
+ GraphQLSubscriptionValue < S > + GraphQLType < S >
183
+ where
184
+ Self :: Context : Send + Sync ,
185
+ Self :: TypeInfo : Send + Sync ,
186
+ S : ScalarValue + Send + Sync ,
187
+ {
188
+ }
189
+
190
+ impl < S , T > GraphQLSubscriptionType < S > for T
191
+ where
192
+ T : GraphQLSubscriptionValue < S > + GraphQLType < S > ,
193
+ T :: Context : Send + Sync ,
194
+ T :: TypeInfo : Send + Sync ,
195
+ S : ScalarValue + Send + Sync ,
196
+ {
197
+ }
198
+
172
199
/// Wrapper function around `resolve_selection_set_into_stream_recursive`.
173
200
/// This wrapper is necessary because async fns can not be recursive.
174
201
/// Panics if executor's current selection set is None.
@@ -184,7 +211,7 @@ where
184
211
' e : ' fut ,
185
212
' ref_e : ' fut ,
186
213
' res : ' fut ,
187
- T : GraphQLSubscriptionType < S , Context = CtxT > + ?Sized ,
214
+ T : GraphQLSubscriptionValue < S , Context = CtxT > + ?Sized ,
188
215
T :: TypeInfo : Send + Sync ,
189
216
S : ScalarValue + Send + Sync ,
190
217
CtxT : Send + Sync ,
@@ -203,7 +230,7 @@ async fn resolve_selection_set_into_stream_recursive<'i, 'inf, 'ref_e, 'e, 'res,
203
230
executor : & ' ref_e Executor < ' ref_e , ' e , CtxT , S > ,
204
231
) -> Value < ValuesStream < ' res , S > >
205
232
where
206
- T : GraphQLSubscriptionType < S , Context = CtxT > + Send + Sync + ?Sized ,
233
+ T : GraphQLSubscriptionValue < S , Context = CtxT > + Send + Sync + ?Sized ,
207
234
T :: TypeInfo : Send + Sync ,
208
235
S : ScalarValue + Send + Sync ,
209
236
CtxT : Send + Sync ,
0 commit comments