From fade1228b5c5a376c166144077763b672e6bbf06 Mon Sep 17 00:00:00 2001 From: Ivan Artemiev <29709626+iartemiev@users.noreply.github.com> Date: Mon, 28 Oct 2024 16:40:25 -0400 Subject: [PATCH] fix(api-graphql): fix events url pattern --- .github/workflows/callable-e2e-tests.yml | 28 +++++++++---------- .github/workflows/push-preid-release.yml | 2 +- .../api-graphql/__tests__/appsyncUrl.test.ts | 14 ++++++++++ packages/api-graphql/__tests__/events.test.ts | 3 +- .../AWSWebSocketProvider/appsyncUrl.ts | 5 ++-- 5 files changed, 34 insertions(+), 18 deletions(-) create mode 100644 packages/api-graphql/__tests__/appsyncUrl.test.ts diff --git a/.github/workflows/callable-e2e-tests.yml b/.github/workflows/callable-e2e-tests.yml index 4ae74a69c88..2ece9fbde47 100644 --- a/.github/workflows/callable-e2e-tests.yml +++ b/.github/workflows/callable-e2e-tests.yml @@ -61,17 +61,17 @@ jobs: # timeout_minutes: ${{ matrix.integ-config.timeout_minutes || 35 }} # retry_count: ${{ matrix.integ-config.retry_count || 3 }} - detox-e2e-test-runner: - name: E2E test runner - needs: e2e-prep - strategy: - matrix: - integ-config: ${{ fromJson(needs.e2e-prep.outputs.detox-integ-config) }} - fail-fast: false - secrets: inherit - uses: ./.github/workflows/callable-e2e-test-detox.yml - with: - test_name: ${{ matrix.integ-config.test_name }} - working_directory: ${{ matrix.integ-config.working_directory }} - timeout_minutes: ${{ matrix.integ-config.timeout_minutes || 45 }} - host_signout_page: ${{ matrix.integ-config.host_signout_page || false }} + # detox-e2e-test-runner: + # name: E2E test runner + # needs: e2e-prep + # strategy: + # matrix: + # integ-config: ${{ fromJson(needs.e2e-prep.outputs.detox-integ-config) }} + # fail-fast: false + # secrets: inherit + # uses: ./.github/workflows/callable-e2e-test-detox.yml + # with: + # test_name: ${{ matrix.integ-config.test_name }} + # working_directory: ${{ matrix.integ-config.working_directory }} + # timeout_minutes: ${{ matrix.integ-config.timeout_minutes || 45 }} + # host_signout_page: ${{ matrix.integ-config.host_signout_page || false }} diff --git a/.github/workflows/push-preid-release.yml b/.github/workflows/push-preid-release.yml index 9837290ed14..e91ee3000ef 100644 --- a/.github/workflows/push-preid-release.yml +++ b/.github/workflows/push-preid-release.yml @@ -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: diff --git a/packages/api-graphql/__tests__/appsyncUrl.test.ts b/packages/api-graphql/__tests__/appsyncUrl.test.ts new file mode 100644 index 00000000000..1f5ffdc25a9 --- /dev/null +++ b/packages/api-graphql/__tests__/appsyncUrl.test.ts @@ -0,0 +1,14 @@ +import { getRealtimeEndpointUrl } from '../src/Providers/AWSWebSocketProvider/appsyncUrl'; + +describe('getRealtimeEndpointUrl', () => { + test('events', () => { + const httpUrl = + 'https://abcdefghijklmnopqrstuvwxyz.appsync-api.us-east-1.amazonaws.com/event'; + + const res = getRealtimeEndpointUrl(httpUrl).toString(); + + expect(res).toEqual( + 'wss://abcdefghijklmnopqrstuvwxyz.appsync-realtime-api.us-east-1.amazonaws.com/event/realtime', + ); + }); +}); diff --git a/packages/api-graphql/__tests__/events.test.ts b/packages/api-graphql/__tests__/events.test.ts index 334d8e49b7c..a1f8054e3dd 100644 --- a/packages/api-graphql/__tests__/events.test.ts +++ b/packages/api-graphql/__tests__/events.test.ts @@ -3,6 +3,7 @@ import { AppSyncEventProvider } from '../src/Providers/AWSAppSyncEventsProvider' import { events } from '../src/'; import { appsyncRequest } from '../src/internals/events/appsyncRequest'; + import { GraphQLAuthMode } from '@aws-amplify/core/internals/utils'; const abortController = new AbortController(); @@ -38,7 +39,7 @@ jest.mock('../src/internals/events/appsyncRequest', () => { * so we're just sanity checking that the expected auth mode is passed to the provider in this test file. */ -describe('Events', () => { +describe('Events client', () => { afterAll(() => { jest.resetAllMocks(); jest.clearAllMocks(); diff --git a/packages/api-graphql/src/Providers/AWSWebSocketProvider/appsyncUrl.ts b/packages/api-graphql/src/Providers/AWSWebSocketProvider/appsyncUrl.ts index 96e17c0fea3..b79c9cca1eb 100644 --- a/packages/api-graphql/src/Providers/AWSWebSocketProvider/appsyncUrl.ts +++ b/packages/api-graphql/src/Providers/AWSWebSocketProvider/appsyncUrl.ts @@ -13,7 +13,7 @@ const protocol = 'wss://'; const standardDomainPattern = /^https:\/\/\w{26}\.appsync-api\.\w{2}(?:(?:-\w{2,})+)-\d\.amazonaws.com(?:\.cn)?\/graphql$/i; const eventDomainPattern = - /^https:\/\/\w{26}\.ddpg-api\.\w{2}(?:(?:-\w{2,})+)-\d\.amazonaws.com(?:\.cn)?\/event$/i; + /^https:\/\/\w{26}\.\w+-api\.\w{2}(?:(?:-\w{2,})+)-\d\.amazonaws.com(?:\.cn)?\/event$/i; const customDomainPath = '/realtime'; export const isCustomDomain = (url: string): boolean => { @@ -31,7 +31,8 @@ export const getRealtimeEndpointUrl = ( if (isEventDomain(realtimeEndpoint)) { realtimeEndpoint = realtimeEndpoint .concat(customDomainPath) - .replace('ddpg-api', 'grt-gamma'); + .replace('ddpg-api', 'grt-gamma') + .replace('appsync-api', 'appsync-realtime-api'); } else if (isCustomDomain(realtimeEndpoint)) { realtimeEndpoint = realtimeEndpoint.concat(customDomainPath); } else {