@aws-amplify/graphql-model-transformer 0.7.1-graphql-vnext-dev-preview.11 → 0.9.1
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.
- package/CHANGELOG.md +2 -138
- package/lib/definitions.d.ts +0 -1
- package/lib/definitions.d.ts.map +1 -1
- package/lib/definitions.js +1 -2
- package/lib/definitions.js.map +1 -1
- package/lib/graphql-model-transformer.d.ts +1 -2
- package/lib/graphql-model-transformer.d.ts.map +1 -1
- package/lib/graphql-model-transformer.js +8 -61
- package/lib/graphql-model-transformer.js.map +1 -1
- package/lib/graphql-types/common.d.ts +2 -6
- package/lib/graphql-types/common.d.ts.map +1 -1
- package/lib/graphql-types/common.js +1 -65
- package/lib/graphql-types/common.js.map +1 -1
- package/lib/resolvers/common.d.ts +1 -1
- package/lib/resolvers/common.d.ts.map +1 -1
- package/lib/resolvers/common.js +2 -1
- package/lib/resolvers/common.js.map +1 -1
- package/package.json +6 -6
- package/src/__tests__/__snapshots__/model-transformer.test.ts.snap +3 -3
- package/src/__tests__/model-transformer.test.ts +15 -119
- package/src/definitions.ts +0 -2
- package/src/graphql-model-transformer.ts +8 -78
- package/src/graphql-types/common.ts +1 -97
- package/src/resolvers/common.ts +3 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.makeModelSortDirectionEnumObject = exports.makeEnumFilterInput = exports.makeSizeInputType = exports.makeSubscriptionField = exports.makeAttributeTypeEnum = exports.makeModelScalarFilterInputObject = exports.createEnumModelFilters = exports.generateModelScalarFilterInputName = exports.addModelConditionInputs = exports.makeConditionFilterInput = void 0;
|
|
4
4
|
const graphql_1 = require("graphql");
|
|
5
5
|
const graphql_transformer_common_1 = require("graphql-transformer-common");
|
|
6
6
|
const definitions_1 = require("../definitions");
|
|
@@ -172,73 +172,9 @@ function makeEnumFilterInput(fieldWrapper) {
|
|
|
172
172
|
return input.serialize();
|
|
173
173
|
}
|
|
174
174
|
exports.makeEnumFilterInput = makeEnumFilterInput;
|
|
175
|
-
const addDirectivesToField = (ctx, typeName, fieldName, directives) => {
|
|
176
|
-
var _a;
|
|
177
|
-
const type = ctx.output.getType(typeName);
|
|
178
|
-
if (type) {
|
|
179
|
-
const field = (_a = type.fields) === null || _a === void 0 ? void 0 : _a.find(f => f.name.value === fieldName);
|
|
180
|
-
if (field) {
|
|
181
|
-
const newFields = [...type.fields.filter(f => f.name.value !== field.name.value), graphql_transformer_common_1.extendFieldWithDirectives(field, directives)];
|
|
182
|
-
const newType = {
|
|
183
|
-
...type,
|
|
184
|
-
fields: newFields,
|
|
185
|
-
};
|
|
186
|
-
ctx.output.putType(newType);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
};
|
|
190
|
-
exports.addDirectivesToField = addDirectivesToField;
|
|
191
|
-
const addDirectivesToOperation = (ctx, typeName, operationName, directives) => {
|
|
192
|
-
exports.addDirectivesToField(ctx, typeName, operationName, directives);
|
|
193
|
-
const type = ctx.output.getType(typeName);
|
|
194
|
-
if (type) {
|
|
195
|
-
const field = type.fields.find(f => f.name.value === operationName);
|
|
196
|
-
if (field) {
|
|
197
|
-
const returnFieldType = field.type;
|
|
198
|
-
if (returnFieldType.name) {
|
|
199
|
-
const returnTypeName = returnFieldType.name.value;
|
|
200
|
-
exports.extendTypeWithDirectives(ctx, returnTypeName, directives);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
};
|
|
205
|
-
exports.addDirectivesToOperation = addDirectivesToOperation;
|
|
206
|
-
const extendTypeWithDirectives = (ctx, typeName, directives) => {
|
|
207
|
-
let objectTypeExtension = graphql_transformer_common_1.blankObjectExtension(typeName);
|
|
208
|
-
objectTypeExtension = graphql_transformer_common_1.extensionWithDirectives(objectTypeExtension, directives);
|
|
209
|
-
ctx.output.addObjectExtension(objectTypeExtension);
|
|
210
|
-
};
|
|
211
|
-
exports.extendTypeWithDirectives = extendTypeWithDirectives;
|
|
212
175
|
function makeModelSortDirectionEnumObject() {
|
|
213
176
|
const name = 'ModelSortDirection';
|
|
214
177
|
return object_definition_wrapper_1.EnumWrapper.create(name, ['ASC', 'DESC']).serialize();
|
|
215
178
|
}
|
|
216
179
|
exports.makeModelSortDirectionEnumObject = makeModelSortDirectionEnumObject;
|
|
217
|
-
const propagateApiKeyToNestedTypes = (ctx, def, seenNonModelTypes) => {
|
|
218
|
-
var _a, _b;
|
|
219
|
-
const nonModelTypePredicate = (fieldType) => {
|
|
220
|
-
if (fieldType) {
|
|
221
|
-
if (fieldType.kind !== 'ObjectTypeDefinition') {
|
|
222
|
-
return undefined;
|
|
223
|
-
}
|
|
224
|
-
const typeModel = fieldType.directives.find(dir => dir.name.value === 'model');
|
|
225
|
-
return typeModel !== undefined ? undefined : fieldType;
|
|
226
|
-
}
|
|
227
|
-
return fieldType;
|
|
228
|
-
};
|
|
229
|
-
const nonModelFieldTypes = def
|
|
230
|
-
.fields.map(f => ctx.output.getType(graphql_transformer_common_1.getBaseType(f.type)))
|
|
231
|
-
.filter(nonModelTypePredicate);
|
|
232
|
-
for (const nonModelFieldType of nonModelFieldTypes) {
|
|
233
|
-
const nonModelName = nonModelFieldType.name.value;
|
|
234
|
-
const hasSeenType = seenNonModelTypes.has(nonModelName);
|
|
235
|
-
const hasApiKey = (_b = (_a = nonModelFieldType.directives) === null || _a === void 0 ? void 0 : _a.some(dir => dir.name.value === definitions_1.API_KEY_DIRECTIVE)) !== null && _b !== void 0 ? _b : false;
|
|
236
|
-
if (!hasSeenType && !hasApiKey) {
|
|
237
|
-
seenNonModelTypes.add(nonModelName);
|
|
238
|
-
exports.extendTypeWithDirectives(ctx, nonModelName, [graphql_transformer_common_1.makeDirective(definitions_1.API_KEY_DIRECTIVE, [])]);
|
|
239
|
-
exports.propagateApiKeyToNestedTypes(ctx, nonModelFieldType, seenNonModelTypes);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
};
|
|
243
|
-
exports.propagateApiKeyToNestedTypes = propagateApiKeyToNestedTypes;
|
|
244
180
|
//# sourceMappingURL=common.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../src/graphql-types/common.ts"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../src/graphql-types/common.ts"],"names":[],"mappings":";;;AACA,qCAOiB;AACjB,2EAQoC;AACpC,gDAawB;AACxB,qFAM+C;AAQxC,MAAM,wBAAwB,GAAG,CACtC,GAAkD,EAClD,IAAY,EACZ,MAAgC,EACF,EAAE;IAChC,MAAM,kBAAkB,GAAG,IAAI,CAAC;IAChC,MAAM,KAAK,GAAG,wDAA4B,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACxD,MAAM,aAAa,GAAG,IAAI,mDAAuB,CAAC,MAAM,CAAC,CAAC;IAC1D,KAAK,IAAI,KAAK,IAAI,aAAa,CAAC,MAAM,EAAE;QACtC,MAAM,SAAS,GAAG,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC;QAC1D,MAAM,UAAU,GAAG,SAAS,IAAI,SAAS,CAAC,IAAI,KAAK,cAAI,CAAC,oBAAoB,CAAC;QAC7E,IAAI,KAAK,CAAC,QAAQ,EAAE,IAAI,UAAU,EAAE;YAClC,MAAM,iBAAiB,GACrB,UAAU,IAAI,KAAK,CAAC,MAAM,EAAE;gBAC1B,CAAC,CAAC,6CAAgB,CAAC,4BAA4B,CAAC,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC,kBAAkB,CAAC;gBACzF,CAAC,CAAC,6CAAgB,CAAC,8BAA8B,CAAC,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC,kBAAkB,CAAC,CAAC;YAChG,MAAM,UAAU,GAAG,6CAAiB,CAAC,MAAM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CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE;YAC9C,MAAM,KAAK,GAAG,6CAAiB,CAAC,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,WAAW,EAAE,EAAE,IAAI,CAAC,CAAC;YACpF,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QACxB,CAAC,CAAC,CAAC;KACJ;IACD,OAAO,KAAK,CAAC,SAAS,EAAE,CAAC;AAC3B,CAAC;AAnBD,kDAmBC;AAED,SAAgB,gCAAgC;IAC9C,MAAM,IAAI,GAAG,oBAAoB,CAAC;IAClC,OAAO,uCAAW,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;AAC/D,CAAC;AAHD,4EAGC"}
|
|
@@ -2,5 +2,5 @@ import { CompoundExpressionNode } from 'graphql-mapping-template';
|
|
|
2
2
|
export declare const generateConditionSlot: (inputConditionObjectName: string, conditionOutputVariableName: string) => CompoundExpressionNode;
|
|
3
3
|
export declare const generateDefaultResponseMappingTemplate: (isSyncEnabled: boolean, mutation?: boolean) => string;
|
|
4
4
|
export declare const generateResolverKey: (typeName: string, fieldName: string) => string;
|
|
5
|
-
export declare const generateAuthExpressionForSandboxMode: (
|
|
5
|
+
export declare const generateAuthExpressionForSandboxMode: (ctx: any) => string;
|
|
6
6
|
//# sourceMappingURL=common.d.ts.map
|
|
@@ -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;
|
|
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"}
|
package/lib/resolvers/common.js
CHANGED
|
@@ -40,7 +40,8 @@ const generateResolverKey = (typeName, fieldName) => {
|
|
|
40
40
|
return `${typeName}.${fieldName}`;
|
|
41
41
|
};
|
|
42
42
|
exports.generateResolverKey = generateResolverKey;
|
|
43
|
-
const generateAuthExpressionForSandboxMode = (
|
|
43
|
+
const generateAuthExpressionForSandboxMode = (ctx) => {
|
|
44
|
+
const enabled = ctx.resourceHelper.api.sandboxModeEnabled;
|
|
44
45
|
let exp;
|
|
45
46
|
if (enabled)
|
|
46
47
|
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,8B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AAc,CAAC,GAAG,CAAC,kBAAkB,CAAC;IAC1D,IAAI,GAAG,CAAC;IAER,IAAI,OAAO;QAAE,GAAG,GAAG,8BAAG,CAAC,oCAAS,CAAC,qCAAU,CAAC,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;AAVW,QAAA,oCAAoC,wCAU/C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-amplify/graphql-model-transformer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.1",
|
|
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.
|
|
32
|
-
"@aws-amplify/graphql-transformer-interfaces": "1.
|
|
31
|
+
"@aws-amplify/graphql-transformer-core": "0.12.1",
|
|
32
|
+
"@aws-amplify/graphql-transformer-interfaces": "1.12.1",
|
|
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.
|
|
61
|
-
"graphql-transformer-common": "4.
|
|
60
|
+
"graphql-mapping-template": "4.20.1",
|
|
61
|
+
"graphql-transformer-common": "4.22.1",
|
|
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": "
|
|
86
|
+
"gitHead": "644886fa3d1a047e8b37995e3ad5ba4c3bee28b1"
|
|
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
|
|
13306
|
+
exports[`ModelTransformer: should support timestamp parameters when generating pipelineFunctions 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
|
|
13460
|
+
exports[`ModelTransformer: should support timestamp parameters when generating pipelineFunctions 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
|
|
13528
|
+
exports[`ModelTransformer: should support timestamp parameters when generating pipelineFunctions 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.
|
|
414
|
+
expect(result.pipelineFunctions['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
|
|
673
|
+
it('should support timestamp parameters when generating pipelineFunctions 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.
|
|
692
|
-
expect(result.
|
|
691
|
+
expect(result.pipelineFunctions['Mutation.createPost.req.vtl']).toMatchSnapshot();
|
|
692
|
+
expect(result.pipelineFunctions['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.
|
|
716
|
-
expect(result.
|
|
715
|
+
expect(result.pipelineFunctions['Mutation.createPost.req.vtl']).toMatchSnapshot();
|
|
716
|
+
expect(result.pipelineFunctions['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.
|
|
741
|
-
expect(result.
|
|
740
|
+
expect(result.pipelineFunctions['Mutation.createPost.req.vtl']).toMatchSnapshot();
|
|
741
|
+
expect(result.pipelineFunctions['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.
|
|
763
|
-
expect(result.
|
|
762
|
+
expect(result.pipelineFunctions['Mutation.createPost.req.vtl']).toMatchSnapshot();
|
|
763
|
+
expect(result.pipelineFunctions['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.
|
|
911
|
+
expect(out.pipelineFunctions).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.
|
|
948
|
+
expect(out.pipelineFunctions).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.
|
|
982
|
+
expect(out.pipelineFunctions).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.
|
|
1119
|
-
expect(out.
|
|
1118
|
+
expect(out.pipelineFunctions['Query.syncTodos.req.vtl']).toMatchSnapshot();
|
|
1119
|
+
expect(out.pipelineFunctions['Query.syncTodos.res.vtl']).toMatchSnapshot();
|
|
1120
1120
|
// ds table
|
|
1121
1121
|
cdkExpect(out.rootStack).to(
|
|
1122
1122
|
haveResource('AWS::DynamoDB::Table', {
|
|
@@ -1166,108 +1166,4 @@ 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
|
-
});
|
|
1273
1169
|
});
|
package/src/definitions.ts
CHANGED
|
@@ -14,5 +14,3 @@ 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,7 +5,6 @@ import {
|
|
|
5
5
|
SyncConfig,
|
|
6
6
|
SyncUtils,
|
|
7
7
|
TransformerModelBase,
|
|
8
|
-
TransformerNestedStack,
|
|
9
8
|
} from '@aws-amplify/graphql-transformer-core';
|
|
10
9
|
import {
|
|
11
10
|
AppSyncDataSourceType,
|
|
@@ -21,7 +20,6 @@ import {
|
|
|
21
20
|
TransformerSchemaVisitStepContextProvider,
|
|
22
21
|
TransformerTransformSchemaStepContextProvider,
|
|
23
22
|
TransformerValidationStepContextProvider,
|
|
24
|
-
TransformerBeforeStepContextProvider,
|
|
25
23
|
} from '@aws-amplify/graphql-transformer-interfaces';
|
|
26
24
|
import { AttributeType, CfnTable, ITable, StreamViewType, Table, TableEncryption } from '@aws-cdk/aws-dynamodb';
|
|
27
25
|
import * as iam from '@aws-cdk/aws-iam';
|
|
@@ -53,10 +51,8 @@ import {
|
|
|
53
51
|
toPascalCase,
|
|
54
52
|
} from 'graphql-transformer-common';
|
|
55
53
|
import {
|
|
56
|
-
addDirectivesToOperation,
|
|
57
54
|
addModelConditionInputs,
|
|
58
55
|
createEnumModelFilters,
|
|
59
|
-
extendTypeWithDirectives,
|
|
60
56
|
makeCreateInputField,
|
|
61
57
|
makeDeleteInputField,
|
|
62
58
|
makeListQueryFilterInput,
|
|
@@ -64,7 +60,6 @@ import {
|
|
|
64
60
|
makeModelSortDirectionEnumObject,
|
|
65
61
|
makeMutationConditionInput,
|
|
66
62
|
makeUpdateInputField,
|
|
67
|
-
propagateApiKeyToNestedTypes,
|
|
68
63
|
} from './graphql-types';
|
|
69
64
|
import {
|
|
70
65
|
generateAuthExpressionForSandboxMode,
|
|
@@ -87,7 +82,6 @@ import {
|
|
|
87
82
|
import { FieldWrapper, InputObjectDefinitionWrapper, ObjectDefinitionWrapper } from './wrappers/object-definition-wrapper';
|
|
88
83
|
import { CfnRole } from '@aws-cdk/aws-iam';
|
|
89
84
|
import md5 from 'md5';
|
|
90
|
-
import { API_KEY_DIRECTIVE } from './definitions';
|
|
91
85
|
|
|
92
86
|
export type Nullable<T> = T | null;
|
|
93
87
|
export type OptionalAndNullable<T> = Partial<T>;
|
|
@@ -173,37 +167,6 @@ export class ModelTransformer extends TransformerModelBase implements Transforme
|
|
|
173
167
|
this.options = this.getOptions(options);
|
|
174
168
|
}
|
|
175
169
|
|
|
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
|
-
|
|
207
170
|
object = (definition: ObjectTypeDefinitionNode, directive: DirectiveNode, ctx: TransformerSchemaVisitStepContextProvider): void => {
|
|
208
171
|
const isTypeNameReserved =
|
|
209
172
|
definition.name.value === ctx.output.getQueryTypeName() ||
|
|
@@ -264,7 +227,6 @@ export class ModelTransformer extends TransformerModelBase implements Transforme
|
|
|
264
227
|
this.ensureModelSortDirectionEnum(ctx);
|
|
265
228
|
for (const type of this.typesWithModelDirective) {
|
|
266
229
|
const def = ctx.output.getObject(type)!;
|
|
267
|
-
const hasAuth = def.directives!.some(dir => dir.name.value === 'auth');
|
|
268
230
|
|
|
269
231
|
// add Non Model type inputs
|
|
270
232
|
this.createNonModelInputs(ctx, def);
|
|
@@ -284,24 +246,6 @@ export class ModelTransformer extends TransformerModelBase implements Transforme
|
|
|
284
246
|
if (ctx.isProjectUsingDataStore()) {
|
|
285
247
|
this.addModelSyncFields(ctx, type);
|
|
286
248
|
}
|
|
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
|
-
}
|
|
305
249
|
}
|
|
306
250
|
};
|
|
307
251
|
|
|
@@ -330,12 +274,10 @@ export class ModelTransformer extends TransformerModelBase implements Transforme
|
|
|
330
274
|
default:
|
|
331
275
|
throw new Error('Unknown query field type');
|
|
332
276
|
}
|
|
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
|
|
335
277
|
resolver.addToSlot(
|
|
336
278
|
'postAuth',
|
|
337
279
|
MappingTemplate.s3MappingTemplateFromString(
|
|
338
|
-
generateAuthExpressionForSandboxMode(context
|
|
280
|
+
generateAuthExpressionForSandboxMode(context),
|
|
339
281
|
`${query.typeName}.${query.fieldName}.{slotName}.{slotIndex}.req.vtl`,
|
|
340
282
|
),
|
|
341
283
|
);
|
|
@@ -362,7 +304,7 @@ export class ModelTransformer extends TransformerModelBase implements Transforme
|
|
|
362
304
|
resolver.addToSlot(
|
|
363
305
|
'postAuth',
|
|
364
306
|
MappingTemplate.s3MappingTemplateFromString(
|
|
365
|
-
generateAuthExpressionForSandboxMode(context
|
|
307
|
+
generateAuthExpressionForSandboxMode(context),
|
|
366
308
|
`${mutation.typeName}.${mutation.fieldName}.{slotName}.{slotIndex}.req.vtl`,
|
|
367
309
|
),
|
|
368
310
|
);
|
|
@@ -410,7 +352,7 @@ export class ModelTransformer extends TransformerModelBase implements Transforme
|
|
|
410
352
|
resolver.addToSlot(
|
|
411
353
|
'postAuth',
|
|
412
354
|
MappingTemplate.s3MappingTemplateFromString(
|
|
413
|
-
generateAuthExpressionForSandboxMode(context
|
|
355
|
+
generateAuthExpressionForSandboxMode(context),
|
|
414
356
|
`${subscription.typeName}.${subscription.fieldName}.{slotName}.{slotIndex}.req.vtl`,
|
|
415
357
|
),
|
|
416
358
|
);
|
|
@@ -1143,42 +1085,30 @@ export class ModelTransformer extends TransformerModelBase implements Transforme
|
|
|
1143
1085
|
description: 'The number of read IOPS the table should support.',
|
|
1144
1086
|
type: 'Number',
|
|
1145
1087
|
default: 5,
|
|
1146
|
-
});
|
|
1088
|
+
}).valueAsString;
|
|
1147
1089
|
const writeIops = new cdk.CfnParameter(stack, ResourceConstants.PARAMETERS.DynamoDBModelTableWriteIOPS, {
|
|
1148
1090
|
description: 'The number of write IOPS the table should support.',
|
|
1149
1091
|
type: 'Number',
|
|
1150
1092
|
default: 5,
|
|
1151
|
-
});
|
|
1093
|
+
}).valueAsString;
|
|
1152
1094
|
const billingMode = new cdk.CfnParameter(stack, ResourceConstants.PARAMETERS.DynamoDBBillingMode, {
|
|
1153
1095
|
description: 'Configure @model types to create DynamoDB tables with PAY_PER_REQUEST or PROVISIONED billing modes.',
|
|
1154
1096
|
type: 'String',
|
|
1155
1097
|
default: 'PAY_PER_REQUEST',
|
|
1156
1098
|
allowedValues: ['PAY_PER_REQUEST', 'PROVISIONED'],
|
|
1157
|
-
});
|
|
1099
|
+
}).valueAsString;
|
|
1158
1100
|
const pointInTimeRecovery = new cdk.CfnParameter(stack, ResourceConstants.PARAMETERS.DynamoDBEnablePointInTimeRecovery, {
|
|
1159
1101
|
description: 'Whether to enable Point in Time Recovery on the table.',
|
|
1160
1102
|
type: 'String',
|
|
1161
1103
|
default: 'false',
|
|
1162
1104
|
allowedValues: ['true', 'false'],
|
|
1163
|
-
});
|
|
1105
|
+
}).valueAsString;
|
|
1164
1106
|
const enableSSE = new cdk.CfnParameter(stack, ResourceConstants.PARAMETERS.DynamoDBEnableServerSideEncryption, {
|
|
1165
1107
|
description: 'Enable server side encryption powered by KMS.',
|
|
1166
1108
|
type: 'String',
|
|
1167
1109
|
default: 'true',
|
|
1168
1110
|
allowedValues: ['true', 'false'],
|
|
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
|
-
);
|
|
1111
|
+
}).valueAsString;
|
|
1182
1112
|
|
|
1183
1113
|
// Add conditions.
|
|
1184
1114
|
// eslint-disable-next-line no-new
|