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

subscription: remove payload on websocket's Ping #4853

Merged
merged 2 commits into from Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changesets/fix_i1g_subscription_websocket_fix_ping.md
@@ -0,0 +1,6 @@
### Remove invalid payload on graphql-ws Ping message ([Issue #4852](https://github.com/apollographql/router/issues/4852))

According to [graphql-ws spec](https://github.com/enisdenjo/graphql-ws/blob/master/PROTOCOL.md#ping) `Ping` payload should be an object or null but router was sending a string.
To ensure better compatibility Ping's payload was removed.

By [@IvanGoncharov](https://github.com/IvanGoncharov) in https://github.com/apollographql/router/pull/4852
10 changes: 2 additions & 8 deletions apollo-router/src/protocols/websocket.rs
Expand Up @@ -416,13 +416,7 @@ where
tokio::time::interval_at(tokio::time::Instant::now() + duration, duration);
interval.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Skip);
let mut heartbeat_stream = IntervalStream::new(interval)
.map(|_| {
Ok(ClientMessage::Ping {
payload: Some(serde_json_bytes::Value::String(
"APOLLO_ROUTER_HEARTBEAT".into(),
)),
})
})
.map(|_| Ok(ClientMessage::Ping { payload: None }))
.take_until(close_sentinel);
if let Err(err) = sink.send_all(&mut heartbeat_stream).await {
tracing::trace!("cannot send heartbeat: {err:?}");
Expand Down Expand Up @@ -755,7 +749,7 @@ mod tests {
tokio::time::sleep(duration).await;
let ping_message = socket.next().await.unwrap().unwrap();
assert_eq!(ping_message, AxumWsMessage::Text(
serde_json::to_string(&ClientMessage::Ping { payload: Some(serde_json_bytes::Value::String("APOLLO_ROUTER_HEARTBEAT".into())) }).unwrap(),
serde_json::to_string(&ClientMessage::Ping { payload: None }).unwrap(),
));

assert!(
Expand Down