@aws-amplify/graphql-model-transformer 0.9.3-beta.0 → 0.9.4-beta.0

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.
@@ -1 +1 @@
1
- {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/resolvers/common.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EAmBvB,MAAM,0BAA0B,CAAC;AAWlC,eAAO,MAAM,qBAAqB,6BAA8B,MAAM,+BAA+B,MAAM,KAAG,sBA8B7G,CAAC;AAMF,eAAO,MAAM,sCAAsC,kBAAmB,OAAO,yBAAqB,MAkBjG,CAAC;AAOF,eAAO,MAAM,mBAAmB,aAAc,MAAM,aAAa,MAAM,KAAG,MAEzE,CAAC;AAMF,eAAO,MAAM,oCAAoC,QAAS,GAAG,KAAG,MAU/D,CAAC"}
1
+ {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/resolvers/common.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EAmBvB,MAAM,0BAA0B,CAAC;AAWlC,eAAO,MAAM,qBAAqB,6BAA8B,MAAM,+BAA+B,MAAM,KAAG,sBA8B7G,CAAC;AAMF,eAAO,MAAM,sCAAsC,kBAAmB,OAAO,yBAAqB,MAkBjG,CAAC;AAOF,eAAO,MAAM,mBAAmB,aAAc,MAAM,aAAa,MAAM,KAAG,MAEzE,CAAC;AAKF,eAAO,MAAM,oCAAoC,YAAa,OAAO,KAAG,MASvE,CAAC"}
@@ -40,8 +40,7 @@ const generateResolverKey = (typeName, fieldName) => {
40
40
  return `${typeName}.${fieldName}`;
41
41
  };
42
42
  exports.generateResolverKey = generateResolverKey;
43
- const generateAuthExpressionForSandboxMode = (ctx) => {
44
- const enabled = ctx.resourceHelper.api.sandboxModeEnabled;
43
+ const generateAuthExpressionForSandboxMode = (enabled) => {
45
44
  let exp;
46
45
  if (enabled)
47
46
  exp = graphql_mapping_template_1.iff(graphql_mapping_template_1.notEquals(graphql_mapping_template_1.methodCall(graphql_mapping_template_1.ref('util.authType')), graphql_mapping_template_1.str(API_KEY)), graphql_mapping_template_1.methodCall(graphql_mapping_template_1.ref('util.unauthorized')));
@@ -1 +1 @@
1
- {"version":3,"file":"common.js","sourceRoot":"","sources":["../../src/resolvers/common.ts"],"names":[],"mappings":";;;AAAA,uEAoBkC;AAClC,gDAA+C;AAE/C,MAAM,OAAO,GAAG,uBAAuB,CAAC;AAQjC,MAAM,qBAAqB,GAAG,CAAC,wBAAgC,EAAE,2BAAmC,EAA0B,EAAE;IACrI,MAAM,UAAU,GAAiB;QAC/B,kCAAO,CAAC,uBAAuB,CAAC;QAEhC,8BAAG,CACD,8BAAG,CAAC,CAAC,8BAAG,CAAC,wBAAwB,CAAC,EAAE,oCAAS,CAAC,qCAAU,CAAC,8BAAG,CAAC,GAAG,wBAAwB,OAAO,CAAC,CAAC,EAAE,8BAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAC5G,6CAAkB,CAAC;YACjB,8BAAG,CAAC,8BAAG,CAAC,kBAAkB,CAAC,EAAE,8BAAG,CAAC,EAAE,GAAG,EAAE,8BAAG,CAAC,wBAAwB,CAAC,EAAE,CAAC,CAAC;YACzE,8BAAG,CACD,8BAAG,CAAC,2BAA2B,CAAC,EAChC,qCAAU,CAAC,8BAAG,CAAC,gBAAgB,CAAC,EAAE,qCAAU,CAAC,8BAAG,CAAC,8CAA8C,CAAC,EAAE,8BAAG,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAC5H;YACD,8BAAG,CACD,8BAAG,CAAC;gBACF,8BAAG,CAAC,GAAG,2BAA2B,mBAAmB,CAAC;gBACtD,iCAAM,CAAC,qCAAU,CAAC,8BAAG,CAAC,GAAG,2BAA2B,wBAAwB,CAAC,CAAC,EAAE,8BAAG,CAAC,CAAC,CAAC,CAAC;aACxF,CAAC,EACF,8BAAG,CACD,8BAAG,CAAC,2BAA2B,CAAC,EAChC,8BAAG,CAAC;gBACF,UAA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AAC,8BAAG,CAAC,eAAe,CAAC,CAAC,EAAE,8BAAG,CAAC,OAAO,CAAC,CAAC,EAAE,qCAAU,CAAC,8BAAG,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC;;QACnH,GAAG,GAAG,qCAAU,CAAC,8BAAG,CAAC,mBAAmB,CAAC,CAAC,CAAC;IAEhD,OAAO,qCAAU,CAAC,gBAAgB,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC,CACnE,6CAAkB,CAAC,CAAC,8BAAG,CAAC,8BAAG,CAAC,8BAAG,CAAC,0BAA0B,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,iCAAM,CAAC,8BAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CACtF,CAAC;AACJ,CAAC,CAAC;AATW,QAAA,oCAAoC,wCAS/C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-amplify/graphql-model-transformer",
3
- "version": "0.9.3-beta.0",
3
+ "version": "0.9.4-beta.0",
4
4
  "description": "Amplify graphql @model transformer",
5
5
  "repository": {
6
6
  "type": "git",
@@ -28,8 +28,8 @@
28
28
  "test-watch": "jest --watch"
29
29
  },
30
30
  "dependencies": {
31
- "@aws-amplify/graphql-transformer-core": "0.12.3-beta.0",
32
- "@aws-amplify/graphql-transformer-interfaces": "1.12.3-beta.0",
31
+ "@aws-amplify/graphql-transformer-core": "0.13.2-beta.0",
32
+ "@aws-amplify/graphql-transformer-interfaces": "1.12.4-beta.0",
33
33
  "@aws-cdk/assets": "~1.124.0",
34
34
  "@aws-cdk/aws-applicationautoscaling": "~1.124.0",
35
35
  "@aws-cdk/aws-appsync": "~1.124.0",
@@ -57,8 +57,8 @@
57
57
  "@aws-cdk/region-info": "~1.124.0",
58
58
  "constructs": "^3.3.125",
59
59
  "graphql": "^14.5.8",
60
- "graphql-mapping-template": "4.20.3-beta.0",
61
- "graphql-transformer-common": "4.22.3-beta.0",
60
+ "graphql-mapping-template": "4.20.1",
61
+ "graphql-transformer-common": "4.22.4-beta.0",
62
62
  "lodash": "^4.17.21",
63
63
  "md5": "^2.3.0"
64
64
  },
@@ -83,5 +83,5 @@
83
83
  ],
84
84
  "collectCoverage": true
85
85
  },
86
- "gitHead": "13a3369b0af71c169cc5ff2943d2714cd790639e"
86
+ "gitHead": "c6a97a5a6512e8c723a500ae7288be6af6afe6d5"
87
87
  }
@@ -13303,7 +13303,7 @@ $util.toJson($UpdateItem)
13303
13303
  ## [End] Mutation Update resolver. **"
13304
13304
  `;
13305
13305
 
13306
- exports[`ModelTransformer: should support timestamp parameters when generating pipelineFunctions and output schema 1`] = `
13306
+ exports[`ModelTransformer: should support timestamp parameters when generating resolvers and output schema 1`] = `
13307
13307
  "
13308
13308
  type Post {
13309
13309
  id: ID!
@@ -13457,7 +13457,7 @@ type Subscription {
13457
13457
  "
13458
13458
  `;
13459
13459
 
13460
- exports[`ModelTransformer: should support timestamp parameters when generating pipelineFunctions and output schema 2`] = `
13460
+ exports[`ModelTransformer: should support timestamp parameters when generating resolvers and output schema 2`] = `
13461
13461
  "## [Start] Create Request template. **
13462
13462
  ## Set the default values to put request **
13463
13463
  #set( $mergedValues = $util.defaultIfNull($ctx.stash.defaultValues, {}) )
@@ -13525,7 +13525,7 @@ $util.toJson($PutObject)
13525
13525
  ## [End] Create Request template. **"
13526
13526
  `;
13527
13527
 
13528
- exports[`ModelTransformer: should support timestamp parameters when generating pipelineFunctions and output schema 3`] = `
13528
+ exports[`ModelTransformer: should support timestamp parameters when generating resolvers and output schema 3`] = `
13529
13529
  "## [Start] Mutation Update resolver. **
13530
13530
  ## Set the default values to put request **
13531
13531
  #set( $mergedValues = $util.defaultIfNull($ctx.stash.defaultValues, {}) )
@@ -411,7 +411,7 @@ describe('ModelTransformer: ', () => {
411
411
  expect(defaultIdField).toBeDefined();
412
412
  expect(getBaseType(defaultIdField.type)).toEqual('Int');
413
413
  // It should not add default value for ctx.arg.id as id is of type Int
414
- expect(result.pipelineFunctions['Mutation.createPost.req.vtl']).toMatchSnapshot();
414
+ expect(result.resolvers['Mutation.createPost.req.vtl']).toMatchSnapshot();
415
415
  });
416
416
 
417
417
  it('should generate only create mutation', () => {
@@ -670,7 +670,7 @@ describe('ModelTransformer: ', () => {
670
670
  validateModelSchema(schema);
671
671
  });
672
672
 
673
- it('should support timestamp parameters when generating pipelineFunctions and output schema', () => {
673
+ it('should support timestamp parameters when generating resolvers and output schema', () => {
674
674
  const validSchema = `
675
675
  type Post @model(timestamps: { createdAt: "createdOn", updatedAt: "updatedOn"}) {
676
676
  id: ID!
@@ -688,8 +688,8 @@ describe('ModelTransformer: ', () => {
688
688
  const schema = parse(result.schema);
689
689
  validateModelSchema(schema);
690
690
 
691
- expect(result.pipelineFunctions['Mutation.createPost.req.vtl']).toMatchSnapshot();
692
- expect(result.pipelineFunctions['Mutation.updatePost.req.vtl']).toMatchSnapshot();
691
+ expect(result.resolvers['Mutation.createPost.req.vtl']).toMatchSnapshot();
692
+ expect(result.resolvers['Mutation.updatePost.req.vtl']).toMatchSnapshot();
693
693
  });
694
694
 
695
695
  it('should not to auto generate createdAt and updatedAt when the type in schema is not AWSDateTime', () => {
@@ -712,8 +712,8 @@ describe('ModelTransformer: ', () => {
712
712
  const schema = parse(result.schema);
713
713
  validateModelSchema(schema);
714
714
 
715
- expect(result.pipelineFunctions['Mutation.createPost.req.vtl']).toMatchSnapshot();
716
- expect(result.pipelineFunctions['Mutation.updatePost.req.vtl']).toMatchSnapshot();
715
+ expect(result.resolvers['Mutation.createPost.req.vtl']).toMatchSnapshot();
716
+ expect(result.resolvers['Mutation.updatePost.req.vtl']).toMatchSnapshot();
717
717
  });
718
718
 
719
719
  it('should have timestamps as nullable fields when the type makes it non-nullable', () => {
@@ -737,8 +737,8 @@ describe('ModelTransformer: ', () => {
737
737
  const schema = parse(result.schema);
738
738
  validateModelSchema(schema);
739
739
 
740
- expect(result.pipelineFunctions['Mutation.createPost.req.vtl']).toMatchSnapshot();
741
- expect(result.pipelineFunctions['Mutation.updatePost.req.vtl']).toMatchSnapshot();
740
+ expect(result.resolvers['Mutation.createPost.req.vtl']).toMatchSnapshot();
741
+ expect(result.resolvers['Mutation.updatePost.req.vtl']).toMatchSnapshot();
742
742
  });
743
743
 
744
744
  it('should not to include createdAt and updatedAt field when timestamps is set to null', () => {
@@ -759,8 +759,8 @@ describe('ModelTransformer: ', () => {
759
759
  const schema = parse(result.schema);
760
760
  validateModelSchema(schema);
761
761
 
762
- expect(result.pipelineFunctions['Mutation.createPost.req.vtl']).toMatchSnapshot();
763
- expect(result.pipelineFunctions['Mutation.updatePost.req.vtl']).toMatchSnapshot();
762
+ expect(result.resolvers['Mutation.createPost.req.vtl']).toMatchSnapshot();
763
+ expect(result.resolvers['Mutation.updatePost.req.vtl']).toMatchSnapshot();
764
764
  });
765
765
 
766
766
  it('should filter known input types from create and update input fields', () => {
@@ -908,7 +908,7 @@ describe('ModelTransformer: ', () => {
908
908
 
909
909
  const definition = out.schema;
910
910
  expect(definition).toBeDefined();
911
- expect(out.pipelineFunctions).toMatchSnapshot();
911
+ expect(out.resolvers).toMatchSnapshot();
912
912
 
913
913
  validateModelSchema(parse(definition));
914
914
  });
@@ -945,7 +945,7 @@ describe('ModelTransformer: ', () => {
945
945
 
946
946
  const definition = out.schema;
947
947
  expect(definition).toBeDefined();
948
- expect(out.pipelineFunctions).toMatchSnapshot();
948
+ expect(out.resolvers).toMatchSnapshot();
949
949
 
950
950
  validateModelSchema(parse(definition));
951
951
  });
@@ -979,7 +979,7 @@ describe('ModelTransformer: ', () => {
979
979
 
980
980
  const definition = out.schema;
981
981
  expect(definition).toBeDefined();
982
- expect(out.pipelineFunctions).toMatchSnapshot();
982
+ expect(out.resolvers).toMatchSnapshot();
983
983
 
984
984
  validateModelSchema(parse(definition));
985
985
  });
@@ -1115,8 +1115,8 @@ describe('ModelTransformer: ', () => {
1115
1115
  const queryObject = getObjectType(schema, 'Query');
1116
1116
  expectFields(queryObject!, ['syncTodos']);
1117
1117
  // sync resolvers
1118
- expect(out.pipelineFunctions['Query.syncTodos.req.vtl']).toMatchSnapshot();
1119
- expect(out.pipelineFunctions['Query.syncTodos.res.vtl']).toMatchSnapshot();
1118
+ expect(out.resolvers['Query.syncTodos.req.vtl']).toMatchSnapshot();
1119
+ expect(out.resolvers['Query.syncTodos.res.vtl']).toMatchSnapshot();
1120
1120
  // ds table
1121
1121
  cdkExpect(out.rootStack).to(
1122
1122
  haveResource('AWS::DynamoDB::Table', {
@@ -1166,4 +1166,108 @@ describe('ModelTransformer: ', () => {
1166
1166
  }),
1167
1167
  );
1168
1168
  });
1169
+
1170
+ it('should add the model parameters at the root sack', () => {
1171
+ const modelParams = {
1172
+ DynamoDBModelTableReadIOPS: expect.objectContaining({
1173
+ Type: 'Number',
1174
+ Default: 5,
1175
+ Description: 'The number of read IOPS the table should support.',
1176
+ }),
1177
+ DynamoDBModelTableWriteIOPS: expect.objectContaining({
1178
+ Type: 'Number',
1179
+ Default: 5,
1180
+ Description: 'The number of write IOPS the table should support.',
1181
+ }),
1182
+ DynamoDBBillingMode: expect.objectContaining({
1183
+ Type: 'String',
1184
+ Default: 'PAY_PER_REQUEST',
1185
+ AllowedValues: ['PAY_PER_REQUEST', 'PROVISIONED'],
1186
+ Description: 'Configure @model types to create DynamoDB tables with PAY_PER_REQUEST or PROVISIONED billing modes.',
1187
+ }),
1188
+ DynamoDBEnablePointInTimeRecovery: expect.objectContaining({
1189
+ Type: 'String',
1190
+ Default: 'false',
1191
+ AllowedValues: ['true', 'false'],
1192
+ Description: 'Whether to enable Point in Time Recovery on the table.',
1193
+ }),
1194
+ DynamoDBEnableServerSideEncryption: expect.objectContaining({
1195
+ Type: 'String',
1196
+ Default: 'true',
1197
+ AllowedValues: ['true', 'false'],
1198
+ Description: 'Enable server side encryption powered by KMS.',
1199
+ }),
1200
+ };
1201
+ const validSchema = `type Todo @model {
1202
+ name: String
1203
+ }`;
1204
+ const transformer = new GraphQLTransform({
1205
+ sandboxModeEnabled: true,
1206
+ transformers: [new ModelTransformer()],
1207
+ });
1208
+ const out = transformer.transform(validSchema);
1209
+
1210
+ const rootStack = out.rootStack;
1211
+ expect(rootStack).toBeDefined();
1212
+ expect(rootStack.Parameters).toMatchObject(modelParams);
1213
+
1214
+ const todoStack = out.stacks['Todo'];
1215
+ expect(todoStack).toBeDefined();
1216
+ expect(todoStack.Parameters).toMatchObject(modelParams);
1217
+ });
1218
+
1219
+ it('global auth enabled should add apiKey if not default mode of auth', () => {
1220
+ const validSchema = `
1221
+ type Post @model {
1222
+ id: ID!
1223
+ title: String!
1224
+ tags: [Tag]
1225
+ }
1226
+
1227
+ type Tag {
1228
+ id: ID
1229
+ tags: [Tag]
1230
+ }`;
1231
+ const transformer = new GraphQLTransform({
1232
+ authConfig: {
1233
+ defaultAuthentication: {
1234
+ authenticationType: 'AMAZON_COGNITO_USER_POOLS',
1235
+ },
1236
+ additionalAuthenticationProviders: [
1237
+ {
1238
+ authenticationType: 'API_KEY',
1239
+ },
1240
+ ],
1241
+ },
1242
+ sandboxModeEnabled: true,
1243
+ transformers: [new ModelTransformer()],
1244
+ });
1245
+ const out = transformer.transform(validSchema);
1246
+ expect(out).toBeDefined();
1247
+
1248
+ const schema = parse(out.schema);
1249
+ validateModelSchema(schema);
1250
+
1251
+ const postType = getObjectType(schema, 'Post')!;
1252
+ expect(postType).toBeDefined();
1253
+ expect(postType.directives).toBeDefined();
1254
+ expect(postType.directives!.some(dir => dir.name.value === 'aws_api_key')).toEqual(true);
1255
+
1256
+ const tagType = getObjectType(schema, 'Tag')!;
1257
+ expect(tagType).toBeDefined();
1258
+ expect(tagType.directives).toBeDefined();
1259
+ expect(tagType.directives!.some(dir => dir.name.value === 'aws_api_key')).toEqual(true);
1260
+
1261
+ // check operations
1262
+ const queryType = getObjectType(schema, 'Query')!;
1263
+ expect(queryType).toBeDefined();
1264
+ const mutationType = getObjectType(schema, 'Mutation')!;
1265
+ expect(mutationType).toBeDefined();
1266
+ const subscriptionType = getObjectType(schema, 'Subscription')!;
1267
+ expect(subscriptionType).toBeDefined();
1268
+
1269
+ for (const field of [...queryType.fields!, ...mutationType.fields!, ...subscriptionType.fields!]) {
1270
+ expect(field.directives!.some(dir => dir.name.value === 'aws_api_key')).toEqual(true);
1271
+ }
1272
+ });
1169
1273
  });
@@ -14,3 +14,5 @@ export const BOOLEAN_FUNCTIONS = new Set<string>(['attributeExists', 'attributeT
14
14
  export const ATTRIBUTE_TYPES = ['binary', 'binarySet', 'bool', 'list', 'map', 'number', 'numberSet', 'string', 'stringSet', '_null'];
15
15
 
16
16
  export const OPERATION_KEY = '__operation';
17
+
18
+ export const API_KEY_DIRECTIVE = 'aws_api_key';
@@ -5,6 +5,7 @@ import {
5
5
  SyncConfig,
6
6
  SyncUtils,
7
7
  TransformerModelBase,
8
+ TransformerNestedStack,
8
9
  } from '@aws-amplify/graphql-transformer-core';
9
10
  import {
10
11
  AppSyncDataSourceType,
@@ -20,6 +21,7 @@ import {
20
21
  TransformerSchemaVisitStepContextProvider,
21
22
  TransformerTransformSchemaStepContextProvider,
22
23
  TransformerValidationStepContextProvider,
24
+ TransformerBeforeStepContextProvider,
23
25
  } from '@aws-amplify/graphql-transformer-interfaces';
24
26
  import { AttributeType, CfnTable, ITable, StreamViewType, Table, TableEncryption } from '@aws-cdk/aws-dynamodb';
25
27
  import * as iam from '@aws-cdk/aws-iam';
@@ -51,8 +53,10 @@ import {
51
53
  toPascalCase,
52
54
  } from 'graphql-transformer-common';
53
55
  import {
56
+ addDirectivesToOperation,
54
57
  addModelConditionInputs,
55
58
  createEnumModelFilters,
59
+ extendTypeWithDirectives,
56
60
  makeCreateInputField,
57
61
  makeDeleteInputField,
58
62
  makeListQueryFilterInput,
@@ -60,6 +64,7 @@ import {
60
64
  makeModelSortDirectionEnumObject,
61
65
  makeMutationConditionInput,
62
66
  makeUpdateInputField,
67
+ propagateApiKeyToNestedTypes,
63
68
  } from './graphql-types';
64
69
  import {
65
70
  generateAuthExpressionForSandboxMode,
@@ -82,6 +87,7 @@ import {
82
87
  import { FieldWrapper, InputObjectDefinitionWrapper, ObjectDefinitionWrapper } from './wrappers/object-definition-wrapper';
83
88
  import { CfnRole } from '@aws-cdk/aws-iam';
84
89
  import md5 from 'md5';
90
+ import { API_KEY_DIRECTIVE } from './definitions';
85
91
 
86
92
  export type Nullable<T> = T | null;
87
93
  export type OptionalAndNullable<T> = Partial<T>;
@@ -167,6 +173,37 @@ export class ModelTransformer extends TransformerModelBase implements Transforme
167
173
  this.options = this.getOptions(options);
168
174
  }
169
175
 
176
+ before = (ctx: TransformerBeforeStepContextProvider) => {
177
+ // add model related-parameters to the root stack
178
+ ctx.stackManager.addParameter(ResourceConstants.PARAMETERS.DynamoDBModelTableReadIOPS, {
179
+ description: 'The number of read IOPS the table should support.',
180
+ type: 'Number',
181
+ default: 5,
182
+ });
183
+ ctx.stackManager.addParameter(ResourceConstants.PARAMETERS.DynamoDBModelTableWriteIOPS, {
184
+ description: 'The number of write IOPS the table should support.',
185
+ type: 'Number',
186
+ default: 5,
187
+ });
188
+ ctx.stackManager.addParameter(ResourceConstants.PARAMETERS.DynamoDBBillingMode, {
189
+ description: 'Configure @model types to create DynamoDB tables with PAY_PER_REQUEST or PROVISIONED billing modes.',
190
+ default: 'PAY_PER_REQUEST',
191
+ allowedValues: ['PAY_PER_REQUEST', 'PROVISIONED'],
192
+ });
193
+ ctx.stackManager.addParameter(ResourceConstants.PARAMETERS.DynamoDBEnablePointInTimeRecovery, {
194
+ description: 'Whether to enable Point in Time Recovery on the table.',
195
+ type: 'String',
196
+ default: 'false',
197
+ allowedValues: ['true', 'false'],
198
+ });
199
+ ctx.stackManager.addParameter(ResourceConstants.PARAMETERS.DynamoDBEnableServerSideEncryption, {
200
+ description: 'Enable server side encryption powered by KMS.',
201
+ type: 'String',
202
+ default: 'true',
203
+ allowedValues: ['true', 'false'],
204
+ });
205
+ };
206
+
170
207
  object = (definition: ObjectTypeDefinitionNode, directive: DirectiveNode, ctx: TransformerSchemaVisitStepContextProvider): void => {
171
208
  const isTypeNameReserved =
172
209
  definition.name.value === ctx.output.getQueryTypeName() ||
@@ -227,6 +264,7 @@ export class ModelTransformer extends TransformerModelBase implements Transforme
227
264
  this.ensureModelSortDirectionEnum(ctx);
228
265
  for (const type of this.typesWithModelDirective) {
229
266
  const def = ctx.output.getObject(type)!;
267
+ const hasAuth = def.directives!.some(dir => dir.name.value === 'auth');
230
268
 
231
269
  // add Non Model type inputs
232
270
  this.createNonModelInputs(ctx, def);
@@ -246,6 +284,24 @@ export class ModelTransformer extends TransformerModelBase implements Transforme
246
284
  if (ctx.isProjectUsingDataStore()) {
247
285
  this.addModelSyncFields(ctx, type);
248
286
  }
287
+ // global auth check
288
+ if (!hasAuth && ctx.sandboxModeEnabled && ctx.authConfig.defaultAuthentication.authenticationType !== 'API_KEY') {
289
+ const apiKeyDirArray = [makeDirective(API_KEY_DIRECTIVE, [])];
290
+ extendTypeWithDirectives(ctx, def.name.value, apiKeyDirArray);
291
+ propagateApiKeyToNestedTypes(ctx as TransformerContextProvider, def, new Set<string>());
292
+ for (let operationField of queryFields) {
293
+ const operationName = operationField.name.value;
294
+ addDirectivesToOperation(ctx, ctx.output.getQueryTypeName()!, operationName, apiKeyDirArray);
295
+ }
296
+ for (let operationField of mutationFields) {
297
+ const operationName = operationField.name.value;
298
+ addDirectivesToOperation(ctx, ctx.output.getMutationTypeName()!, operationName, apiKeyDirArray);
299
+ }
300
+ for (let operationField of subscriptionsFields) {
301
+ const operationName = operationField.name.value;
302
+ addDirectivesToOperation(ctx, ctx.output.getSubscriptionTypeName()!, operationName, apiKeyDirArray);
303
+ }
304
+ }
249
305
  }
250
306
  };
251
307
 
@@ -274,10 +330,12 @@ export class ModelTransformer extends TransformerModelBase implements Transforme
274
330
  default:
275
331
  throw new Error('Unknown query field type');
276
332
  }
333
+ // TODO: add mechanism to add an auth like rule to all non auth @models
334
+ // this way we can just depend on auth to add the check
277
335
  resolver.addToSlot(
278
336
  'postAuth',
279
337
  MappingTemplate.s3MappingTemplateFromString(
280
- generateAuthExpressionForSandboxMode(context),
338
+ generateAuthExpressionForSandboxMode(context.sandboxModeEnabled),
281
339
  `${query.typeName}.${query.fieldName}.{slotName}.{slotIndex}.req.vtl`,
282
340
  ),
283
341
  );
@@ -304,7 +362,7 @@ export class ModelTransformer extends TransformerModelBase implements Transforme
304
362
  resolver.addToSlot(
305
363
  'postAuth',
306
364
  MappingTemplate.s3MappingTemplateFromString(
307
- generateAuthExpressionForSandboxMode(context),
365
+ generateAuthExpressionForSandboxMode(context.sandboxModeEnabled),
308
366
  `${mutation.typeName}.${mutation.fieldName}.{slotName}.{slotIndex}.req.vtl`,
309
367
  ),
310
368
  );
@@ -352,7 +410,7 @@ export class ModelTransformer extends TransformerModelBase implements Transforme
352
410
  resolver.addToSlot(
353
411
  'postAuth',
354
412
  MappingTemplate.s3MappingTemplateFromString(
355
- generateAuthExpressionForSandboxMode(context),
413
+ generateAuthExpressionForSandboxMode(context.sandboxModeEnabled),
356
414
  `${subscription.typeName}.${subscription.fieldName}.{slotName}.{slotIndex}.req.vtl`,
357
415
  ),
358
416
  );
@@ -1085,30 +1143,42 @@ export class ModelTransformer extends TransformerModelBase implements Transforme
1085
1143
  description: 'The number of read IOPS the table should support.',
1086
1144
  type: 'Number',
1087
1145
  default: 5,
1088
- }).valueAsString;
1146
+ });
1089
1147
  const writeIops = new cdk.CfnParameter(stack, ResourceConstants.PARAMETERS.DynamoDBModelTableWriteIOPS, {
1090
1148
  description: 'The number of write IOPS the table should support.',
1091
1149
  type: 'Number',
1092
1150
  default: 5,
1093
- }).valueAsString;
1151
+ });
1094
1152
  const billingMode = new cdk.CfnParameter(stack, ResourceConstants.PARAMETERS.DynamoDBBillingMode, {
1095
1153
  description: 'Configure @model types to create DynamoDB tables with PAY_PER_REQUEST or PROVISIONED billing modes.',
1096
1154
  type: 'String',
1097
1155
  default: 'PAY_PER_REQUEST',
1098
1156
  allowedValues: ['PAY_PER_REQUEST', 'PROVISIONED'],
1099
- }).valueAsString;
1157
+ });
1100
1158
  const pointInTimeRecovery = new cdk.CfnParameter(stack, ResourceConstants.PARAMETERS.DynamoDBEnablePointInTimeRecovery, {
1101
1159
  description: 'Whether to enable Point in Time Recovery on the table.',
1102
1160
  type: 'String',
1103
1161
  default: 'false',
1104
1162
  allowedValues: ['true', 'false'],
1105
- }).valueAsString;
1163
+ });
1106
1164
  const enableSSE = new cdk.CfnParameter(stack, ResourceConstants.PARAMETERS.DynamoDBEnableServerSideEncryption, {
1107
1165
  description: 'Enable server side encryption powered by KMS.',
1108
1166
  type: 'String',
1109
1167
  default: 'true',
1110
1168
  allowedValues: ['true', 'false'],
1111
- }).valueAsString;
1169
+ });
1170
+ // add the connection between the root and nested stack so the values can be passed down
1171
+ (stack as TransformerNestedStack).setParameter(readIops.node.id, cdk.Fn.ref(ResourceConstants.PARAMETERS.DynamoDBModelTableReadIOPS));
1172
+ (stack as TransformerNestedStack).setParameter(writeIops.node.id, cdk.Fn.ref(ResourceConstants.PARAMETERS.DynamoDBModelTableWriteIOPS));
1173
+ (stack as TransformerNestedStack).setParameter(billingMode.node.id, cdk.Fn.ref(ResourceConstants.PARAMETERS.DynamoDBBillingMode));
1174
+ (stack as TransformerNestedStack).setParameter(
1175
+ pointInTimeRecovery.node.id,
1176
+ cdk.Fn.ref(ResourceConstants.PARAMETERS.DynamoDBEnablePointInTimeRecovery),
1177
+ );
1178
+ (stack as TransformerNestedStack).setParameter(
1179
+ enableSSE.node.id,
1180
+ cdk.Fn.ref(ResourceConstants.PARAMETERS.DynamoDBEnableServerSideEncryption),
1181
+ );
1112
1182
 
1113
1183
  // Add conditions.
1114
1184
  // eslint-disable-next-line no-new
@@ -1,14 +1,20 @@
1
- import { TransformerTransformSchemaStepContextProvider } from '@aws-amplify/graphql-transformer-interfaces';
1
+ import { TransformerContextProvider, TransformerTransformSchemaStepContextProvider } from '@aws-amplify/graphql-transformer-interfaces';
2
2
  import {
3
+ DirectiveNode,
3
4
  EnumTypeDefinitionNode,
4
5
  FieldDefinitionNode,
5
6
  InputObjectTypeDefinitionNode,
6
7
  Kind,
8
+ NamedTypeNode,
7
9
  ObjectTypeDefinitionNode,
8
10
  TypeDefinitionNode,
9
11
  } from 'graphql';
10
12
  import {
13
+ blankObjectExtension,
11
14
  DEFAULT_SCALARS,
15
+ extendFieldWithDirectives,
16
+ extensionWithDirectives,
17
+ getBaseType,
12
18
  makeArgument,
13
19
  makeDirective,
14
20
  makeField,
@@ -29,6 +35,7 @@ import {
29
35
  SIZE_CONDITIONS,
30
36
  STRING_CONDITIONS,
31
37
  STRING_FUNCTIONS,
38
+ API_KEY_DIRECTIVE,
32
39
  } from '../definitions';
33
40
  import {
34
41
  EnumWrapper,
@@ -245,7 +252,96 @@ export function makeEnumFilterInput(fieldWrapper: FieldWrapper): InputObjectType
245
252
  return input.serialize();
246
253
  }
247
254
 
255
+ export const addDirectivesToField = (
256
+ ctx: TransformerTransformSchemaStepContextProvider,
257
+ typeName: string,
258
+ fieldName: string,
259
+ directives: Array<DirectiveNode>,
260
+ ) => {
261
+ const type = ctx.output.getType(typeName) as ObjectTypeDefinitionNode;
262
+ if (type) {
263
+ const field = type.fields?.find(f => f.name.value === fieldName);
264
+ if (field) {
265
+ const newFields = [...type.fields!.filter(f => f.name.value !== field.name.value), extendFieldWithDirectives(field, directives)];
266
+
267
+ const newType = {
268
+ ...type,
269
+ fields: newFields,
270
+ };
271
+
272
+ ctx.output.putType(newType);
273
+ }
274
+ }
275
+ };
276
+
277
+ export const addDirectivesToOperation = (
278
+ ctx: TransformerTransformSchemaStepContextProvider,
279
+ typeName: string,
280
+ operationName: string,
281
+ directives: Array<DirectiveNode>,
282
+ ) => {
283
+ // add directives to the given operation
284
+ addDirectivesToField(ctx, typeName, operationName, directives);
285
+
286
+ // add the directives to the result type of the operation
287
+ const type = ctx.output.getType(typeName) as ObjectTypeDefinitionNode;
288
+ if (type) {
289
+ const field = type.fields!.find(f => f.name.value === operationName);
290
+
291
+ if (field) {
292
+ const returnFieldType = field.type as NamedTypeNode;
293
+
294
+ if (returnFieldType.name) {
295
+ const returnTypeName = returnFieldType.name.value;
296
+
297
+ extendTypeWithDirectives(ctx, returnTypeName, directives);
298
+ }
299
+ }
300
+ }
301
+ };
302
+
303
+ export const extendTypeWithDirectives = (
304
+ ctx: TransformerTransformSchemaStepContextProvider,
305
+ typeName: string,
306
+ directives: Array<DirectiveNode>,
307
+ ): void => {
308
+ let objectTypeExtension = blankObjectExtension(typeName);
309
+ objectTypeExtension = extensionWithDirectives(objectTypeExtension, directives);
310
+ ctx.output.addObjectExtension(objectTypeExtension);
311
+ };
312
+
248
313
  export function makeModelSortDirectionEnumObject(): EnumTypeDefinitionNode {
249
314
  const name = 'ModelSortDirection';
250
315
  return EnumWrapper.create(name, ['ASC', 'DESC']).serialize();
251
316
  }
317
+ // the smaller version of it's @auth equivalent since we only support
318
+ // apikey as the only global auth rule
319
+ export const propagateApiKeyToNestedTypes = (
320
+ ctx: TransformerContextProvider,
321
+ def: ObjectTypeDefinitionNode,
322
+ seenNonModelTypes: Set<string>,
323
+ ) => {
324
+ const nonModelTypePredicate = (fieldType: TypeDefinitionNode): TypeDefinitionNode | undefined => {
325
+ if (fieldType) {
326
+ if (fieldType.kind !== 'ObjectTypeDefinition') {
327
+ return undefined;
328
+ }
329
+ const typeModel = fieldType.directives!.find(dir => dir.name.value === 'model');
330
+ return typeModel !== undefined ? undefined : fieldType;
331
+ }
332
+ return fieldType;
333
+ };
334
+ const nonModelFieldTypes = def
335
+ .fields!.map(f => ctx.output.getType(getBaseType(f.type)) as TypeDefinitionNode)
336
+ .filter(nonModelTypePredicate);
337
+ for (const nonModelFieldType of nonModelFieldTypes) {
338
+ const nonModelName = nonModelFieldType.name.value;
339
+ const hasSeenType = seenNonModelTypes.has(nonModelName);
340
+ const hasApiKey = nonModelFieldType.directives?.some(dir => dir.name.value === API_KEY_DIRECTIVE) ?? false;
341
+ if (!hasSeenType && !hasApiKey) {
342
+ seenNonModelTypes.add(nonModelName);
343
+ extendTypeWithDirectives(ctx, nonModelName, [makeDirective(API_KEY_DIRECTIVE, [])]);
344
+ propagateApiKeyToNestedTypes(ctx, nonModelFieldType as ObjectTypeDefinitionNode, seenNonModelTypes);
345
+ }
346
+ }
347
+ };
@@ -96,10 +96,8 @@ export const generateResolverKey = (typeName: string, fieldName: string): string
96
96
 
97
97
  /**
98
98
  * Util function to generate sandbox mode expression
99
- * @param ctx context to get sandbox mode
100
99
  */
101
- export const generateAuthExpressionForSandboxMode = (ctx: any): string => {
102
- const enabled = ctx.resourceHelper.api.sandboxModeEnabled;
100
+ export const generateAuthExpressionForSandboxMode = (enabled: boolean): string => {
103
101
  let exp;
104
102
 
105
103
  if (enabled) exp = iff(notEquals(methodCall(ref('util.authType')), str(API_KEY)), methodCall(ref('util.unauthorized')));