feat: prototype Variation E realtime client (standalone RealtimeClient + React hooks)#1097
Closed
pyramation wants to merge 2 commits intomainfrom
Closed
feat: prototype Variation E realtime client (standalone RealtimeClient + React hooks)#1097pyramation wants to merge 2 commits intomainfrom
pyramation wants to merge 2 commits intomainfrom
Conversation
…t + React hooks) Two-layer architecture for frontend realtime subscriptions: Layer 1: @constructive-io/realtime (packages/realtime) - Framework-agnostic RealtimeClient managing graphql-ws WebSocket connection - Multiplexes subscriptions over single connection - Connection state management with listeners - createSubscriptionModel() factory for codegen - buildSubscriptionDocument/Variables helpers - 19 unit tests passing Layer 2: @constructive-io/react-realtime (packages/react-realtime) - RealtimeProvider context for React tree - useSubscription() hook with React Query cache bridge - useConnectionState() hook for connection monitoring - createSubscriptionHook() factory for codegen (generates per-table hooks) - CacheBridge: auto-invalidate list queries, optimistic detail updates - 3 unit tests passing Tree-shakeable: each layer imports independently. Escape hatch: use RealtimeClient directly without React hooks.
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
4 tasks
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
Prototype of "Variation E" (Hybrid) frontend realtime subscription architecture — two new packages that provide a framework-agnostic subscription client and a React hooks layer with React Query cache bridge.
This sits on top of the database-layer realtime infrastructure built in constructive-db PRs #1073–#1086 (partition support,
realtime_module,DataRealtimegenerator, subscriber tables with RLS). The backend is transport-agnostic; this PR demonstrates one possible frontend binding.@constructive-io/realtime(packages/realtime) — framework-agnostic:RealtimeClientwrappinggraphql-ws, multiplexing subscriptions over a single WebSocketcreateSubscriptionModel()factory for codegen to produce per-table typed.subscribe()methodsbuildSubscriptionDocument()/buildSubscriptionVariables()helpers for codegen templates@constructive-io/react-realtime(packages/react-realtime) — React + React Query:RealtimeProvider/useRealtimeClient()contextuseSubscription()hook with optionalCacheBridgeconfig (auto-invalidate list queries, optimistic detail cache updates on INSERT/UPDATE, cache removal on DELETE)useConnectionState()hook for connection monitoringcreateSubscriptionHook()factory for codegen (generates per-table hooks likeuseContactSubscription())Tree-shakeable: each layer imports independently. Escape hatch: use
RealtimeClientdirectly without React hooks.Review & Testing Checklist for Human
createSubscriptionHookandcreateSubscriptionModelfactories define the codegen contract — confirm the API shape is what you'd want generated code to call.use-subscription.tsapplyCacheBridge): This function doessetQueryData,invalidateQueries, andremoveQuerieson React Query cache but has no test coverage. Review the INSERT/UPDATE/DELETE handling for correctness — particularly thegetIdcast throughunknown.useSubscriptionresubscribes whenfilterJson(serialized filter) changes. Verify the cleanup/unsubscribe path is correct and doesn't leak subscriptions on rapid filter changes.client.tslines 98–113): The client extractsoperation,data,previousValues,timestampfrom the GraphQL subscription payload. This assumes a specific payload shape that the Graphile subscription plugin (Phase 3a, not yet built) will need to match.Notes
@testing-library/react. Sufficient for a prototype but would need expansion before shipping.pnpm-lock.yamldiff is large due to formatting changes (pnpm version difference) — the actual new dependency entries are justgraphql-ws,@tanstack/react-query, and the workspace link between the two packages.Link to Devin session: https://app.devin.ai/sessions/19485cf5cc58416a9f86068563d512f5
Requested by: @pyramation