@aws-amplify/graphql-model-transformer 0.16.10-alpha.0 → 0.16.10-alpha.74

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -37,4 +37,33 @@ describe('ModelTransformer: ', () => {
37
37
  expect(postStack).toMatchSnapshot();
38
38
  expect(commentStack).toMatchSnapshot();
39
39
  });
40
+
41
+ it('should not override model objects when override file does not exist', () => {
42
+ const validSchema = `
43
+ type Post @model {
44
+ id: ID!
45
+ comments: [Comment]
46
+ }
47
+ type Comment @model{
48
+ id: String!
49
+ text: String!
50
+ }
51
+ `;
52
+ const transformer = new GraphQLTransform({
53
+ transformers: [new ModelTransformer()],
54
+ overrideConfig: {
55
+ overrideDir: path.join(__dirname, 'non-existing-override-directory'),
56
+ overrideFlag: true,
57
+ resourceName: 'myResource',
58
+ },
59
+ featureFlags,
60
+ });
61
+ const out = transformer.transform(validSchema);
62
+ expect(out).toBeDefined();
63
+ const postStack = out.stacks.Post;
64
+ const commentStack = out.stacks.Comment;
65
+
66
+ expect(postStack).toMatchSnapshot();
67
+ expect(commentStack).toMatchSnapshot();
68
+ });
40
69
  });
@@ -13,7 +13,7 @@ import {
13
13
  verifyInputCount,
14
14
  verifyMatchingTypes,
15
15
  } from './test-utils/helpers';
16
- import { expect as cdkExpect, haveResource, haveResourceLike } from '@aws-cdk/assert';
16
+ import { Template } from 'aws-cdk-lib/assertions';
17
17
 
