Skip to content

Commit

Permalink
Revert "fix: pushing multiple APIs at a time (#8663)"
Browse files Browse the repository at this point in the history
This reverts commit 4ff68bb.
  • Loading branch information
akshbhu authored Nov 5, 2021
1 parent fdbab02 commit d8e5ace
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 16 deletions.
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

0 comments on commit d8e5ace

Please sign in to comment.