Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let subscribe() add my own id #120

Open
emilm opened this issue Sep 12, 2024 · 4 comments
Open

Let subscribe() add my own id #120

emilm opened this issue Sep 12, 2024 · 4 comments

Comments

@emilm
Copy link

emilm commented Sep 12, 2024

I am not sure if this should be valid but to keep track of the graphql subscriptions on the server one expects a unique ID.
This code to send your own string is out of reach:

let id = self.next_id.fetch_add(1, Ordering::Relaxed);
let message = protocol::Message::Subscribe {
    id: id.to_string(),
    payload: &op,
};

Should it be made possible to provide your own or should the server not rely on it?

@obmarg
Copy link
Owner

obmarg commented Sep 12, 2024

Just curious: what's the use case for setting your own id?

Either way: I'm not against exposing that functionality if we can find a nice way to integrate it into the API.

@emilm
Copy link
Author

emilm commented Sep 12, 2024

Thanks!

The idea is to have an unique identifier per subscription client so you can distinguish them on the server when tracking / holding a list of active connections, so you can add / remove them based on that ID in the dictionary.
Some graphql clients just send 0 others send a GUID.

Otherwise you need to assign them on the server which seems difficult with the current server side APIs.

@obmarg
Copy link
Owner

obmarg commented Sep 12, 2024

The idea is to have an unique identifier per subscription client so you can distinguish them on the server when tracking / holding a list of active connections, so you can add / remove them based on that ID in the dictionary.

Do you want a unique identifier per subscription or per client? Guessing per subscription, but if it was per client then setting the connection payload with this function might be a better fit.

@emilm
Copy link
Author

emilm commented Sep 12, 2024

Thank you!

#[derive(Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
struct CustomPayload {
    id: String
}

Then

let (client, actor) = Client::build(con).payload(
    CustomPayload { id: "123".to_string() }).unwrap()
    .await.unwrap();

Still shows up as session id "0" on the server.

Maybe I am doing this wrong. Forgive me. My rust knowledge isn't that good yet.

I guess the subscription level code doesn't get my id. I would assume it's per subscription this id comes into play. So I am not sure if this is carried on from the client to the sub. It needs to be the standard id property that is sent like in the first post.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants