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 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!(