Skip to content
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

feat(api): add custom endpoint support to API #14086

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
revert superfluous test changes to api-graphql
Jon Wire committed Dec 18, 2024
commit ba4c61dd1dd3014c8f3dfc1ebfc66bcf8170eaa9
Original file line number Diff line number Diff line change
@@ -36,7 +36,10 @@ describe('server generateClient', () => {
test('subscriptions are disabled', () => {
const getAmplify = async (fn: any) => await fn(Amplify);

const client = generateClientWithAmplifyInstance<Schema>({
const client = generateClientWithAmplifyInstance<
Schema,
V6ClientSSRCookies<Schema>
>({
amplify: getAmplify,
config: config,
});
@@ -68,7 +71,10 @@ describe('server generateClient', () => {

const getAmplify = async (fn: any) => await fn(Amplify);

const client = generateClientWithAmplifyInstance<Schema>({
const client = generateClientWithAmplifyInstance<
Schema,
V6ClientSSRCookies<Schema>
>({
amplify: getAmplify,
config: config,
});
@@ -112,7 +118,10 @@ describe('server generateClient', () => {

const getAmplify = async (fn: any) => await fn(Amplify);

const client = generateClientWithAmplifyInstance<Schema>({
const client = generateClientWithAmplifyInstance<
Schema,
V6ClientSSRCookies<Schema>
>({
amplify: getAmplify,
config: config,
});
@@ -158,7 +167,10 @@ describe('server generateClient', () => {

const getAmplify = async (fn: any) => await fn(Amplify);

const client = generateClientWithAmplifyInstance<Schema>({
const client = generateClientWithAmplifyInstance<
Schema,
V6ClientSSRCookies<Schema>
>({
amplify: getAmplify,
config: config,
});
@@ -185,7 +197,10 @@ describe('server generateClient', () => {

describe('with request', () => {
test('subscriptions are disabled', () => {
const client = generateClientWithAmplifyInstance<Schema>({
const client = generateClientWithAmplifyInstance<
Schema,
V6ClientSSRRequest<Schema>
>({
amplify: null,
config: config,
});
@@ -200,7 +215,10 @@ describe('server generateClient', () => {
Amplify.configure(configFixture as any);
const config = Amplify.getConfig();

const client = generateClientWithAmplifyInstance<Schema>({
const client = generateClientWithAmplifyInstance<
Schema,
V6ClientSSRRequest<Schema>
>({
amplify: null,
config: config,
});
72 changes: 14 additions & 58 deletions packages/api-graphql/__tests__/utils/expects.ts
Original file line number Diff line number Diff line change
@@ -2,18 +2,6 @@ import { parse, print, DocumentNode } from 'graphql';
import { CustomHeaders } from '@aws-amplify/data-schema-types';
import { Amplify } from 'aws-amplify';

type SpecialRequestVariations = {
/**
* A string or jest matcher.
*/
endpoint?: any;

/**
* Object or jest matcher.
*/
headers?: any;
};

/**
* Performs an `expect()` on a jest spy with some basic nested argument checks
* based on the given mutation `opName` and `item`.
@@ -26,16 +14,12 @@ export function expectMutation(
spy: jest.SpyInstance<any, any>,
opName: string,
item: Record<string, any>,
{
endpoint = 'https://localhost/graphql',
headers = expect.objectContaining({ 'X-Api-Key': 'FAKE-KEY' }),
}: SpecialRequestVariations = {},
) {
expect(spy).toHaveBeenCalledWith({
abortController: expect.any(AbortController),
url: new URL(endpoint),
url: new URL('https://localhost/graphql'),
options: expect.objectContaining({
headers,
headers: expect.objectContaining({ 'X-Api-Key': 'FAKE-KEY' }),
body: expect.objectContaining({
query: expect.stringContaining(
`${opName}(input: $input, condition: $condition)`,
@@ -60,10 +44,6 @@ export function expectGet(
spy: jest.SpyInstance<any, any>,
opName: string,
item: Record<string, any>,
{
endpoint = 'https://localhost/graphql',
headers = expect.objectContaining({ 'X-Api-Key': 'FAKE-KEY' }),
}: SpecialRequestVariations = {},
) {
expect(spy).toHaveBeenCalledWith(
expect.objectContaining({
@@ -73,9 +53,9 @@ export function expectGet(
}),
{
abortController: expect.any(AbortController),
url: new URL(endpoint),
url: new URL('https://localhost/graphql'),
options: expect.objectContaining({
headers,
headers: expect.objectContaining({ 'X-Api-Key': 'FAKE-KEY' }),
body: expect.objectContaining({
query: expect.stringContaining(`${opName}(id: $id)`),
variables: expect.objectContaining(item),
@@ -97,16 +77,12 @@ export function expectList(
spy: jest.SpyInstance<any, any>,
opName: string,
item: Record<string, any>,
{
endpoint = 'https://localhost/graphql',
headers = expect.objectContaining({ 'X-Api-Key': 'FAKE-KEY' }),
}: SpecialRequestVariations = {},
) {
expect(spy).toHaveBeenCalledWith({
abortController: expect.any(AbortController),
url: new URL(endpoint),
url: new URL('https://localhost/graphql'),
options: expect.objectContaining({
headers,
headers: expect.objectContaining({ 'X-Api-Key': 'FAKE-KEY' }),
body: expect.objectContaining({
query: expect.stringContaining(
`${opName}(filter: $filter, limit: $limit, nextToken: $nextToken)`,
@@ -129,20 +105,12 @@ export function expectSub(
spy: jest.SpyInstance<any, any>,
opName: string,
item: Record<string, any>,
{
endpoint = 'https://localhost/graphql',
authenticationType = 'apiKey',
apiKey = 'FAKE-KEY',
}: SpecialRequestVariations & {
authenticationType?: string;
apiKey?: string;
} = {},
) {
expect(spy).toHaveBeenCalledWith(
expect.objectContaining({
authenticationType,
apiKey,
appSyncGraphqlEndpoint: endpoint,
authenticationType: 'apiKey',
apiKey: 'FAKE-KEY',
appSyncGraphqlEndpoint: 'https://localhost/graphql',
// Code-gen'd queries have an owner param; TypeBeast queries don't:
query: expect.stringContaining(`${opName}(filter: $filter`),
variables: expect.objectContaining(item),
@@ -168,21 +136,13 @@ export function expectSubWithHeaders(
spy: jest.SpyInstance<any, any>,
opName: string,
item: Record<string, any>,
{
endpoint = 'https://localhost/graphql',
authenticationType = 'apiKey',
apiKey = 'FAKE-KEY',
headers = {},
}: SpecialRequestVariations & {
authenticationType?: string;
apiKey?: string;
} = {},
headers?: CustomHeaders,
) {
expect(spy).toHaveBeenCalledWith(
expect.objectContaining({
authenticationType,
apiKey,
appSyncGraphqlEndpoint: endpoint,
authenticationType: 'apiKey',
apiKey: 'FAKE-KEY',
appSyncGraphqlEndpoint: 'https://localhost/graphql',
// Code-gen'd queries have an owner param; TypeBeast queries don't:
query: expect.stringContaining(`${opName}(filter: $filter`),
variables: expect.objectContaining(item),
@@ -208,16 +168,12 @@ export function expectSubWithHeadersFn(
spy: jest.SpyInstance<any, any>,
opName: string,
item: Record<string, any>,
{
endpoint = 'https://localhost/graphql',
headers = expect.objectContaining({ 'X-Api-Key': 'FAKE-KEY' }),
}: SpecialRequestVariations = {},
) {
expect(spy).toHaveBeenCalledWith(
expect.objectContaining({
authenticationType: 'apiKey',
apiKey: 'FAKE-KEY',
appSyncGraphqlEndpoint: endpoint,
appSyncGraphqlEndpoint: 'https://localhost/graphql',
// Code-gen'd queries have an owner param; TypeBeast queries don't:
query: expect.stringContaining(`${opName}(filter: $filter`),
variables: expect.objectContaining(item),

Unchanged files with check annotations Beta

* @param postInput.abortController The abort controller used to cancel the POST request
* @returns a {@link RestApiResponse}
*
* @throws an {@link AmplifyError} with `Network Error` as the `message` when the external resource is unreachable due to one

Check warning on line 50 in packages/api-rest/src/apis/common/internalPost.ts

GitHub Actions / unit-tests / Unit Test - @aws-amplify/api-rest

The type 'AmplifyError' is undefined

Check warning on line 50 in packages/api-rest/src/apis/common/internalPost.ts

GitHub Actions / e2e / unit-tests / Unit Test - @aws-amplify/api-rest

The type 'AmplifyError' is undefined
* of the following reasons:
* 1. no network connection
* 2. CORS error
import { DateUtils } from '../src/Signer/DateUtils';

Check warning on line 1 in packages/core/__tests__/DateUtils.test.ts

GitHub Actions / unit-tests / Unit Test - @aws-amplify/core

Deprecated

Check warning on line 1 in packages/core/__tests__/DateUtils.test.ts

GitHub Actions / e2e / unit-tests / Unit Test - @aws-amplify/core

Deprecated
describe('DateUtils', () => {
beforeAll(() => {
// SPDX-License-Identifier: Apache-2.0
import { SignRequestOptions } from '../src/clients/middleware/signing/signer/signatureV4/types';
import { Signer } from '../src/Signer';

Check warning on line 5 in packages/core/__tests__/Signer.test.ts

GitHub Actions / unit-tests / Unit Test - @aws-amplify/core

Deprecated

Check warning on line 5 in packages/core/__tests__/Signer.test.ts

GitHub Actions / e2e / unit-tests / Unit Test - @aws-amplify/core

Deprecated
import { DateUtils } from '../src/Signer/DateUtils';

Check warning on line 6 in packages/core/__tests__/Signer.test.ts

GitHub Actions / unit-tests / Unit Test - @aws-amplify/core

Deprecated

Check warning on line 6 in packages/core/__tests__/Signer.test.ts

GitHub Actions / e2e / unit-tests / Unit Test - @aws-amplify/core

Deprecated
import * as getSignatureModule from '../src/clients/middleware/signing/signer/signatureV4/utils/getSignature';
import {
import { Reachability as ReachabilityNative } from '../src/Reachability/Reachability.native';
import { Reachability } from '../src/Reachability/Reachability';
import { ConsoleLogger } from '../src/Logger';
import { DateUtils } from '../src/Signer/DateUtils';

Check warning on line 12 in packages/core/__tests__/utils.test.ts

GitHub Actions / unit-tests / Unit Test - @aws-amplify/core

Deprecated

Check warning on line 12 in packages/core/__tests__/utils.test.ts

GitHub Actions / e2e / unit-tests / Unit Test - @aws-amplify/core

Deprecated
ConsoleLogger.LOG_LEVEL = 'DEBUG';
} from '../clients/middleware/signing/signer/signatureV4';
import { AmplifyUrl } from '../utils/amplifyUrl';
import { DateUtils } from './DateUtils';

Check warning on line 11 in packages/core/src/Signer/Signer.ts

GitHub Actions / unit-tests / Unit Test - @aws-amplify/core

Deprecated

Check warning on line 11 in packages/core/src/Signer/Signer.ts

GitHub Actions / e2e / unit-tests / Unit Test - @aws-amplify/core

Deprecated
const IOT_SERVICE_NAME = 'iotdevicegateway';
// Best practice regex to parse the service and region from an AWS endpoint
/**
* @public
*
* The input for {@link GetCredentialsForIdentityCommand}.

Check warning on line 33 in packages/core/src/awsClients/cognitoIdentity/types.ts

GitHub Actions / unit-tests / Unit Test - @aws-amplify/core

The type 'GetCredentialsForIdentityCommand' is undefined

Check warning on line 33 in packages/core/src/awsClients/cognitoIdentity/types.ts

GitHub Actions / e2e / unit-tests / Unit Test - @aws-amplify/core

The type 'GetCredentialsForIdentityCommand' is undefined
*/
export type GetCredentialsForIdentityCommandInput =
GetCredentialsForIdentityInput;
/**
* @public
*
* The output of {@link GetCredentialsForIdentityCommand}.

Check warning on line 40 in packages/core/src/awsClients/cognitoIdentity/types.ts

GitHub Actions / unit-tests / Unit Test - @aws-amplify/core

The type 'GetCredentialsForIdentityCommand' is undefined

Check warning on line 40 in packages/core/src/awsClients/cognitoIdentity/types.ts

GitHub Actions / e2e / unit-tests / Unit Test - @aws-amplify/core

The type 'GetCredentialsForIdentityCommand' is undefined
*/
export interface GetCredentialsForIdentityCommandOutput
extends GetCredentialsForIdentityResponse,
/**
* @public
*
* The input for {@link GetIdCommand}.

Check warning on line 92 in packages/core/src/awsClients/cognitoIdentity/types.ts

GitHub Actions / unit-tests / Unit Test - @aws-amplify/core

The type 'GetIdCommand' is undefined

Check warning on line 92 in packages/core/src/awsClients/cognitoIdentity/types.ts

GitHub Actions / e2e / unit-tests / Unit Test - @aws-amplify/core

The type 'GetIdCommand' is undefined
*/
export type GetIdCommandInput = GetIdInput;
/**
* @public
*
* The output of {@link GetIdCommand}.

Check warning on line 98 in packages/core/src/awsClients/cognitoIdentity/types.ts

GitHub Actions / unit-tests / Unit Test - @aws-amplify/core

The type 'GetIdCommand' is undefined

Check warning on line 98 in packages/core/src/awsClients/cognitoIdentity/types.ts

GitHub Actions / e2e / unit-tests / Unit Test - @aws-amplify/core

The type 'GetIdCommand' is undefined
*/
export interface GetIdCommandOutput extends GetIdResponse, __MetadataBearer {}
/**
/**
* @public
*
* The input for {@link GetInAppMessagesCommand}.

Check warning on line 377 in packages/core/src/awsClients/pinpoint/types.ts

GitHub Actions / unit-tests / Unit Test - @aws-amplify/core

The type 'GetInAppMessagesCommand' is undefined

Check warning on line 377 in packages/core/src/awsClients/pinpoint/types.ts

GitHub Actions / e2e / unit-tests / Unit Test - @aws-amplify/core

The type 'GetInAppMessagesCommand' is undefined
*/
export type GetInAppMessagesCommandInput = GetInAppMessagesRequest;
/**