pub fn new_with_initializer<Query, Mutation, Subscription, F, R>(
        schema: Schema<Query, Mutation, Subscription>,
        initializer: F,
    ) -> Self
    where
        Query: ObjectType + 'static,
        Mutation: ObjectType + 'static,
        Subscription: SubscriptionType + 'static,
        F: FnOnce(serde_json::Value) -> R + Unpin + Send + Sync + Clone + 'static,
        R: Future<Output = Result<Data>> + Send + 'static,
    {
        let endpoint = tide_websockets::WebSocket::<S, _>::new(move |request, connection| {
            let schema = schema.clone();
            let initializer = initializer.clone();
            async move {
                let protocol = match request
                    .header("sec-websocket-protocol")
                    .map(|value| value.as_str())
                    .and_then(|protocols| {
                        protocols
                            .split(',')
                            .find_map(|p| WebSocketProtocols::from_str(p.trim()).ok())
                    }) {
                    Some(protocol) => protocol,
                    None => {
                        // default to the prior standard
                        WebSocketProtocols::SubscriptionsTransportWS
                    }
                };

                let sink = connection.clone();
                let mut stream = AGWebSocket::with_data(
                    schema.clone(),
                    connection
                        .take_while(|msg| future::ready(msg.is_ok()))
                        .map(Result::unwrap)
                        .map(Message::into_data),
                    initializer,
                    protocol,
                );
                while let Some(data) = stream.next().await {
                    match data {
                        WsMessage::Text(text) => {
                            if sink.send_string(text).await.is_err() {
                                break;
                            }
                        }
                        WsMessage::Close(_code, _msg) => {
                            // TODO: Send close frame
                            break;
                        }
                    }
                }

                Ok(())
            }
        })
        .with_protocols(&["graphql-transport-ws", "graphql-ws"]);
        Self {
            inner: Box::pin(endpoint),
        }
    }
/// Create a graphql subscription endpoint.
///
/// Specifies that a function converts the init payload to data.
Create a graphql subscription endpoint.
Specifies that a function converts the init payload to data.
Create a graphql subscription endpoint . Specifies that a function converts the init payload to data .
pub fn new_with_initializer<Query, Mutation, Subscription, F, R>(
        schema: Schema<Query, Mutation, Subscription>,
        initializer: F,
    ) -> Self
    where
        Query: ObjectType + 'static,
        Mutation: ObjectType + 'static,
        Subscription: SubscriptionType + 'static,
        F: FnOnce(serde_json::Value) -> R + Unpin + Send + Sync + Clone + 'static,
        R: Future<Output = Result<Data>> + Send + 'static,
    {
        let endpoint = tide_websockets::WebSocket::<S, _>::new(move |request, connection| {
            let schema = schema.clone();
            let initializer = initializer.clone();
            async move {
                let protocol = match request
                    .header("sec-websocket-protocol")
                    .map(|value| value.as_str())
                    .and_then(|protocols| {
                        protocols
                            .split(',')
                            .find_map(|p| WebSocketProtocols::from_str(p.trim()).ok())
                    }) {
                    Some(protocol) => protocol,
                    None => {
                        // default to the prior standard
                        WebSocketProtocols::SubscriptionsTransportWS
                    }
                };
                let sink = connection.clone();
                let mut stream = AGWebSocket::with_data(
                    schema.clone(),
                    connection
                        .take_while(|msg| future::ready(msg.is_ok()))
                        .map(Result::unwrap)
                        .map(Message::into_data),
                    initializer,
                    protocol,
                );
                while let Some(data) = stream.next().await {
                    match data {
                        WsMessage::Text(text) => {
                            if sink.send_string(text).await.is_err() {
                                break;
                            }
                        }
                        WsMessage::Close(_code, _msg) => {
                            // TODO: Send close frame
                            break;
                        }
                    }
                }
                Ok(())
            }
        })
        .with_protocols(&["graphql-transport-ws", "graphql-ws"]);
        Self {
            inner: Box::pin(endpoint),
        }
    }
pub fn new_with_initializer < Query , Mutation , Subscription , F , R > ( schema : Schema < Query , Mutation , Subscription > , initializer : F , ) -> Self where Query : ObjectType + ' static , Mutation : ObjectType + ' static , Subscription : SubscriptionType + ' static , F : FnOnce ( serde_json :: Value ) -> R + Unpin + Send + Sync + Clone + ' static , R : Future < Output = Result < Data > > + Send + ' static , { let endpoint = tide_websockets :: WebSocket :: < S , _ > :: new ( move | request , connection | { let schema = schema . clone ( ) ; let initializer = initializer . clone ( ) ; async move { let protocol = match request . header ( " " ) . map ( | value | value . as_str ( ) ) . and_then ( | protocols | { protocols . split ( ',' ) . find_map ( | p | WebSocketProtocols :: from_str ( p . trim ( ) ) . ok ( ) ) } ) { Some ( protocol ) => protocol , None => { // default to the prior standard WebSocketProtocols :: SubscriptionsTransportWS } } ; let sink = connection . clone ( ) ; let mut stream = AGWebSocket :: with_data ( schema . clone ( ) , connection . take_while ( | msg | future :: ready ( msg . is_ok ( ) ) ) . map ( Result :: unwrap ) . map ( Message :: into_data ) , initializer , protocol , ) ; while let Some ( data ) = stream . next ( ) . await { match data { WsMessage :: Text ( text ) => { if sink . send_string ( text ) . await . is_err ( ) { break ; } } WsMessage :: Close ( _code , _msg ) => { // TODO: Send close frame break ; } } } Ok ( ( ) ) } } ) . with_protocols ( & [ " " , " " ] ) ; Self { inner : Box :: pin ( endpoint ) , } }
Create a graphql subscription endpoint.
Create a graphql subscription endpoint .
schema
Schema<Query, Mutation, Subscription>
initializer
F
schema
Schema<Query, Mutation, Subscription>
initializer
F