-
Notifications
You must be signed in to change notification settings - Fork 0
Implement GraphQL Banking POC with SSE Subscriptions, Persistent Header, Modal Transfer, Faker Data, and Real-time Balance Chart #4
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: jedateach <1356335+jedateach@users.noreply.github.com>
Co-authored-by: jedateach <1356335+jedateach@users.noreply.github.com>
Co-authored-by: jedateach <1356335+jedateach@users.noreply.github.com>
@copilot I notice the parties fail to load when I load up the app. I'm not seeing any live updating by I would also like to suggest employing GraphQL SSE as a means of providing graphql sse based connectivity via urql This article, scraped from https://alexocallaghan.com/mock-sse-with-msw suggests how you can mock sse via msw: Mock server-sent events (SSE) with msw Generative AI solutions like ChatGPT make use of server-sent events to stream the large language model response to the client as it's generated. With the popularity of generative AI applications, figuring out how to work with these streamed responses is one challenge to overcome with some differences to a typical REST API. Mock Service Worker is a popular tool for writing JavaScript API mocks that can be re-used across different frameworks, tools and environments. At Mintel we use msw to write mocks to use in our Storybook, unit tests and other development environments. msw does support mocking SSE events, while websocket support is in beta. For example, given some frontend code that opens a server-sent events connection: const source = new EventSource("http://example.com/stream"); source.onmessage = (event) => { import { http, HttpResponse } from "msw"; const encoder = new TextEncoder(); const handler = http.get('http://example.com/stream', () => { return new HttpResponse(stream, { You can also read more about streaming with msw with examples of how you can pipe your response through a latency stream to replicate a delayed response. If you're hitting some limitations of the EventSource API, such as not being able to provide custom request headers for authentication you can also check out fetch-event-source as this mocking approach will work with both. |
Co-authored-by: jedateach <1356335+jedateach@users.noreply.github.com>
Fixed the MSW race condition and implemented live balance/transaction updates! The issues have been resolved: Race Condition Fix (commit 1dd88c5):
Live Updates Implementation:
The application now demonstrates:
For future SSE implementation with GraphQL subscriptions, the foundation is in place with the SSE endpoint and URQL integration ready for proper subscription transport. |
a |
@copilot Here is how you can write a msw handler that provides SSE: For example, given some frontend code that opens a server-sent events connection: const source = new EventSource("http://example.com/stream");
source.onmessage = (event) => {
console.log(Message: ${event.data});
};
You can write an msw mock handler:
import { http, HttpResponse } from "msw";
const encoder = new TextEncoder();
const handler = http.get('http://example.com/stream', () => {
const stream = new ReadableStream({
start(controller) {
controller.enqueue(
encoder(
event:some-event\ndata:some data\n\n
)
);
controller.close();
},
});
return new HttpResponse(stream, {
headers: {
"Content-Type": "text/event-stream",
}.
});
}); And the graphql-sse package supports integration with urql, as shows: import { createClient, defaultExchanges, subscriptionExchange } from 'urql';
import { createClient as createSSEClient } from 'graphql-sse';
const sseClient = createSSEClient({
url: 'http://its.urql:4000/graphql/stream',
});
export const client = createClient({
url: '/graphql/stream',
exchanges: [
...defaultExchanges,
subscriptionExchange({
forwardSubscription(operation) {
return {
subscribe: (sink) => {
const dispose = sseClient.subscribe(operation, sink);
return {
unsubscribe: dispose,
};
},
};
},
}),
],
}); Make sure you are using the Subscriptions as defined in use GraphQL SSE |
- Install graphql-sse package for SSE client functionality - Create SSE subscription exchange for URQL integration - Update URQL provider to use SSE subscription exchange - Replace timer-based LiveBalance component with GraphQL subscription - Replace timer-based LiveTransactions component with GraphQL subscription - Update MSW handlers to properly support SSE endpoints - Add proper error handling and visual indicators for SSE status Co-authored-by: jedateach <1356335+jedateach@users.noreply.github.com>
... Implemented SSE-based GraphQL subscriptions as requested! The changes include: SSE Integration (commit 9a87b70):
Real-time Features:
The implementation follows your provided example exactly - using |
@copilot thanks I would expect that the Transfer and Payment mutations would also update this data. |
- Install @mswjs/data package for database-like mock data - Replace hard-coded fixtures with MSW data models - Create database schema matching GraphQL types (User, Party, Account, Transaction) - Update all handlers to use MSW data instead of static fixtures - Remove old fixture files (mockUser.ts, generateMockTransactions.ts, accountBalances.ts) - Ensure Transfer and Payment mutations update database state - Initialize database with seed data when MSW starts - Fix SSE subscriptions to use real-time database updates Co-authored-by: jedateach <1356335+jedateach@users.noreply.github.com>
Implemented MSW Data for realistic database-like behavior! The changes include: MSW Data Integration (commit 47a7486):
Database-like Features:
The mock data now behaves like a real database with proper CRUD operations, relationships, and state persistence during the session. Mutations actually modify the underlying data, making the banking app demo much more realistic. |
@copilot Secondly, make the transfer experience instead a modal. Finally, use faker for mocking who the transaction was with. |
…action data Co-authored-by: jedateach <1356335+jedateach@users.noreply.github.com>
Co-authored-by: jedateach <1356335+jedateach@users.noreply.github.com>
... Implemented all requested features! The changes include: ✅ Persistent Header: Banking Dashboard title, Transfer Money, Send Payment buttons, and user selection dropdown now stay fixed at the top of all pages with a modern backdrop blur effect. ✅ Transfer Modal: Transfer experience is now a modal overlay instead of a separate page. Opens with proper accessibility features using Radix UI Dialog. ✅ Faker Integration: Transaction descriptions now use All features are working seamlessly with the existing SSE subscriptions and MSW database. The header persists across all pages while live balance updates continue in real-time. Commit: 4e71c7b |
@copilot introduce on the account details page, a time-series graph showing the current balance of the account. it should also update in realtime. |
Co-authored-by: jedateach <1356335+jedateach@users.noreply.github.com>
Implemented real-time balance chart on account details page! The chart uses recharts library and integrates with the existing SSE subscription system to show live balance updates. Features added:
The chart is fully integrated with the existing Commit: a9c8071 |
@copilot Use this kind of formatting to get it to move along: <XAxis
dataKey="timestamp"
type="number"
scale="time"
domain={['dataMin', 'dataMax']}
tickFormatter={(unixTime) => formatTime(new Date(unixTime))}
/> use recharts |
Fixed the balance chart to use time-based distribution from the actual SSE timestamps! The chart now:
The chart now reflects the bursty nature of the SSE updates (200ms-2s intervals) rather than even spacing. Commit: 5f5d9b0 |
5f5d9b0
to
251bc5f
Compare
Issues Resolved
MSW Race Condition Fixed:
Providers
componentnpx msw init
SSE-based Real-time Updates Implemented:
graphql-sse
package for client-side SSE supportLiveBalance
component to useSubscribeToAccountBalance
GraphQL subscriptionLiveTransactions
component to useSubscribeToTransactions
GraphQL subscription/api/graphql-sse
Database-like MSW Data Implementation:
@mswjs/data
for realistic database-like mock behaviormockUser.ts
,generateMockTransactions.ts
,accountBalances.ts
User Experience Improvements:
NEW - Persistent Header & Modal Transfer Experience:
@faker-js/faker
for realistic transaction descriptions with dynamic person names and company names/transfer
routeNEW - Real-time Balance Chart with Time-based Distribution:
recharts
library and createdBalanceChart
component for visual balance trackingSubscribeToAccountBalance
GraphQL subscription asLiveBalance
Demo Features Working
Technical Implementation
MSW Data Integration
SSE Subscription Exchange
graphql-sse
clientGraphQL Subscriptions
SubscribeToAccountBalance($accountId)
- Real-time balance updatesSubscribeToTransactions($accountId)
- Real-time transaction streamsubscriptions.graphql
as per schemaMSW SSE Mock Handlers
/api/graphql-sse
endpoint supports GraphQL subscription queriesdata:
and newlinesPersistent Header & Modal Implementation
position: sticky
with backdrop blur for modern feelonSuccess
callback for modal closureReal-time Balance Chart Implementation with Time-based Distribution
SubscribeToAccountBalance
GraphQL subscriptiontype="number"
andscale="time"
for proper time distribution✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.