Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat(api-graphql): return entire payload in callback #13980

Merged
merged 2 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions packages/api-graphql/__tests__/AWSAppSyncEventProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,40 @@ describe('AppSyncEventProvider', () => {
'Connection failed: Retriable Test',
);
});

test('subscription observer is triggered when a connection is formed and a data message is received after connection ack', async () => {
expect.assertions(1);
const mockNext = jest.fn();

const observer = provider.subscribe({
appSyncGraphqlEndpoint: 'ws://localhost:8080',
});

const event = JSON.stringify({ some: 'data' });

observer.subscribe({
// Succeed only when the first message comes through
next: mockNext,
// Closing a hot connection (for cleanup) makes it blow up the test stack
error: () => {},
});
await fakeWebSocketInterface?.standardConnectionHandshake();
await fakeWebSocketInterface?.startAckMessage({
connectionTimeoutMs: 100,
});
await fakeWebSocketInterface?.sendDataMessage({
id: fakeWebSocketInterface?.webSocket.subscriptionId,
type: MESSAGE_TYPES.DATA,
event,
});

// events callback returns entire message contents
expect(mockNext).toHaveBeenCalledWith({
id: fakeWebSocketInterface?.webSocket.subscriptionId,
type: MESSAGE_TYPES.DATA,
event: JSON.parse(event),
});
});
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export class AWSAppSyncEventProvider extends AWSWebSocketProvider {
if (type === MESSAGE_TYPES.DATA && payload) {
const deserializedEvent = JSON.parse(payload);
if (observer) {
observer.next(deserializedEvent);
observer.next({ id, type, event: deserializedEvent });
} else {
this.logger.debug(`observer not found for id: ${id}`);
}
Expand Down
Loading