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

fix(graphql): reset api config on mock exit #9385

Merged
merged 2 commits into from
Jan 5, 2022
Merged
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
3 changes: 2 additions & 1 deletion packages/amplify-util-mock/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class APITest {
context.amplify.addCleanUpTask(async context => {
await this.stop(context);
});
this.configOverrideManager = ConfigOverrideManager.getInstance(context);
this.configOverrideManager = await ConfigOverrideManager.getInstance(context);
// check java version
await checkJavaVersion(context);
this.apiName = await this.getAppSyncAPI(context);
Expand Down Expand Up @@ -177,6 +177,7 @@ export class APITest {
testMode: true,
});
}

private async ensureDDBTables(config) {
const tables = config.tables.map(t => t.Properties);
await createAndUpdateTable(this.ddbClient, config);
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-util-mock/src/storage/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class StorageTest {
context.amplify.addCleanUpTask(async context => {
await this.stop();
});
this.configOverrideManager = ConfigOverrideManager.getInstance(context);
this.configOverrideManager = await ConfigOverrideManager.getInstance(context);
this.storageName = await this.getStorage(context);
const storageConfig = { port, route, localDirS3 };
this.storageSimulator = new AmplifyStorageSimulator(storageConfig);
Expand Down
10 changes: 6 additions & 4 deletions packages/amplify-util-mock/src/utils/config-override.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { getAmplifyMeta } from './index';
export class ConfigOverrideManager {
private static instance: ConfigOverrideManager = null;
private overrides: {};
private amplifyMeta: any = {};
constructor(context) {
this.overrides = {};
context.amplify.addCleanUpTask(async context => {
Expand All @@ -22,13 +23,14 @@ export class ConfigOverrideManager {
}

async restoreFrontendExports(context) {
const meta = await getAmplifyMeta(context);
await context.amplify.onCategoryOutputsChange(context, null, meta);
await context.amplify.onCategoryOutputsChange(context, null, this.amplifyMeta);
}

static getInstance(context: any) {
static async getInstance(context: any): Promise<ConfigOverrideManager> {
if (!ConfigOverrideManager.instance) {
ConfigOverrideManager.instance = new ConfigOverrideManager(context);
const configOverrideManager = new ConfigOverrideManager(context);
configOverrideManager.amplifyMeta = await getAmplifyMeta(context);
ConfigOverrideManager.instance = configOverrideManager;
}
return ConfigOverrideManager.instance;
}
Expand Down