From 55f8fbdf4d5eff534cc27632c339f431b9bc2140 Mon Sep 17 00:00:00 2001 From: Ivan Goncharov Date: Wed, 27 Mar 2024 01:51:44 +0200 Subject: [PATCH] subscription: remove payload on websocket's Ping (#4853) Removes invalid payload on graphql-ws Ping message Fixes #4852 --- **Checklist** Complete the checklist (and note appropriate exceptions) before the PR is marked ready-for-review. - [x] Changes are compatible[^1] - [x] Documentation[^2] completed - [x] Performance impact assessed and acceptable - Tests added and passing[^3] - [x] Unit Tests - [ ] Integration Tests - [ ] Manual Tests **Exceptions** *Note any exceptions here* **Notes** [^1]: It may be appropriate to bring upcoming changes to the attention of other (impacted) groups. Please endeavour to do this before seeking PR approval. The mechanism for doing this will vary considerably, so use your judgement as to how and when to do this. [^2]: Configuration is an important part of many changes. Where applicable please try to document configuration examples. [^3]: Tick whichever testing boxes are applicable. If you are adding Manual Tests, please document the manual testing (extensively) in the Exceptions. --- .changesets/fix_i1g_subscription_websocket_fix_ping.md | 6 ++++++ apollo-router/src/protocols/websocket.rs | 10 ++-------- 2 files changed, 8 insertions(+), 8 deletions(-) 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 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!(