From 5195d67f9395f388f17a31a09bdd260327f53389 Mon Sep 17 00:00:00 2001 From: Ivan Goncharov Date: Tue, 26 Mar 2024 19:10:56 +0200 Subject: [PATCH 1/2] subscription: remove payload on websocket's Ping --- apollo-router/src/protocols/websocket.rs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/apollo-router/src/protocols/websocket.rs b/apollo-router/src/protocols/websocket.rs index 4e68e3bd6d..621b37a853 100644 --- a/apollo-router/src/protocols/websocket.rs +++ b/apollo-router/src/protocols/websocket.rs @@ -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:?}"); @@ -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!( From ea1f3dece7bb0ba0674b73174cf3dbebf45acfd8 Mon Sep 17 00:00:00 2001 From: Ivan Goncharov Date: Tue, 26 Mar 2024 19:22:21 +0200 Subject: [PATCH 2/2] add changeset --- .changesets/fix_i1g_subscription_websocket_fix_ping.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changesets/fix_i1g_subscription_websocket_fix_ping.md diff --git a/.changesets/fix_i1g_subscription_websocket_fix_ping.md b/.changesets/fix_i1g_subscription_websocket_fix_ping.md new file mode 100644 index 0000000000..1c3cb05e29 --- /dev/null +++ b/.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 \ No newline at end of file