feat: GraphQL subscriptions via Strawberry + Channels (#764)#816
Open
Jessepriase wants to merge 1 commit into
Open
feat: GraphQL subscriptions via Strawberry + Channels (#764)#816Jessepriase wants to merge 1 commit into
Jessepriase wants to merge 1 commit into
Conversation
Implementation was already in place across schema.py, asgi.py and
subscription_middleware.py. This commit completes the issue by:
requirements.txt:
- Upgrade strawberry-graphql to strawberry-graphql[channels]==0.289.0
to formally declare the channels extras dependency (channels, daphne,
channels_redis were already present individually)
test_graphql_subscriptions.py — integration tests covering all
acceptance criteria without requiring a live WebSocket stack:
Schema shape
- Subscription type exists and is named 'Subscription'
- contractEvents field is present with contractId argument
- Existing notifications field is still present
Resolver type safety
- contract_events is an AsyncGenerator (async def ... yield)
- notifications is also an AsyncGenerator
Channel lifecycle
- group_add called with 'events_{contract_id}' group name on subscribe
- group_discard called in finally block when generator is closed
- group_discard called even when channel layer raises mid-loop
- No channel layer configured: resolver exits gracefully without error
End-to-end event flow
- Message published to channel group causes resolver to yield ContractEvent
- ContractEvent.DoesNotExist is swallowed; generator continues
HTTP query regression
- contracts, events, and introspection queries all still work
Rate limiting (SubscriptionRateLimitMiddleware)
- Allows up to 5 concurrent connections per IP
- Rejects 6th connection with close code 4429
- Allows connections below the limit
- Decrements counter on close
- IP extraction: X-Forwarded-For takes precedence over client address
- Non-WebSocket scopes bypass middleware unchanged
ASGI routing
- GraphQLWSConsumer importable from strawberry.channels
- application is a ProtocolTypeRouter
- Schema object exposes a subscription type
|
@Jessepriase Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Collaborator
|
@Jessepriase CI checks are failing, kindly resolve |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implementation was already in place across schema.py, asgi.py and subscription_middleware.py. This commit completes the issue by:
requirements.txt:
test_graphql_subscriptions.py — integration tests covering all acceptance criteria without requiring a live WebSocket stack:
Schema shape
Resolver type safety
Channel lifecycle
End-to-end event flow
HTTP query regression
Rate limiting (SubscriptionRateLimitMiddleware)
ASGI routing
closes GraphQL Subscriptions via Strawberry + Channels #764