Skip to content

Commit ee90c2c

Browse files
authored
fix(modelgen): remove timestamps if defined null in @model (#355)
1 parent fa067e0 commit ee90c2c

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-visitor.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,21 @@ describe('AppSyncModelVisitor', () => {
680680
const updatedAtField = postFields.find(field => field.name === 'updatedOn');
681681
expect(updatedAtField).toMatchObject(updatedAtFieldObj);
682682
});
683+
it('should not generate timestamp fields if "timestamps:null" is defined in @model', () => {
684+
const schema = /* GraphQL */ `
685+
type Post @model(timestamps: null) {
686+
id: ID!
687+
}
688+
`;
689+
const visitor = createAndGenerateVisitor(schema);
690+
expect(visitor.models.Post).toBeDefined();
691+
692+
const postFields = visitor.models.Post.fields;
693+
const createdAtField = postFields.find(field => field.name === 'createdAt');
694+
expect(createdAtField).not.toBeDefined();
695+
const updatedAtField = postFields.find(field => field.name === 'updatedAt');
696+
expect(updatedAtField).not.toBeDefined();
697+
});
683698
});
684699

685700
describe('manyToMany testing', () => {

packages/appsync-modelgen-plugin/src/visitors/appsync-visitor.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,10 @@ export class AppSyncModelVisitor<
853853
if (directive.name !== 'model') {
854854
return;
855855
}
856+
//when the '{timestamps: null}' is defined in @model, the timestamp fields should not be generated
857+
if (directive.arguments && directive.arguments.hasOwnProperty('timestamps') && directive.arguments.timestamps === null) {
858+
return;
859+
}
856860
const timestamps = directive.arguments.timestamps;
857861
const createdAtField: CodeGenField = {
858862
name: timestamps?.createdAt || DEFAULT_CREATED_TIME,

0 commit comments

Comments
 (0)