Skip to content

Commit

Permalink
fix: move importedModels key up to defineData
Browse files Browse the repository at this point in the history
  • Loading branch information
dpilch committed Sep 26, 2024
1 parent 32edb50 commit 663d474
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
8 changes: 8 additions & 0 deletions packages/amplify-gen2-codegen/src/data/source_builder.test.ts
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

0 comments on commit 663d474

Please sign in to comment.