18
18
  const featureFlags = {
19
19
  getBoolean: jest.fn(),
@@ -1027,8 +1027,8 @@ describe('ModelTransformer: ', () => {
1027
1027
 
1028
1028
  const iamStackResource = out.stacks.ThisIsAVeryLongNameModelThatShouldNotGenerateIAMRoleNamesOver64Characters;
1029
1029
  expect(iamStackResource).toBeDefined();
1030
- cdkExpect(iamStackResource).to(
1031
- haveResource('AWS::IAM::Role', {
1030
+ Template.fromJSON(iamStackResource)
1031
+ .hasResourceProperties('AWS::IAM::Role', {
1032
1032
  AssumeRolePolicyDocument: {
1033
1033
  Statement: [
1034
1034
  {
@@ -1056,8 +1056,7 @@ describe('ModelTransformer: ', () => {
1056
1056
  ],
1057
1057
  ],
1058
1058
  },
1059
- }),
1060
- );
1059
+ });
1061
1060
 
1062
1061
  validateModelSchema(parsed);
1063
1062
  });
@@ -1122,8 +1121,8 @@ describe('ModelTransformer: ', () => {
1122
1121
  expect(out.resolvers['Query.syncTodos.req.vtl']).toMatchSnapshot();
1123
1122
  expect(out.resolvers['Query.syncTodos.res.vtl']).toMatchSnapshot();
1124
1123
  // ds table
1125
- cdkExpect(out.rootStack).to(
1126
- haveResource('AWS::DynamoDB::Table', {
1124
+ Template.fromJSON(out.rootStack)
1125
+ .hasResourceProperties('AWS::DynamoDB::Table', {
1127
1126
  KeySchema: [
1128
1127
  {
1129
1128
  AttributeName: 'ds_pk',
@@ -1167,8 +1166,7 @@ describe('ModelTransformer: ', () => {
1167
1166
  AttributeName: '_ttl',
1168
1167
  Enabled: true,
1169
1168
  },
1170
- }),
1171
- );
1169
+ });
1172
1170
  });
1173
1171
  it("the conflict detection of per model rule should be respected", () => {
1174
1172
  const validSchema = `
@@ -1212,50 +1210,44 @@ describe('ModelTransformer: ', () => {
1212
1210
  const todoStack = out.stacks["Todo"];
1213
1211
  const authorStack = out.stacks["Author"];
1214
1212
  // Todo stack should have lambda for conflict detect rather than auto merge
1215
- cdkExpect(todoStack).to(
1216
- haveResourceLike(
1217
- "AWS::AppSync::FunctionConfiguration",
1218
- {
1219
- SyncConfig: {
1220
- ConflictDetection: "VERSION",
1221
- ConflictHandler: "LAMBDA",
1222
- }
1213
+ Template.fromJSON(todoStack).hasResourceProperties(
1214
+ "AWS::AppSync::FunctionConfiguration",
1215
+ {
1216
+ SyncConfig: {
1217
+ ConflictDetection: "VERSION",
1218
+ ConflictHandler: "LAMBDA",
1223
1219
  }
1224
- )
1220
+ }
1225
1221
  );
1226
- cdkExpect(todoStack).notTo(
1227
- haveResourceLike(
1228
- "AWS::AppSync::FunctionConfiguration",
1229
- {
1230
- SyncConfig: {
1231
- ConflictDetection: "VERSION",
1232
- ConflictHandler: "AUTOMERGE",
1233
- }
1222
+ Template.fromJSON(todoStack).resourcePropertiesCountIs(
1223
+ "AWS::AppSync::FunctionConfiguration",
1224
+ {
1225
+ SyncConfig: {
1226
+ ConflictDetection: "VERSION",
1227
+ ConflictHandler: "AUTOMERGE",
1234
1228
  }
1235
- )
1229
+ },
1230
+ 0
1236
1231
  );
1237
1232
  // Author stack should have automerge for conflict detect rather than lambda
1238
- cdkExpect(authorStack).notTo(
1239
- haveResourceLike(
1240
- "AWS::AppSync::FunctionConfiguration",
1241
- {
1242
- SyncConfig: {
1243
- ConflictDetection: "VERSION",
1244
- ConflictHandler: "LAMBDA",
1245
- }
1233
+ Template.fromJSON(authorStack).resourcePropertiesCountIs(
1234
+ "AWS::AppSync::FunctionConfiguration",
1235
+ {
1236
+ SyncConfig: {
1237
+ ConflictDetection: "VERSION",
1238
+ ConflictHandler: "LAMBDA",
1246
1239
  }
1247
- )
1240
+ },
1241
+ 0
1248
1242
  );
1249
- cdkExpect(authorStack).to(
1250
- haveResourceLike(
1251
- "AWS::AppSync::FunctionConfiguration",
1252
- {
1253
- SyncConfig: {
1254
- ConflictDetection: "VERSION",
1255
- ConflictHandler: "AUTOMERGE",
1256
- }
1243
+ Template.fromJSON(authorStack).hasResourceProperties(
1244
+ "AWS::AppSync::FunctionConfiguration",
1245
+ {
1246
+ SyncConfig: {
1247
+ ConflictDetection: "VERSION",
1248
+ ConflictHandler: "AUTOMERGE",
1257
1249
  }
1258
- )
1250
+ }
1259
1251
  );
1260
1252
 
1261
1253
  });
@@ -35,11 +35,11 @@ import {
35
35
  StreamViewType,
36
36
  Table,
37
37
  TableEncryption,
38
- } from '@aws-cdk/aws-dynamodb';
39
- import * as iam from '@aws-cdk/aws-iam';
40
- import { CfnRole } from '@aws-cdk/aws-iam';
41
- import * as cdk from '@aws-cdk/core';
42
- import { CfnDataSource } from '@aws-cdk/aws-appsync';
38
+ } from 'aws-cdk-lib/aws-dynamodb';
39
+ import * as iam from 'aws-cdk-lib/aws-iam';
40
+ import { CfnRole } from 'aws-cdk-lib/aws-iam';
41
+ import * as cdk from 'aws-cdk-lib';
42
+ import { CfnDataSource } from 'aws-cdk-lib/aws-appsync';
43
43
  import {
44
44
  DirectiveNode,
45
45
  FieldDefinitionNode,
@@ -1238,6 +1238,10 @@ export class ModelTransformer extends TransformerModelBase implements Transforme
1238
1238
  });
1239
1239
  const cfnTable = table.node.defaultChild as CfnTable;
1240
1240
 
1241
+ // CDK started to append hash to logical id of dynamodb table.
1242
+ // This line overrides that behavior to avoid deletion and re-creation of existing tables.
1243
+ cfnTable.overrideLogicalId(tableLogicalName);
1244
+
1241
1245
  cfnTable.provisionedThroughput = cdk.Fn.conditionIf(usePayPerRequestBilling.logicalId, cdk.Fn.ref('AWS::NoValue'), {
1242
1246
  ReadCapacityUnits: readIops,
1243
1247
  WriteCapacityUnits: writeIops,