-
-
Notifications
You must be signed in to change notification settings - Fork 535
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
Fix graphql ws did not ignore parsing errors #3670
Fix graphql ws did not ignore parsing errors #3670
Conversation
Reviewer's Guide by SourceryThis pull request fixes a regression in the legacy GraphQL over WebSocket protocol implementation. The main change is to restore the behavior of ignoring client message parsing errors in the legacy protocol, which was accidentally changed in a recent refactor. The PR updates the WebSocket adapters, handlers, and related tests to properly handle and ignore parsing errors when required. Sequence diagram for WebSocket message handling with parsing errorssequenceDiagram
participant Client
participant Server
Client->>Server: Send text message
alt Valid JSON
Server->>Server: Process message
else Invalid JSON
Server->>Server: Ignore message
end
Client->>Server: Send non-text message
Server->>Client: Close connection with error "WebSocket message type must be text"
Updated class diagram for WebSocket adaptersclassDiagram
class AsyncWebSocketAdapter {
+iter_json(ignore_parsing_errors: bool) AsyncGenerator
+send_json(message: Mapping)
}
class LitestarWebSocketAdapter {
+iter_json(ignore_parsing_errors: bool) AsyncGenerator
}
class ASGIWebSocketAdapter {
+iter_json(ignore_parsing_errors: bool) AsyncGenerator
}
class ChannelsWebSocketAdapter {
+iter_json(ignore_parsing_errors: bool) AsyncGenerator
}
class AiohttpWebSocketAdapter {
+iter_json(ignore_parsing_errors: bool) AsyncGenerator
}
AsyncWebSocketAdapter <|-- LitestarWebSocketAdapter
AsyncWebSocketAdapter <|-- ASGIWebSocketAdapter
AsyncWebSocketAdapter <|-- ChannelsWebSocketAdapter
AsyncWebSocketAdapter <|-- AiohttpWebSocketAdapter
note for AsyncWebSocketAdapter "Added ignore_parsing_errors parameter to iter_json method"
Updated class diagram for WebSocket exceptionsclassDiagram
class NonTextMessageReceived {
}
class NonJsonMessageReceived {
}
class HTTPException {
-status_code: int
-reason: str
}
HTTPException <|-- NonTextMessageReceived
HTTPException <|-- NonJsonMessageReceived
note for NonTextMessageReceived "New exception for non-text messages"
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
8d712d8
to
0ad7d1d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @DoctorJohn - I've reviewed your changes and they look great!
Here's what I looked at during the review
- 🟢 General issues: all looks good
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Thanks for adding the Here's a preview of the changelog: This release fixes a regression in the legacy GraphQL over WebSocket protocol. Here's the tweet text:
|
CodSpeed Performance ReportMerging #3670 will not alter performanceComparing Summary
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3670 +/- ##
==========================================
+ Coverage 96.67% 97.02% +0.35%
==========================================
Files 503 503
Lines 33457 33520 +63
Branches 5602 5632 +30
==========================================
+ Hits 32344 32524 +180
+ Misses 880 790 -90
+ Partials 233 206 -27 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some nits, but LGTM :)
raise NonTextMessageReceived() | ||
|
||
try: | ||
yield json.loads(text) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not related to this PR (so nothing to change here), but this got me thinking if we should allow for different json libs to be used in places like this, like orjson
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very good point, I'll create a PR for it!
Description
The legacy WS protocol dictates that servers should ignore text messages sent by clients that are not valid JSON. Here's the relevant section from the legacy protocol specification:
I accidentally changed this behavior in a recent refactor to match the newer protocol, which requires servers to close the WebSocket in this case.
This PR restores the intended behavior and updates the relevant tests.
Types of Changes
Summary by Sourcery
Fix the handling of non-JSON messages in the legacy GraphQL WebSocket protocol to ignore parsing errors instead of closing the connection, and update tests to reflect this behavior.
Bug Fixes:
Documentation:
Tests: