graphql-ws-client icon indicating copy to clipboard operation
graphql-ws-client copied to clipboard

legacy gql (graphql-ws) support, payload options on connection init

Open painedpineapple opened this issue 10 months ago • 2 comments

I'm not sure if you want to support legacy gql (graphql-ws protocol) events , if not I can maintain a fork. We're currently using Hasura, a graphql layer, which only uses the legacy gql protocol so this is a necessity for us.

This PR also includes the option to allow params on the connection_init event. This is necessary when needing to set an authorization header. Example:

#[derive(Serialize)]
struct AuthHeaders {
    #[serde(rename = "Authorization")]
    authorization: String,
}

#[derive(Serialize)]
struct AuthPayload {
    headers: AuthHeaders,
}

    let auth_payload = serde_json::to_value(&AuthPayload {
        headers: AuthHeaders {
            authorization: format!("Bearer {}", token),
        },
    })?;

    let (client, actor) = Client::build(connection, Some(auth_payload)).await?;

This is a breaking change in the sense that anyone using Client::build will now need to pass an optional payload as a second param. I'm fairly new to rust so if there is a more idiomatic way to do this w/out causing a breaking change lmk!

painedpineapple avatar Jan 24 '25 16:01 painedpineapple

Hi @logandeancall - thanks for the contribution.

I'm not sure about support for the legacy protocol. I have previously resisted adding support for it, although if it's all hasura support I could be convinced to add it. Let me have a think.

The change to the build method is definitely not something I want to accept though. The non breaking way to make this change would be to add a payload method to the ClientBuilder (which Client::build returns). Im pretty sure this function already exists though.

If you're able to revert the change to build I can take a look at the rest of the change in isolation when I get a minute

obmarg avatar Jan 24 '25 22:01 obmarg

Thanks @obmarg. I've cleaned up the PR including removing the change to Client::build.

painedpineapple avatar Jan 30 '25 17:01 painedpineapple