feat(graphql): add WebSocket subscription support for real-time data (Fixes #242) - #260
Merged
elizabetheonoja-art merged 2 commits intoAug 24, 2026
Conversation
…ixes Utility-Protocol#242) Implements async-graphql based GraphQL subscriptions with pubsub event bus enabling clients to receive real-time meter readings and billing events without polling. Adds schema with query, mutation, and subscription roots, in-process PubSub using tokio broadcast channels, subscription filtering by deviceId and serviceType, and axum route wiring. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
- Add missing serde imports to graphql/types.rs - Replace custom poll_recv stream impl with tokio_stream::BroadcastStream - Remove Arc wrapping of Schema (incompatible with Executor trait) - Clean up duplicate imports in graphql/mod.rs 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
elizabetheonoja-art
merged commit Aug 24, 2026
6bce1f3
into
Utility-Protocol:main
2 of 7 checks passed
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.
Summary
Adds async-graphql based subscription support enabling clients to receive real-time meter readings and billing events over WebSocket without polling.
Changes
New Modules
src/graphql/pubsub.rs— In-process PubSub event bus usingtokio::sync::broadcastfor per-topic event delivery, subscriber count tracking, and lazy GC of dead channels.src/graphql/types.rs— GraphQL types withasync-graphqlderives:MeterReading— readingId, deviceId, serviceType, value, unit, timestampBillingEvent— eventId, deviceId, serviceType, amount, currency, status, timestamp, descriptionMeterReadingFilter/BillingEventFilter— optional deviceId and serviceType filter inputssrc/graphql/mod.rs— Schema with:apiVersion,health,activeSubscriptionspublishMeterReading,publishBillingEventfor pushing events into the subscription busmeterReadings(filter)andbillingEvents(filter)with in-stream filtering via customStreamimpls wrapping broadcast receiversbuild_schema(pubsub)that injects the shared PubSub into GraphQL contextRouter Changes (
src/api/router.rs)GET/POST /api/graphqlGET /api/graphql/wsusingasync-graphql-axum::GraphQLSubscriptionDependencies
async-graphql = "7"— GraphQL server frameworkasync-graphql-axum = "7"— Axum integration with WebSocket subscription transportTests
tests/graphql_subscription_tests.rs— 17 integration tests:src/graphql/pubsub.rs— 4 unit tests (publish/subscribe, topic isolation, subscriber count tracking, GC)How to Test
Architecture
Events flow: Mutations publish JSON payloads to the PubSub, which fans them out to all active subscription streams. Each subscription stream applies optional deviceId/serviceType filters before yielding to the WebSocket client.
Closes #242