11use crate :: {
22 http:: { GraphQLRequest , GraphQLResponse } ,
33 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 ,
77} ;
88
99/// Global subscription coordinator trait.
@@ -58,23 +58,24 @@ where
5858/// server integration crates.
5959pub trait SubscriptionConnection < ' a , S > : futures:: Stream < Item = GraphQLResponse < ' a , S > > { }
6060
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
7273where
7374 Self :: Context : Send + Sync ,
7475 Self :: TypeInfo : Send + Sync ,
7576 S : ScalarValue + Send + Sync ,
7677{
77- /// Resolve into `Value<ValuesStream>`
78+ /// Resolves into `Value<ValuesStream>`.
7879 ///
7980 /// ## Default implementation
8081 ///
@@ -169,6 +170,32 @@ where
169170 }
170171}
171172
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+
172199/// Wrapper function around `resolve_selection_set_into_stream_recursive`.
173200/// This wrapper is necessary because async fns can not be recursive.
174201/// Panics if executor's current selection set is None.
@@ -184,7 +211,7 @@ where
184211 ' e : ' fut ,
185212 ' ref_e : ' fut ,
186213 ' res : ' fut ,
187- T : GraphQLSubscriptionType < S , Context = CtxT > + ?Sized ,
214+ T : GraphQLSubscriptionValue < S , Context = CtxT > + ?Sized ,
188215 T :: TypeInfo : Send + Sync ,
189216 S : ScalarValue + Send + Sync ,
190217 CtxT : Send + Sync ,
@@ -203,7 +230,7 @@ async fn resolve_selection_set_into_stream_recursive<'i, 'inf, 'ref_e, 'e, 'res,
203230 executor : & ' ref_e Executor < ' ref_e , ' e , CtxT , S > ,
204231) -> Value < ValuesStream < ' res , S > >
205232where
206- T : GraphQLSubscriptionType < S , Context = CtxT > + Send + Sync + ?Sized ,
233+ T : GraphQLSubscriptionValue < S , Context = CtxT > + Send + Sync + ?Sized ,
207234 T :: TypeInfo : Send + Sync ,
208235 S : ScalarValue + Send + Sync ,
209236 CtxT : Send + Sync ,
0 commit comments