0

I'm trying to use tokio-tungstenite to subscribe to a graphql endpoint. I've been able to establish a handshake with the server (ping and pongs get logged) but I can't figure out how to pass my subscription query correctly.

I thought it was supposed to be in the query string but I'm not exactly sure how it is supposed to be formatted. Here is what I've tried so far:

    use tungstenite::client::IntoClientRequest;

    let mut url = Url::parse("ws://localhost:3000/graphql").unwrap();

    let graphql_query = "\'subscription { updates(from: ["my-source"]) { timestamp } }\'";
    url.set_query(Some(&format!("payload={}", graphql_query)));

    let mut request = url.into_client_request()?;
    let headers = request.headers_mut();
    headers.insert("Sec-WebSocket-Protocol", "graphql-ws".parse().unwrap());

    match connect_async(request).await {
       //...snipped...
    }

0