pub trait SubscriptionCoordinator<'a, CtxT, S>where
S: ScalarValue,{
type Connection: SubscriptionConnection<S>;
type Error;
// Required method
fn subscribe(
&'a self,
_: &'a GraphQLRequest<S>,
_: &'a CtxT,
) -> BoxFuture<'a, Result<Self::Connection, Self::Error>>;
}
Expand description
Global subscription coordinator trait.
With regular queries we could get away with not having some in-between layer, but for subscriptions it is needed, otherwise the integration crates can become really messy and cumbersome to maintain. Subscriptions are also quite a bit more stability sensitive than regular queries, they provide a great vector for DOS attacks and can bring down a server easily if not handled right.
This trait implementation might include the following features:
- contains the schema
- keeps track of subscription connections
- handles subscription start, maintains a global subscription id
- max subscription limits / concurrency limits
- subscription de-duplication
- reconnection on connection loss / buffering / re-synchronisation
'a
is how long spawned connections live for.
Required Associated Types§
Sourcetype Connection: SubscriptionConnection<S>
type Connection: SubscriptionConnection<S>
Type of SubscriptionConnection
s this SubscriptionCoordinator
returns
Sourcetype Error
type Error
Type of error while trying to spawn SubscriptionConnection
Required Methods§
Sourcefn subscribe(
&'a self,
_: &'a GraphQLRequest<S>,
_: &'a CtxT,
) -> BoxFuture<'a, Result<Self::Connection, Self::Error>>
fn subscribe( &'a self, _: &'a GraphQLRequest<S>, _: &'a CtxT, ) -> BoxFuture<'a, Result<Self::Connection, Self::Error>>
Return SubscriptionConnection
based on given GraphQLRequest