Skip to content

Commit

Permalink
update ws protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
iartemiev committed Oct 18, 2024
1 parent f975992 commit 538dd9f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/push-preid-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
push:
branches:
# Change this to your branch name where "example-preid" corresponds to the preid you want your changes released on
- feat/example-preid-branch/main
- feat/events/main

jobs:
e2e:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,15 @@ interface DataResponse {
}

const PROVIDER_NAME = 'AWSAppSyncEventsProvider';
const WS_PROTOCOL_NAME = 'aws-appsync-event-ws';

class AWSAppSyncEventProvider extends AWSWebSocketProvider {
constructor() {
super(PROVIDER_NAME);
super({ providerName: PROVIDER_NAME, wsProtocolName: WS_PROTOCOL_NAME });
}

getProviderName() {
return PROVIDER_NAME;
}

public async connect(options: AWSAppSyncEventProviderOptions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,15 @@ interface DataPayload {
}

const PROVIDER_NAME = 'AWSAppSyncRealTimeProvider';
const WS_PROTOCOL_NAME = 'graphql-ws';

// get rid of generic. Just map the options from Gogi-specific to general
export class AWSAppSyncRealTimeProvider extends AWSWebSocketProvider {
constructor() {
super(PROVIDER_NAME);
super({ providerName: PROVIDER_NAME, wsProtocolName: WS_PROTOCOL_NAME });
}

getProviderName() {
return PROVIDER_NAME;
}

public subscribe(
Expand All @@ -55,10 +59,6 @@ export class AWSAppSyncRealTimeProvider extends AWSWebSocketProvider {
return super.subscribe(options, customUserAgentDetails);
}

getProviderName() {
return PROVIDER_NAME;
}

protected async _prepareSubscriptionPayload({
options,
subscriptionId,
Expand Down
13 changes: 10 additions & 3 deletions packages/api-graphql/src/Providers/AWSWebSocketProvider/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ interface ParsedMessagePayload {
};
}

interface AWSWebSocketProviderArgs {
providerName: string;
wsProtocolName: string;
}

export abstract class AWSWebSocketProvider {
protected logger: ConsoleLogger;
protected subscriptionObserverMap = new Map<string, ObserverQuery>();
Expand All @@ -84,9 +89,11 @@ export abstract class AWSWebSocketProvider {
private readonly connectionStateMonitor = new ConnectionStateMonitor();
private readonly reconnectionMonitor = new ReconnectionMonitor();
private connectionStateMonitorSubscription: SubscriptionLike;
private readonly wsProtocolName: string;

constructor(providerName: string) {
this.logger = new ConsoleLogger(providerName);
constructor(args: AWSWebSocketProviderArgs) {
this.logger = new ConsoleLogger(args.providerName);
this.wsProtocolName = args.wsProtocolName;

this.connectionStateMonitorSubscription =
this._startConnectionStateMonitoring();
Expand Down Expand Up @@ -774,7 +781,7 @@ export abstract class AWSWebSocketProvider {
private async _openConnection(awsRealTimeUrl: string, subprotocol: string) {
return new Promise<void>((resolve, reject) => {
const newSocket = this._getNewWebSocket(awsRealTimeUrl, [
'graphql-ws',
this.wsProtocolName,
subprotocol,
]);

Expand Down

0 comments on commit 538dd9f

Please sign in to comment.