Skip to content

Commit

Permalink
fix: pushing multiple APIs at a time (aws-amplify#8663)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhockett authored and akshbhu committed Nov 10, 2021
1 parent 8d09217 commit 65a45ce
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 20 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 = ApigwInputState.getInstance(context, selectedResourceName);
const apigwInputState = new ApigwInputState(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,22 +17,13 @@ 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 };

private constructor(private readonly context: $TSContext, resourceName?: string) {
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 @@ -214,7 +205,7 @@ export class ApigwInputState {

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

const stack = new ApigwStackTransform(this.context, this.resourceName);
const stack = new ApigwStackTransform(this.context, this.resourceName, this);
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) {
constructor(context: $TSContext, resourceName: string, cliInputState?: ApigwInputState) {
this._app = new cdk.App();
this.resourceName = resourceName;

// Validate the cli-inputs.json for the resource
this.cliInputsState = ApigwInputState.getInstance(context, this.resourceName);
this.cliInputsState = cliInputState ?? new ApigwInputState(context, 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 = ApigwInputState.getInstance(context, apiProps.apiName);
const apigwInputState = new ApigwInputState(context, apiProps.apiName);
return apigwInputState.addAdminQueriesResource(apiProps);
}

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

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

Expand Down Expand Up @@ -79,7 +79,7 @@ async function addNonContainerResource(context: $TSContext, service: string, opt
}
return apiName;
case AmplifySupportedService.APIGW:
const apigwInputState = ApigwInputState.getInstance(context);
const apigwInputState = new ApigwInputState(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 = ApigwInputState.getInstance(context);
const apigwInputState = new ApigwInputState(context);
return apigwInputState.updateApigwResource(updateWalkthroughPromise);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ 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 @@ -585,7 +590,7 @@ async function askLambdaArn(context: $TSContext, currentPath?: ApigwPath) {
}

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

Expand Down

0 comments on commit 65a45ce

Please sign in to comment.