Skip to content

Commit 78e7730

Browse files
committed
review comments 2
1 parent 01c2f46 commit 78e7730

File tree

21 files changed

+86
-77
lines changed

21 files changed

+86
-77
lines changed

packages/amplify-graphql-model-transformer/src/graphql-model-transformer.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ import {
5454
DirectiveWrapper,
5555
FieldWrapper,
5656
InputObjectDefinitionWrapper,
57-
ObjectDefinationWrapper,
57+
ObjectDefinitionWrapper,
5858
} from './wrappers/object-definition-wrapper';
5959

6060
export type Nullable<T> = T | null;
@@ -248,8 +248,8 @@ export class ModelTransformer extends TransformerModelBase implements Transforme
248248
const def = context.output.getObject(type);
249249
// add the table
250250
const tableLogicalName = `${def!.name.value}Table`;
251-
const tableName = context.resourceHelper.generateResourceName(def!.name.value);
252-
const stack = context.stackManager.getStackFor(tableLogicalName, def!.name.value);
251+
const stack = context.stackManager.getOrCreateStackFor(tableLogicalName, def!.name.value);
252+
const tableName = context.resourceHelper.generateResourceName(def!.name.value, stack);
253253
// Expose a way in context to allow proper resource naming
254254
const table = new Table(stack, tableLogicalName, {
255255
tableName,
@@ -261,7 +261,7 @@ export class ModelTransformer extends TransformerModelBase implements Transforme
261261
removalPolicy: RemovalPolicy.DESTROY,
262262
});
263263
// Expose a better API to select what stack this belongs to
264-
const dataSource = context.api.addDynamoDbDataSource(
264+
const dataSource = context.api.addDynamoDBDataSource(
265265
`${def!.name.value}DS`,
266266
table,
267267
{
@@ -794,7 +794,7 @@ export class ModelTransformer extends TransformerModelBase implements Transforme
794794
if (!typeObj) {
795795
throw new Error(`Type ${name} is missing in outputs`);
796796
}
797-
const typeWrapper = new ObjectDefinationWrapper(typeObj);
797+
const typeWrapper = new ObjectDefinitionWrapper(typeObj);
798798
if (!typeWrapper.hasField('id')) {
799799
const idField = FieldWrapper.create('id', 'ID');
800800
typeWrapper.addField(idField);

packages/amplify-graphql-model-transformer/src/graphql-types/common.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,22 @@ import {
3333
EnumWrapper,
3434
InputFieldWraper,
3535
InputObjectDefinitionWrapper,
36-
ObjectDefinationWrapper
36+
ObjectDefinitionWrapper
3737
} from '../wrappers/object-definition-wrapper';
3838

3939
/**
4040
* Creates the condition/filter input for a model
4141
* @param ctx TransformerContext
4242
* @param name model name
43-
* @param object ModelObjectDefination
43+
* @param object ModelObjectDefinition
4444
*/
4545
export const makeConditionFilterInput = (
4646
ctx: TranformerTransformSchemaStepContextProvider,
4747
name: string,
4848
object: ObjectTypeDefinitionNode,
4949
): InputObjectDefinitionWrapper => {
5050
const input = InputObjectDefinitionWrapper.create(name);
51-
const wrappedObject = new ObjectDefinationWrapper(object);
51+
const wrappedObject = new ObjectDefinitionWrapper(object);
5252
for (let field of wrappedObject.fields) {
5353
const fieldType = ctx.output.getType(field.getTypeName());
5454
const isEnumType = fieldType && fieldType.kind === 'EnumTypeDefinition';
@@ -105,7 +105,7 @@ export const createEnumModelFilters = (
105105
type: ObjectTypeDefinitionNode,
106106
): InputObjectTypeDefinitionNode[] => {
107107
// add enum type if present
108-
const typeWrapper = new ObjectDefinationWrapper(type);
108+
const typeWrapper = new ObjectDefinitionWrapper(type);
109109
const enumFields = typeWrapper.fields.filter(field => {
110110
const typeName = field.getTypeName();
111111
const typeObj = ctx.output.getType(typeName);

packages/amplify-graphql-model-transformer/src/graphql-types/mutation.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { TranformerTransformSchemaStepContextProvider } from '@aws-amplify/graph
22
import { ObjectTypeDefinitionNode, InputObjectTypeDefinitionNode } from 'graphql';
33
import { toPascalCase } from 'graphql-transformer-common';
44
import { ModelDirectiveConfiguration } from '../graphql-model-transformer';
5-
import { ObjectDefinationWrapper, InputObjectDefinitionWrapper, InputFieldWraper } from '../wrappers/object-definition-wrapper';
5+
import { ObjectDefinitionWrapper, InputObjectDefinitionWrapper, InputFieldWraper } from '../wrappers/object-definition-wrapper';
66
import { makeConditionFilterInput } from './common';
77

88
/**
@@ -17,7 +17,7 @@ export const makeUpdateInputField = (
1717
knownModelTypes: Set<string>,
1818
): InputObjectTypeDefinitionNode => {
1919
// sync related things
20-
const objectWrapped = new ObjectDefinationWrapper(obj);
20+
const objectWrapped = new ObjectDefinitionWrapper(obj);
2121
const typeName = objectWrapped.name;
2222
const name = toPascalCase([`Update`, typeName, 'Input']);
2323
const hasIdField = objectWrapped.hasField('id');
@@ -51,9 +51,9 @@ export const makeUpdateInputField = (
5151
}
5252

5353
// Make createdAt and updatedAt field Optionals if present
54-
for (let timeStampFieldName of Object.values(modelDirectiveConfig?.timestamps || {})) {
55-
if (input.hasField(timeStampFieldName!)) {
56-
const timestampField = input.getField(timeStampFieldName!);
54+
for (let timestampFieldName of Object.values(modelDirectiveConfig?.timestamps || {})) {
55+
if (input.hasField(timestampFieldName!)) {
56+
const timestampField = input.getField(timestampFieldName!);
5757
if (['String', 'AWSDateTime'].includes(timestampField.getTypeName())) {
5858
timestampField.makeNullable();
5959
}
@@ -86,7 +86,7 @@ export const makeCreateInputField = (
8686
knownModelTypes: Set<string>,
8787
): InputObjectTypeDefinitionNode => {
8888
// sync related things
89-
const objectWrapped = new ObjectDefinationWrapper(obj);
89+
const objectWrapped = new ObjectDefinitionWrapper(obj);
9090
const typeName = objectWrapped.name;
9191
const name = toPascalCase([`Create`, typeName, 'Input']);
9292
const hasIdField = objectWrapped.hasField('id');

packages/amplify-graphql-model-transformer/src/graphql-types/query.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { TranformerTransformSchemaStepContextProvider } from '@aws-amplify/graphql-transformer-interfaces';
22
import { InputObjectTypeDefinitionNode, ObjectTypeDefinitionNode } from 'graphql';
3-
import { FieldWrapper, ObjectDefinationWrapper } from '../wrappers/object-definition-wrapper';
3+
import { FieldWrapper, ObjectDefinitionWrapper } from '../wrappers/object-definition-wrapper';
44
import { makeConditionFilterInput } from './common';
55
export const makeListQueryFilterInput = (
66
ctx: TranformerTransformSchemaStepContextProvider,
@@ -11,7 +11,7 @@ export const makeListQueryFilterInput = (
1111
};
1212

1313
export const makeListQueryModel = (type: ObjectTypeDefinitionNode, modelName: string): ObjectTypeDefinitionNode => {
14-
const outputType = ObjectDefinationWrapper.create(modelName);
14+
const outputType = ObjectDefinitionWrapper.create(modelName);
1515

1616
outputType.addField(FieldWrapper.create('items', type.name.value, true, true));
1717
outputType.addField(FieldWrapper.create('nextToken', 'String', true, false));

packages/amplify-graphql-model-transformer/src/resolvers/common.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
toJson,
1818
} from 'graphql-mapping-template';
1919

20+
export const APPSYNC_RESOLVER_VERSION = '2018-05-29';
2021
/**
2122
* Helper method to genrate code that converts DynamoDB condition object to condtion
2223
* expression

packages/amplify-graphql-model-transformer/src/resolvers/mutation.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
printBlock,
2020
} from 'graphql-mapping-template';
2121
import { ModelDirectiveConfiguration } from '../graphql-model-transformer';
22-
import { generateConditionSlot } from './common';
22+
import { APPSYNC_RESOLVER_VERSION, generateConditionSlot } from './common';
2323

2424
/**
2525
* Generates VTL template in update mutation
@@ -121,7 +121,7 @@ export const generateUpdateRequestTemplate = (modelName: string): string => {
121121
set(
122122
ref('UpdateItem'),
123123
obj({
124-
version: str('2018-05-29'),
124+
version: str(APPSYNC_RESOLVER_VERSION),
125125
operation: str('UpdateItem'),
126126
key: ref('Key'),
127127
update: ref('update'),
@@ -165,7 +165,7 @@ export const generateCreateRequestTemplate = (modelName: string): string => {
165165
set(
166166
ref('PutObject'),
167167
obj({
168-
version: str('2018-05-29'),
168+
version: str(APPSYNC_RESOLVER_VERSION),
169169
operation: str('PutItem'),
170170
attributeValues: methodCall(ref('util.dynamodb.toMapValues'), ref('mergedValues')),
171171
condition: ref('condition'),
@@ -240,7 +240,7 @@ export const generateCreateInitSlotTemplate = (name: string, modelConfig: ModelD
240240
statements.push(
241241
toJson(
242242
obj({
243-
version: str('2018-05-29'),
243+
version: str(APPSYNC_RESOLVER_VERSION),
244244
payload: obj({}),
245245
}),
246246
),
@@ -256,7 +256,7 @@ export const generateDeleteRequestTemplate = (): string => {
256256
set(
257257
ref('DeleteRequest'),
258258
obj({
259-
version: str('2018-05-29'),
259+
version: str(APPSYNC_RESOLVER_VERSION),
260260
operation: str('DeleteItem'),
261261
}),
262262
),
@@ -314,7 +314,7 @@ export const generateUpdateInitSlotTemplate = (modelName: string, modelConfig: M
314314
statements.push(
315315
toJson(
316316
obj({
317-
version: str('2018-05-29'),
317+
version: str(APPSYNC_RESOLVER_VERSION),
318318
payload: obj({}),
319319
}),
320320
),

packages/amplify-graphql-model-transformer/src/resolvers/query.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ import {
1717
bool,
1818
and,
1919
} from 'graphql-mapping-template';
20+
import { APPSYNC_RESOLVER_VERSION } from './common';
2021

2122
/**
2223
* Generate get query resolver template
2324
*/
2425
export const generateGetRequestTemplate = (): string => {
2526
const statements: Expression[] = [
26-
set(ref('GetRequest'), obj({ version: str('2018-05-29'), operation: str('GetItem') })),
27+
set(ref('GetRequest'), obj({ version: str(APPSYNC_RESOLVER_VERSION), operation: str('GetItem') })),
2728
ifElse(
2829
ref('ctx.stash.metadata.modelKeyObject'),
2930
set(ref('Key'), ref('ctx.stash.metadata.modelKeyObject')),
@@ -45,7 +46,7 @@ export const generateListRequestTemplate = (): string => {
4546
set(
4647
ref(requestVariable),
4748
obj({
48-
version: str('2018-05-29'),
49+
version: str(APPSYNC_RESOLVER_VERSION),
4950
limit: ref('limit'),
5051
}),
5152
),

packages/amplify-graphql-model-transformer/src/resolvers/subscriptions.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { compoundExpression, Expression, obj, printBlock, str, toJson, nul } from 'graphql-mapping-template';
2+
import { APPSYNC_RESOLVER_VERSION } from './common';
23

34
export const generateSubscriptionRequestTemplate = (): string => {
4-
const statements: Expression[] = [toJson(obj({ version: str('2018-05-29'), payload: obj({}) }))];
5+
const statements: Expression[] = [toJson(obj({ version: str(APPSYNC_RESOLVER_VERSION), payload: obj({}) }))];
56
return printBlock('Subscription Request template')(compoundExpression(statements));
67
};
78

packages/amplify-graphql-model-transformer/src/wrappers/object-definition-wrapper.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ export class FieldWrapper extends GenericFieldWrapper {
259259
};
260260
}
261261

262-
export class ObjectDefinationWrapper {
262+
export class ObjectDefinitionWrapper {
263263
public readonly directives?: DirectiveWrapper[];
264264
public readonly fields: FieldWrapper[];
265265
public readonly name: string;
@@ -310,8 +310,8 @@ export class ObjectDefinationWrapper {
310310
this.fields.splice(index, 1);
311311
};
312312

313-
static create = (name: string, fields: FieldDefinitionNode[] = [], directives: DirectiveNode[] = []): ObjectDefinationWrapper => {
314-
return new ObjectDefinationWrapper({
313+
static create = (name: string, fields: FieldDefinitionNode[] = [], directives: DirectiveNode[] = []): ObjectDefinitionWrapper => {
314+
return new ObjectDefinitionWrapper({
315315
kind: 'ObjectTypeDefinition',
316316
name: {
317317
kind: 'Name',

packages/amplify-graphql-transformer-core/src/graphql-api.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,19 @@ export interface GraphqlApiProps {
6464
readonly xrayEnabled?: boolean;
6565
}
6666

67-
export class IamResource implements APIIAMResourceProvider {
67+
export class IAMResource implements APIIAMResourceProvider {
6868
/**
6969
* Generate the resource names given custom arns
7070
*
7171
* @param arns The custom arns that need to be permissioned
7272
*
7373
* Example: custom('/types/Query/fields/getExample')
7474
*/
75-
public static custom(...arns: string[]): IamResource {
75+
public static custom(...arns: string[]): IAMResource {
7676
if (arns.length === 0) {
7777
throw new Error('At least 1 custom ARN must be provided.');
7878
}
79-
return new IamResource(arns);
79+
return new IAMResource(arns);
8080
}
8181

8282
/**
@@ -87,16 +87,16 @@ export class IamResource implements APIIAMResourceProvider {
8787
*
8888
* Example: ofType('Query', 'GetExample')
8989
*/
90-
public static ofType(type: string, ...fields: string[]): IamResource {
90+
public static ofType(type: string, ...fields: string[]): IAMResource {
9191
const arns = fields.length ? fields.map(field => `types/${type}/fields/${field}`) : [`types/${type}/*`];
92-
return new IamResource(arns);
92+
return new IAMResource(arns);
9393
}
9494

9595
/**
9696
* Generate the resource names that accepts all types: `*`
9797
*/
98-
public static all(): IamResource {
99-
return new IamResource(['*']);
98+
public static all(): IAMResource {
99+
return new IAMResource(['*']);
100100
}
101101

102102
private arns: string[];
@@ -224,11 +224,11 @@ export class GraphQLApi extends GraphqlApiBase implements GraphQLAPIProvider {
224224
return dataSource;
225225
}
226226

227-
public addDynamoDbDataSource(name: string, table: ITable, options?: DataSourceOptions, stack?: Stack): DynamoDbDataSource {
227+
public addDynamoDBDataSource(name: string, table: ITable, options?: DataSourceOptions, stack?: Stack): DynamoDbDataSource {
228228
if (this.dataSources.has(name)) {
229229
throw new Error(`DataSource ${name} already exists in the API`);
230230
}
231-
const dataSource = this.doAddDynamoDbDataSource(name, table, options, stack);
231+
const dataSource = this.doAddDynamoDBDataSource(name, table, options, stack);
232232
this.dataSources.set(options?.name || name, dataSource);
233233
return dataSource;
234234
}
@@ -279,7 +279,7 @@ export class GraphQLApi extends GraphqlApiBase implements GraphQLAPIProvider {
279279
* @param resources The set of resources to allow (i.e. ...:[region]:[accountId]:apis/GraphQLId/...)
280280
* @param actions The actions that should be granted to the principal (i.e. appsync:graphql )
281281
*/
282-
public grant(grantee: IGrantable, resources: IamResource, ...actions: string[]): Grant {
282+
public grant(grantee: IGrantable, resources: IAMResource, ...actions: string[]): Grant {
283283
return Grant.addToPrincipal({
284284
grantee,
285285
actions,
@@ -289,11 +289,11 @@ export class GraphQLApi extends GraphqlApiBase implements GraphQLAPIProvider {
289289
}
290290

291291
public grantQuery(grantee: IGrantable, ...fields: string[]): Grant {
292-
return this.grant(grantee, IamResource.ofType('Query', ...fields), 'appsync:GraphQL');
292+
return this.grant(grantee, IAMResource.ofType('Query', ...fields), 'appsync:GraphQL');
293293
}
294294

295295
public grantMutation(grantee: IGrantable, ...fields: string[]): Grant {
296-
return this.grant(grantee, IamResource.ofType('Mutation', ...fields), 'appsync:GraphQL');
296+
return this.grant(grantee, IAMResource.ofType('Mutation', ...fields), 'appsync:GraphQL');
297297
}
298298

299299
/**
@@ -304,7 +304,7 @@ export class GraphQLApi extends GraphqlApiBase implements GraphQLAPIProvider {
304304
* @param fields The fields to grant access to that are Subscriptions (leave blank for all)
305305
*/
306306
public grantSubscription(grantee: IGrantable, ...fields: string[]): Grant {
307-
return this.grant(grantee, IamResource.ofType('Subscription', ...fields), 'appsync:GraphQL');
307+
return this.grant(grantee, IAMResource.ofType('Subscription', ...fields), 'appsync:GraphQL');
308308
}
309309

310310
public createAPIKey(config?: ApiKeyConfig) {
@@ -415,7 +415,7 @@ export class GraphQLApi extends GraphqlApiBase implements GraphQLAPIProvider {
415415
* @param options The optional configuration for this data source
416416
* @param stack Stack to which this datasource needs to mapped to
417417
*/
418-
protected doAddDynamoDbDataSource(id: string, table: ITable, options?: DataSourceOptions, stack?: Stack): DynamoDbDataSource {
418+
protected doAddDynamoDBDataSource(id: string, table: ITable, options?: DataSourceOptions, stack?: Stack): DynamoDbDataSource {
419419
return new DynamoDbDataSource(stack ?? this, id, {
420420
api: this,
421421
table,

0 commit comments

Comments
 (0)