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: move importedModels key up to defineData #13943

Open
wants to merge 1 commit into
base: migrations
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,13 @@ describe('Data Category code generation', () => {
const array = source.match(/importedModels:\s+\[(.*?)\]/);
assert.deepEqual(tables, array?.[1].replaceAll('"', '').split(', '));
});
it('has each each key in defineData', () => {
const tableMapping = { Todo: 'my-todo-mapping' };
const source = printNodeArray(generateDataSource({ tableMapping }));
assert.match(
source,
/defineData\({\n\s+importedAmplifyDynamoDBTableMap: \{\s+Todo: ['"]my-todo-mapping['"] },\n\s+importedModels:\s+\[.*?\],\n\s+schema: "TODO: Add your existing graphql schema here"\n}\)/,
);
});
});
});
16 changes: 8 additions & 8 deletions packages/amplify-gen2-codegen/src/data/source_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@ export const generateDataSource = (dataDefinition?: DataDefinition): ts.NodeArra
tableMappingProperties.push(
factory.createPropertyAssignment(factory.createIdentifier(tableName), factory.createStringLiteral(tableId)),
);
tableMappingProperties.push(
factory.createPropertyAssignment(
factory.createIdentifier(importedModelsKey),
factory.createArrayLiteralExpression(
Object.keys(dataDefinition.tableMapping).map((tableName) => factory.createStringLiteral(tableName)),
),
),
);
}
dataRenderProperties.push(
factory.createPropertyAssignment(
importedAmplifyDynamoDBTableMapKeyName,
factory.createObjectLiteralExpression(tableMappingProperties),
),
);
dataRenderProperties.push(
factory.createPropertyAssignment(
importedModelsKey,
factory.createArrayLiteralExpression(
Object.keys(dataDefinition.tableMapping).map((tableName) => factory.createStringLiteral(tableName)),
),
),
);
}
dataRenderProperties.push(
factory.createPropertyAssignment(factory.createIdentifier('schema'), factory.createStringLiteral(schemaPlaceholderComment)),
Expand Down
Loading