Skip to content

Commit

Permalink
subscription: remove payload on websocket's Ping (#4853)
Browse files Browse the repository at this point in the history
Removes invalid payload on graphql-ws Ping message

Fixes #4852

<!-- start metadata -->
---

**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.
  • Loading branch information
IvanGoncharov committed Mar 26, 2024
1 parent 615b74d commit 55f8fbd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
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

0 comments on commit 55f8fbd

Please sign in to comment.