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

Revert "fix: pushing multiple APIs at a time" #8689

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion packages/amplify-category-api/src/commands/api/override.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const run = async (context: $TSContext) => {
throw 'To be implemented';
} else if (service === AmplifySupportedService.APIGW) {
// Migration logic goes in here
const apigwInputState = new ApigwInputState(context, selectedResourceName);
const apigwInputState = ApigwInputState.getInstance(context, selectedResourceName);
if (!apigwInputState.cliInputsFileExists()) {
if (await prompter.yesOrNo('File migration required to continue. Do you want to continue?', true)) {
await apigwInputState.migrateApigwResource(selectedResourceName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,22 @@ import { ApigwInputs, ApigwStackTransform, CrudOperation, Path, PermissionSettin
import { ApigwWalkthroughReturnPromise } from './service-walkthrough-types/apigw-types';

export class ApigwInputState {
private static instance: ApigwInputState;
projectRootPath: string;
resourceName: string;
paths: { [pathName: string]: Path };

constructor(private readonly context: $TSContext, resourceName?: string) {
private constructor(private readonly context: $TSContext, resourceName?: string) {
this.projectRootPath = pathManager.findProjectRoot();
this.resourceName = resourceName;
ApigwInputState.instance = this;
}

public static getInstance(context: $TSContext, resourceName?: string) {
if (!ApigwInputState.instance) {
new ApigwInputState(context, resourceName);
}
return ApigwInputState.instance;
}

public addAdminQueriesResource = async (adminQueriesProps: AdminQueriesProps) => {
Expand Down Expand Up @@ -205,7 +214,7 @@ export class ApigwInputState {

stateManager.setResourceParametersJson(this.projectRootPath, AmplifyCategories.API, this.resourceName, {});

const stack = new ApigwStackTransform(this.context, this.resourceName, this);
const stack = new ApigwStackTransform(this.context, this.resourceName);
await stack.transform();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ export class ApigwStackTransform {
cfnInputParams!: {};
resourceName: string;

constructor(context: $TSContext, resourceName: string, cliInputState?: ApigwInputState) {
constructor(context: $TSContext, resourceName: string) {
this._app = new cdk.App();
this.resourceName = resourceName;

// Validate the cli-inputs.json for the resource
this.cliInputsState = cliInputState ?? new ApigwInputState(context, resourceName);
this.cliInputsState = ApigwInputState.getInstance(context, this.resourceName);
this.cliInputs = this.cliInputsState.getCliInputPayload();
this.cliInputsState.isCLIInputsValid();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ export async function addAdminQueriesApi(
context: $TSContext,
apiProps: { apiName: string; functionName: string; authResourceName: string; dependsOn: $TSObject[] },
) {
const apigwInputState = new ApigwInputState(context, apiProps.apiName);
const apigwInputState = ApigwInputState.getInstance(context, apiProps.apiName);
return apigwInputState.addAdminQueriesResource(apiProps);
}

export async function updateAdminQueriesApi(
context: $TSContext,
apiProps: { apiName: string; functionName: string; authResourceName: string; dependsOn: $TSObject[] },
) {
const apigwInputState = new ApigwInputState(context, apiProps.apiName);
const apigwInputState = ApigwInputState.getInstance(context, apiProps.apiName);
// Check for migration

if (!apigwInputState.cliInputsFileExists()) {
await apigwInputState.migrateAdminQueries(apiProps);
} else {
return apigwInputState.updateAdminQueriesResource(apiProps);
return apigwInputState.addAdminQueriesResource(apiProps);
}
}

Expand Down Expand Up @@ -79,7 +79,7 @@ async function addNonContainerResource(context: $TSContext, service: string, opt
}
return apiName;
case AmplifySupportedService.APIGW:
const apigwInputState = new ApigwInputState(context);
const apigwInputState = ApigwInputState.getInstance(context);
return apigwInputState.addApigwResource(serviceWalkthroughPromise, options);
default:
return legacyAddResource(serviceWalkthroughPromise, context, category, service, options);
Expand Down Expand Up @@ -263,7 +263,7 @@ async function updateNonContainerResource(context: $TSContext, service: string)
case AmplifySupportedService.APPSYNC:
return updateWalkthroughPromise.then(getCfnApiArtifactHandler(context).updateArtifacts);
default:
const apigwInputState = new ApigwInputState(context);
const apigwInputState = ApigwInputState.getInstance(context);
return apigwInputState.updateApigwResource(updateWalkthroughPromise);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,6 @@ async function askApiName(context: $TSContext, defaultResourceName: string) {
required: true,
})(input);

const adminQueriesName = 'AdminQueries';
if (input === adminQueriesName) {
return `${adminQueriesName} is a reserved name for REST API resources for use by the auth category. Run "amplify update auth" to create an Admin Queries API.`;
}

let uniqueCheck = false;
try {
uniqueCheck = isResourceNameUnique(category, input);
Expand Down Expand Up @@ -590,7 +585,7 @@ async function askLambdaArn(context: $TSContext, currentPath?: ApigwPath) {
}

export async function migrate(context: $TSContext, projectPath: string, resourceName: string) {
const apigwInputState = new ApigwInputState(context, resourceName);
const apigwInputState = ApigwInputState.getInstance(context, resourceName);
return apigwInputState.migrateApigwResource(resourceName);
}

Expand Down