Skip to content

Commit

Permalink
fix(api-graphql): events ws connect sig (aws-amplify#14003)
Browse files Browse the repository at this point in the history
  • Loading branch information
iartemiev authored Nov 12, 2024
1 parent 0f50917 commit 4606279
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,15 @@ interface DataResponse {

const PROVIDER_NAME = 'AWSAppSyncEventsProvider';
const WS_PROTOCOL_NAME = 'aws-appsync-event-ws';
const CONNECT_URI = ''; // events does not expect a connect uri

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

getProviderName() {
Expand Down Expand Up @@ -90,7 +95,6 @@ export class AWSAppSyncEventProvider extends AWSWebSocketProvider {
appSyncGraphqlEndpoint,
authenticationType,
query,
variables,
apiKey,
region,
} = options;
Expand All @@ -100,7 +104,7 @@ export class AWSAppSyncEventProvider extends AWSWebSocketProvider {
// events: [variables],
// };

const serializedData = JSON.stringify([variables]);
const serializedData = JSON.stringify({ channel: query });

const headers = {
...(await awsRealTimeHeaderBasedAuth({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,15 @@ interface DataPayload {

const PROVIDER_NAME = 'AWSAppSyncRealTimeProvider';
const WS_PROTOCOL_NAME = 'graphql-ws';
const CONNECT_URI = '/connect';

export class AWSAppSyncRealTimeProvider extends AWSWebSocketProvider {
constructor() {
super({ providerName: PROVIDER_NAME, wsProtocolName: WS_PROTOCOL_NAME });
super({
providerName: PROVIDER_NAME,
wsProtocolName: WS_PROTOCOL_NAME,
connectUri: CONNECT_URI,
});
}

getProviderName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ interface ParsedMessagePayload {
interface AWSWebSocketProviderArgs {
providerName: string;
wsProtocolName: string;
connectUri: string;
}

export abstract class AWSWebSocketProvider {
Expand All @@ -91,10 +92,12 @@ export abstract class AWSWebSocketProvider {
private readonly reconnectionMonitor = new ReconnectionMonitor();
private connectionStateMonitorSubscription: SubscriptionLike;
private readonly wsProtocolName: string;
private readonly wsConnectUri: string;

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

this.connectionStateMonitorSubscription =
this._startConnectionStateMonitoring();
Expand Down Expand Up @@ -739,7 +742,7 @@ export abstract class AWSWebSocketProvider {
const authHeader = await awsRealTimeHeaderBasedAuth({
authenticationType,
payload: payloadString,
canonicalUri: '/connect',
canonicalUri: this.wsConnectUri,
apiKey,
appSyncGraphqlEndpoint,
region,
Expand Down

0 comments on commit 4606279

Please sign in to comment.