pub struct GraphQLWebSocket<Sink, Stream, E, OnConnInit, OnPing> { /* private fields */ }
Expand description
A Websocket connection for GraphQL subscription.
Implementations§
source§impl<S, E> GraphQLWebSocket<SplitSink<S, Message>, SplitStream<S>, E, DefaultOnConnInitType, DefaultOnPingType>
impl<S, E> GraphQLWebSocket<SplitSink<S, Message>, SplitStream<S>, E, DefaultOnConnInitType, DefaultOnPingType>
sourcepub fn new(stream: S, executor: E, protocol: GraphQLProtocol) -> Self
pub fn new(stream: S, executor: E, protocol: GraphQLProtocol) -> Self
Create a GraphQLWebSocket
object.
source§impl<Sink, Stream, E> GraphQLWebSocket<Sink, Stream, E, DefaultOnConnInitType, DefaultOnPingType>
impl<Sink, Stream, E> GraphQLWebSocket<Sink, Stream, E, DefaultOnConnInitType, DefaultOnPingType>
sourcepub fn new_with_pair(
sink: Sink,
stream: Stream,
executor: E,
protocol: GraphQLProtocol,
) -> Self
pub fn new_with_pair( sink: Sink, stream: Stream, executor: E, protocol: GraphQLProtocol, ) -> Self
Create a GraphQLWebSocket
object with sink and stream objects.
source§impl<Sink, Stream, E, OnConnInit, OnConnInitFut, OnPing, OnPingFut> GraphQLWebSocket<Sink, Stream, E, OnConnInit, OnPing>where
Sink: Sink<Message>,
Stream: Stream<Item = Result<Message, Error>>,
E: Executor,
OnConnInit: FnOnce(Value) -> OnConnInitFut + Send + 'static,
OnConnInitFut: Future<Output = Result<Data>> + Send + 'static,
OnPing: FnOnce(Option<&Data>, Option<Value>) -> OnPingFut + Clone + Send + 'static,
OnPingFut: Future<Output = Result<Option<Value>>> + Send + 'static,
impl<Sink, Stream, E, OnConnInit, OnConnInitFut, OnPing, OnPingFut> GraphQLWebSocket<Sink, Stream, E, OnConnInit, OnPing>where
Sink: Sink<Message>,
Stream: Stream<Item = Result<Message, Error>>,
E: Executor,
OnConnInit: FnOnce(Value) -> OnConnInitFut + Send + 'static,
OnConnInitFut: Future<Output = Result<Data>> + Send + 'static,
OnPing: FnOnce(Option<&Data>, Option<Value>) -> OnPingFut + Clone + Send + 'static,
OnPingFut: Future<Output = Result<Option<Value>>> + Send + 'static,
sourcepub fn with_data(self, data: Data) -> Self
pub fn with_data(self, data: Data) -> Self
Specify the initial subscription context data, usually you can get something from the incoming request to create it.
sourcepub fn on_connection_init<F, R>(
self,
callback: F,
) -> GraphQLWebSocket<Sink, Stream, E, F, OnPing>
pub fn on_connection_init<F, R>( self, callback: F, ) -> GraphQLWebSocket<Sink, Stream, E, F, OnPing>
Specify a callback function to be called when the connection is initialized.
You can get something from the payload of GQL_CONNECTION_INIT
message to create Data
.
The data returned by this callback function will be merged with the data
specified by [with_data
].
sourcepub fn on_ping<F, R>(
self,
callback: F,
) -> GraphQLWebSocket<Sink, Stream, E, OnConnInit, F>
pub fn on_ping<F, R>( self, callback: F, ) -> GraphQLWebSocket<Sink, Stream, E, OnConnInit, F>
Specify a ping callback function.
This function if present, will be called with the data sent by the
client in the Ping
message.
The function should return the data to be sent in the Pong
message.
NOTE: Only used for the graphql-ws
protocol.
sourcepub fn keepalive_timeout(self, timeout: impl Into<Option<Duration>>) -> Self
pub fn keepalive_timeout(self, timeout: impl Into<Option<Duration>>) -> Self
Sets a timeout for receiving an acknowledgement of the keep-alive ping.
If the ping is not acknowledged within the timeout, the connection will be closed.
NOTE: Only used for the graphql-ws
protocol.