Skip to content

Commit f611e94

Browse files
authored
feat(modelgen): add timestamp fields createdAt & updatedAt for @model (#114)
* feat(modelgen): add timestamp fields createdAt & updatedAt * add test for scenario 4 * add readOnly fields in java output * remove null in timestamp fields * remove readOnly params in swift constructor * feat: add read-only support for swift modelgen * fix: update field cannot be overrided * fix: address feedback * fix: add id field to not break customer * fix: add id in public init * fix: remove timestamp changes to js and dart * fix: remove metadata change * fix: remove update field override * feat: add FF support * feat: add timestamp fields in js modelgen
1 parent b3b03a0 commit f611e94

13 files changed

+1232
-140
lines changed

packages/amplify-codegen/src/commands/models.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const path = require('path');
22
const fs = require('fs-extra');
33
const { parse } = require('graphql');
4-
const glob = require('glob-all');
4+
const glob = require('glob-all');
55
const { FeatureFlags, pathManager } = require('amplify-cli-core');
66
const gqlCodeGen = require('@graphql-codegen/core');
77
const { getModelgenPackage } = require('../utils/getModelgenPackage');
@@ -53,12 +53,20 @@ async function generateModels(context) {
5353

5454
const appSyncDataStoreCodeGen = getModelgenPackage(FeatureFlags.getBoolean(modelgenPackageMigrationflag));
5555

56+
let isTimestampFieldsAdded = false;
57+
try {
58+
isTimestampFieldsAdded = FeatureFlags.getBoolean('addTimestampFields');
59+
} catch (err) {
60+
isTimestampFieldsAdded = false;
61+
}
62+
5663
const appsyncLocalConfig = await appSyncDataStoreCodeGen.preset.buildGeneratesSection({
5764
baseOutputDir: outputPath,
5865
schema,
5966
config: {
6067
target: platformToLanguageMap[projectConfig.frontend] || projectConfig.frontend,
6168
directives: directiveDefinitions,
69+
isTimestampFieldsAdded,
6270
},
6371
});
6472

@@ -78,12 +86,6 @@ async function generateModels(context) {
7886

7987
const generatedCode = await Promise.all(codeGenPromises);
8088

81-
// clean the output directory before re-generating models
82-
// const cleanOutputPath = FeatureFlags.getBoolean('codegen.cleanGeneratedModelsDirectory');
83-
// if (cleanOutputPath) {
84-
// await fs.emptyDir(outputPath);
85-
// }
86-
8789
appsyncLocalConfig.forEach((cfg, idx) => {
8890
const outPutPath = cfg.filename;
8991
fs.ensureFileSync(outPutPath);
@@ -116,9 +118,7 @@ function loadSchema(apiResourcePath) {
116118
}
117119
if (fs.pathExistsSync(schemaDirectory) && fs.lstatSync(schemaDirectory).isDirectory()) {
118120
// search recursively for graphql schema files inside `schema` directory
119-
const schemas = glob.sync([
120-
path.join(schemaDirectory, '**/*.graphql')
121-
]);
121+
const schemas = glob.sync([path.join(schemaDirectory, '**/*.graphql')]);
122122
return schemas.map(file => fs.readFileSync(file, 'utf8')).join('\n');
123123
}
124124

0 commit comments

Comments
 (0)