@aws-amplify/graphql-index-transformer 1.2.9-test-tag-1.0 → 1.2.10-no-internal-synth.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +7 -1
- package/lib/graphql-index-transformer.d.ts +13 -0
- package/lib/graphql-index-transformer.d.ts.map +1 -0
- package/lib/graphql-index-transformer.js +143 -0
- package/lib/graphql-index-transformer.js.map +1 -0
- package/lib/graphql-primary-key-transformer.d.ts +15 -0
- package/lib/graphql-primary-key-transformer.d.ts.map +1 -0
- package/lib/graphql-primary-key-transformer.js +144 -0
- package/lib/graphql-primary-key-transformer.js.map +1 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +10 -0
- package/lib/index.js.map +1 -0
- package/lib/resolvers/generators/dynamodb-vtl-generator.d.ts +8 -0
- package/lib/resolvers/generators/dynamodb-vtl-generator.d.ts.map +1 -0
- package/lib/resolvers/generators/dynamodb-vtl-generator.js +51 -0
- package/lib/resolvers/generators/dynamodb-vtl-generator.js.map +1 -0
- package/lib/resolvers/generators/index.d.ts +4 -0
- package/lib/resolvers/generators/index.d.ts.map +1 -0
- package/lib/resolvers/generators/index.js +20 -0
- package/lib/resolvers/generators/index.js.map +1 -0
- package/lib/resolvers/generators/rds-vtl-generator.d.ts +10 -0
- package/lib/resolvers/generators/rds-vtl-generator.d.ts.map +1 -0
- package/lib/resolvers/generators/rds-vtl-generator.js +65 -0
- package/lib/resolvers/generators/rds-vtl-generator.js.map +1 -0
- package/lib/resolvers/generators/vtl-generator.d.ts +7 -0
- package/lib/resolvers/generators/vtl-generator.d.ts.map +1 -0
- package/lib/resolvers/generators/vtl-generator.js +3 -0
- package/lib/resolvers/generators/vtl-generator.js.map +1 -0
- package/lib/resolvers/index.d.ts +3 -0
- package/lib/resolvers/index.d.ts.map +1 -0
- package/lib/resolvers/index.js +19 -0
- package/lib/resolvers/index.js.map +1 -0
- package/lib/resolvers/resolvers.d.ts +23 -0
- package/lib/resolvers/resolvers.d.ts.map +1 -0
- package/lib/resolvers/resolvers.js +569 -0
- package/lib/resolvers/resolvers.js.map +1 -0
- package/lib/schema.d.ts +13 -0
- package/lib/schema.d.ts.map +1 -0
- package/lib/schema.js +340 -0
- package/lib/schema.js.map +1 -0
- package/lib/types.d.ts +15 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +3 -0
- package/lib/types.js.map +1 -0
- package/lib/utils.d.ts +7 -0
- package/lib/utils.d.ts.map +1 -0
- package/lib/utils.js +84 -0
- package/lib/utils.js.map +1 -0
- package/package.json +10 -7
@@ -0,0 +1,569 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
+
}) : function(o, v) {
|
16
|
+
o["default"] = v;
|
17
|
+
});
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
+
if (mod && mod.__esModule) return mod;
|
20
|
+
var result = {};
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
+
__setModuleDefault(result, mod);
|
23
|
+
return result;
|
24
|
+
};
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
26
|
+
exports.getVTLGenerator = exports.getDBType = exports.getDBInfo = exports.generateAuthExpressionForSandboxMode = exports.constructSyncVTL = exports.addIndexToResolverSlot = exports.mergeInputsAndDefaultsSnippet = exports.updateResolversForIndex = exports.appendSecondaryIndex = exports.validateSortDirectionInput = exports.setQuerySnippet = exports.ensureCompositeKeySnippet = exports.getResolverObject = exports.attributeTypeFromType = exports.updateResolvers = exports.replaceDdbPrimaryKey = void 0;
|
27
|
+
const graphql_model_transformer_1 = require("@aws-amplify/graphql-model-transformer");
|
28
|
+
const graphql_transformer_core_1 = require("@aws-amplify/graphql-transformer-core");
|
29
|
+
const cdk = __importStar(require("aws-cdk-lib"));
|
30
|
+
const graphql_1 = require("graphql");
|
31
|
+
const graphql_mapping_template_1 = require("graphql-mapping-template");
|
32
|
+
const graphql_transformer_common_1 = require("graphql-transformer-common");
|
33
|
+
const utils_1 = require("../utils");
|
34
|
+
const generators_1 = require("./generators");
|
35
|
+
const API_KEY = 'API Key Authorization';
|
36
|
+
function replaceDdbPrimaryKey(config, ctx) {
|
37
|
+
var _a, _b, _c;
|
38
|
+
const { field, object } = config;
|
39
|
+
const table = getTable(ctx, object);
|
40
|
+
const cfnTable = table.table;
|
41
|
+
const tableAttrDefs = table.attributeDefinitions;
|
42
|
+
const tableKeySchema = table.keySchema;
|
43
|
+
const keySchema = getDdbKeySchema(config);
|
44
|
+
const attrDefs = attributeDefinitions(config, ctx);
|
45
|
+
const existingAttrDefSet = new Set(tableAttrDefs.map((ad) => ad.attributeName));
|
46
|
+
const primaryKeyPartitionKeyName = (_a = field.name.value) !== null && _a !== void 0 ? _a : 'id';
|
47
|
+
const primaryKeyPartitionKeyType = (_c = (_b = attrDefs.find((attr) => attr.attributeName === primaryKeyPartitionKeyName)) === null || _b === void 0 ? void 0 : _b.attributeType) !== null && _c !== void 0 ? _c : 'S';
|
48
|
+
for (const existingKey of tableKeySchema) {
|
49
|
+
if (existingAttrDefSet.has(existingKey.attributeName)) {
|
50
|
+
table.attributeDefinitions = tableAttrDefs.filter((ad) => ad.attributeName !== existingKey.attributeName);
|
51
|
+
existingAttrDefSet.delete(existingKey.attributeName);
|
52
|
+
}
|
53
|
+
}
|
54
|
+
table.keySchema = keySchema;
|
55
|
+
table.tablePartitionKey = { name: primaryKeyPartitionKeyName, type: primaryKeyPartitionKeyType };
|
56
|
+
for (const attr of attrDefs) {
|
57
|
+
if (!existingAttrDefSet.has(attr.attributeName)) {
|
58
|
+
table.attributeDefinitions.push(attr);
|
59
|
+
}
|
60
|
+
}
|
61
|
+
cfnTable.keySchema = table.keySchema;
|
62
|
+
cfnTable.attributeDefinitions = table.attributeDefinitions;
|
63
|
+
}
|
64
|
+
exports.replaceDdbPrimaryKey = replaceDdbPrimaryKey;
|
65
|
+
function updateResolvers(config, ctx, resolverMap) {
|
66
|
+
const getResolver = getResolverObject(config, ctx, 'get');
|
67
|
+
const listResolver = getResolverObject(config, ctx, 'list');
|
68
|
+
const createResolver = getResolverObject(config, ctx, 'create');
|
69
|
+
const updateResolver = getResolverObject(config, ctx, 'update');
|
70
|
+
const deleteResolver = getResolverObject(config, ctx, 'delete');
|
71
|
+
const syncResolver = getResolverObject(config, ctx, 'sync');
|
72
|
+
if (getResolver) {
|
73
|
+
addIndexToResolverSlot(getResolver, [setPrimaryKeySnippet(config, false)]);
|
74
|
+
}
|
75
|
+
if (listResolver) {
|
76
|
+
addIndexToResolverSlot(listResolver, [
|
77
|
+
(0, graphql_mapping_template_1.print)(setQuerySnippet(config, ctx, true)),
|
78
|
+
`$util.qr($ctx.stash.put("${graphql_transformer_common_1.ResourceConstants.SNIPPETS.ModelQueryExpression}", $${graphql_transformer_common_1.ResourceConstants.SNIPPETS.ModelQueryExpression}))`,
|
79
|
+
]);
|
80
|
+
}
|
81
|
+
if (createResolver) {
|
82
|
+
addIndexToResolverSlot(createResolver, [
|
83
|
+
mergeInputsAndDefaultsSnippet(),
|
84
|
+
setPrimaryKeySnippet(config, true),
|
85
|
+
ensureCompositeKeySnippet(config, false),
|
86
|
+
]);
|
87
|
+
}
|
88
|
+
if (updateResolver) {
|
89
|
+
addIndexToResolverSlot(updateResolver, [
|
90
|
+
mergeInputsAndDefaultsSnippet(),
|
91
|
+
setPrimaryKeySnippet(config, true),
|
92
|
+
ensureCompositeKeySnippet(config, false),
|
93
|
+
]);
|
94
|
+
}
|
95
|
+
if (deleteResolver) {
|
96
|
+
addIndexToResolverSlot(deleteResolver, [mergeInputsAndDefaultsSnippet(), setPrimaryKeySnippet(config, true)]);
|
97
|
+
}
|
98
|
+
if (syncResolver) {
|
99
|
+
makeSyncResolver('dbTable', config, ctx, syncResolver, resolverMap);
|
100
|
+
}
|
101
|
+
}
|
102
|
+
exports.updateResolvers = updateResolvers;
|
103
|
+
function getTable(context, object) {
|
104
|
+
const ddbDataSource = context.dataSources.get(object);
|
105
|
+
const tableName = graphql_transformer_common_1.ModelResourceIDs.ModelTableResourceID(object.name.value);
|
106
|
+
const table = ddbDataSource.ds.stack.node.findChild(tableName);
|
107
|
+
if (!table) {
|
108
|
+
throw new Error(`Table not found in stack with table name ${tableName}`);
|
109
|
+
}
|
110
|
+
return table;
|
111
|
+
}
|
112
|
+
function getDdbKeySchema(config) {
|
113
|
+
const schema = [{ attributeName: config.field.name.value, keyType: 'HASH' }];
|
114
|
+
if (config.sortKey.length > 0) {
|
115
|
+
schema.push({ attributeName: getSortKeyName(config), keyType: 'RANGE' });
|
116
|
+
}
|
117
|
+
return schema;
|
118
|
+
}
|
119
|
+
function attributeTypeFromType(type, ctx) {
|
120
|
+
const baseTypeName = (0, graphql_transformer_common_1.getBaseType)(type);
|
121
|
+
const ofType = ctx.output.getType(baseTypeName);
|
122
|
+
if (ofType && ofType.kind === graphql_1.Kind.ENUM_TYPE_DEFINITION) {
|
123
|
+
return 'S';
|
124
|
+
}
|
125
|
+
return (0, graphql_transformer_common_1.attributeTypeFromScalar)(type);
|
126
|
+
}
|
127
|
+
exports.attributeTypeFromType = attributeTypeFromType;
|
128
|
+
function attributeDefinitions(config, ctx) {
|
129
|
+
const { field, sortKey, sortKeyFields } = config;
|
130
|
+
const definitions = [{ attributeName: field.name.value, attributeType: attributeTypeFromType(field.type, ctx) }];
|
131
|
+
if (sortKeyFields.length === 1) {
|
132
|
+
definitions.push({
|
133
|
+
attributeName: sortKeyFields[0],
|
134
|
+
attributeType: attributeTypeFromType(sortKey[0].type, ctx),
|
135
|
+
});
|
136
|
+
}
|
137
|
+
else if (sortKeyFields.length > 1) {
|
138
|
+
definitions.push({
|
139
|
+
attributeName: getSortKeyName(config),
|
140
|
+
attributeType: 'S',
|
141
|
+
});
|
142
|
+
}
|
143
|
+
return definitions;
|
144
|
+
}
|
145
|
+
function getSortKeyName(config) {
|
146
|
+
return config.sortKeyFields.join(graphql_transformer_common_1.ModelResourceIDs.ModelCompositeKeySeparator());
|
147
|
+
}
|
148
|
+
function getResolverObject(config, ctx, op) {
|
149
|
+
var _a;
|
150
|
+
const resolverName = (0, utils_1.lookupResolverName)(config, ctx, op);
|
151
|
+
if (!resolverName) {
|
152
|
+
return null;
|
153
|
+
}
|
154
|
+
const objectName = op === 'get' || op === 'list' || op === 'sync' ? ctx.output.getQueryTypeName() : ctx.output.getMutationTypeName();
|
155
|
+
if (!objectName) {
|
156
|
+
return null;
|
157
|
+
}
|
158
|
+
return (_a = ctx.resolvers.getResolver(objectName, resolverName)) !== null && _a !== void 0 ? _a : null;
|
159
|
+
}
|
160
|
+
exports.getResolverObject = getResolverObject;
|
161
|
+
function setPrimaryKeySnippet(config, isMutation) {
|
162
|
+
const cmds = [
|
163
|
+
(0, graphql_mapping_template_1.qref)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('ctx.stash.metadata.put'), (0, graphql_mapping_template_1.str)(graphql_transformer_common_1.ResourceConstants.SNIPPETS.ModelObjectKey), modelObjectKeySnippet(config, isMutation))),
|
164
|
+
];
|
165
|
+
return (0, graphql_mapping_template_1.printBlock)('Set the primary key')((0, graphql_mapping_template_1.compoundExpression)(cmds));
|
166
|
+
}
|
167
|
+
function modelObjectKeySnippet(config, isMutation) {
|
168
|
+
const { field, sortKeyFields } = config;
|
169
|
+
const argsPrefix = isMutation ? 'mergedValues' : 'ctx.args';
|
170
|
+
const modelObject = {
|
171
|
+
[field.name.value]: (0, graphql_mapping_template_1.ref)(`util.dynamodb.toDynamoDB($${argsPrefix}.${field.name.value})`),
|
172
|
+
};
|
173
|
+
if (sortKeyFields.length > 1) {
|
174
|
+
const compositeSortKey = getSortKeyName(config);
|
175
|
+
const compositeSortKeyValue = sortKeyFields
|
176
|
+
.map((keyField) => `\${${argsPrefix}.${keyField}}`)
|
177
|
+
.join(graphql_transformer_common_1.ModelResourceIDs.ModelCompositeKeySeparator());
|
178
|
+
modelObject[compositeSortKey] = (0, graphql_mapping_template_1.ref)(`util.dynamodb.toDynamoDB("${compositeSortKeyValue}")`);
|
179
|
+
}
|
180
|
+
else if (sortKeyFields.length === 1) {
|
181
|
+
modelObject[sortKeyFields[0]] = (0, graphql_mapping_template_1.ref)(`util.dynamodb.toDynamoDB($${argsPrefix}.${sortKeyFields[0]})`);
|
182
|
+
}
|
183
|
+
return (0, graphql_mapping_template_1.obj)(modelObject);
|
184
|
+
}
|
185
|
+
function ensureCompositeKeySnippet(config, conditionallySetSortKey) {
|
186
|
+
const { sortKeyFields } = config;
|
187
|
+
if (sortKeyFields.length < 2) {
|
188
|
+
return '';
|
189
|
+
}
|
190
|
+
const argsPrefix = 'mergedValues';
|
191
|
+
const condensedSortKey = getSortKeyName(config);
|
192
|
+
const dynamoDBFriendlySortKeyName = (0, graphql_transformer_common_1.toCamelCase)(sortKeyFields.map((f) => (0, graphql_transformer_common_1.graphqlName)(f)));
|
193
|
+
const condensedSortKeyValue = sortKeyFields
|
194
|
+
.map((keyField) => `\${${argsPrefix}.${keyField}}`)
|
195
|
+
.join(graphql_transformer_common_1.ModelResourceIDs.ModelCompositeKeySeparator());
|
196
|
+
return (0, graphql_mapping_template_1.print)((0, graphql_mapping_template_1.compoundExpression)([
|
197
|
+
(0, graphql_mapping_template_1.ifElse)((0, graphql_mapping_template_1.raw)(`$util.isNull($ctx.stash.metadata.${graphql_transformer_common_1.ResourceConstants.SNIPPETS.DynamoDBNameOverrideMap})`), (0, graphql_mapping_template_1.qref)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('ctx.stash.metadata.put'), (0, graphql_mapping_template_1.str)(graphql_transformer_common_1.ResourceConstants.SNIPPETS.DynamoDBNameOverrideMap), (0, graphql_mapping_template_1.raw)(`{ '${condensedSortKey}': "${dynamoDBFriendlySortKeyName}" }`))), (0, graphql_mapping_template_1.qref)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)(`ctx.stash.metadata.${graphql_transformer_common_1.ResourceConstants.SNIPPETS.DynamoDBNameOverrideMap}.put`), (0, graphql_mapping_template_1.raw)(`'${condensedSortKey}'`), (0, graphql_mapping_template_1.str)(dynamoDBFriendlySortKeyName)))),
|
198
|
+
conditionallySetSortKey
|
199
|
+
? (0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.ref)(graphql_transformer_common_1.ResourceConstants.SNIPPETS.HasSeenSomeKeyArg), (0, graphql_mapping_template_1.qref)(`$ctx.args.input.put('${condensedSortKey}',"${condensedSortKeyValue}")`))
|
200
|
+
: (0, graphql_mapping_template_1.qref)(`$ctx.args.input.put('${condensedSortKey}',"${condensedSortKeyValue}")`),
|
201
|
+
]));
|
202
|
+
}
|
203
|
+
exports.ensureCompositeKeySnippet = ensureCompositeKeySnippet;
|
204
|
+
function setQuerySnippet(config, ctx, isListResolver) {
|
205
|
+
const { field, sortKey, sortKeyFields } = config;
|
206
|
+
const keyFields = [field, ...sortKey];
|
207
|
+
const keyNames = [field.name.value, ...sortKeyFields];
|
208
|
+
const keyTypes = keyFields.map((k) => attributeTypeFromType(k.type, ctx));
|
209
|
+
const expressions = validateSortDirectionInput(config, isListResolver);
|
210
|
+
expressions.push((0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(graphql_transformer_common_1.ResourceConstants.SNIPPETS.ModelQueryExpression), (0, graphql_mapping_template_1.obj)({})), (0, graphql_transformer_common_1.applyKeyExpressionForCompositeKey)(keyNames, keyTypes, graphql_transformer_common_1.ResourceConstants.SNIPPETS.ModelQueryExpression));
|
211
|
+
return (0, graphql_mapping_template_1.block)('Set query expression for key', expressions);
|
212
|
+
}
|
213
|
+
exports.setQuerySnippet = setQuerySnippet;
|
214
|
+
function validateSortDirectionInput(config, isListResolver) {
|
215
|
+
const { field, sortKeyFields } = config;
|
216
|
+
const keyNames = [field.name.value, ...sortKeyFields];
|
217
|
+
const expressions = [];
|
218
|
+
if (keyNames.length === 1) {
|
219
|
+
const sortDirectionValidation = (0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.raw)('!$util.isNull($ctx.args.sortDirection)'), (0, graphql_mapping_template_1.raw)('$util.error("sortDirection is not supported for List operations without a Sort key defined.", "InvalidArgumentsError")'));
|
220
|
+
expressions.push(sortDirectionValidation);
|
221
|
+
}
|
222
|
+
else if (isListResolver === true && keyNames.length >= 1) {
|
223
|
+
const sortDirectionValidation = (0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.and)([(0, graphql_mapping_template_1.raw)(`$util.isNull($ctx.args.${keyNames[0]})`), (0, graphql_mapping_template_1.raw)('!$util.isNull($ctx.args.sortDirection)')]), (0, graphql_mapping_template_1.raw)(`$util.error("When providing argument 'sortDirection' you must also provide argument '${keyNames[0]}'.", "InvalidArgumentsError")`));
|
224
|
+
expressions.push(sortDirectionValidation);
|
225
|
+
}
|
226
|
+
return expressions;
|
227
|
+
}
|
228
|
+
exports.validateSortDirectionInput = validateSortDirectionInput;
|
229
|
+
function appendSecondaryIndex(config, ctx) {
|
230
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
231
|
+
const { name, object, primaryKeyField } = config;
|
232
|
+
const dbType = getDBType(ctx, object.name.value);
|
233
|
+
if (dbType === 'MySQL') {
|
234
|
+
return;
|
235
|
+
}
|
236
|
+
const table = getTable(ctx, object);
|
237
|
+
const keySchema = getDdbKeySchema(config);
|
238
|
+
const attrDefs = attributeDefinitions(config, ctx);
|
239
|
+
const primaryKeyPartitionKeyName = (_b = (_a = primaryKeyField === null || primaryKeyField === void 0 ? void 0 : primaryKeyField.name) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : 'id';
|
240
|
+
const partitionKeyName = (_c = keySchema[0]) === null || _c === void 0 ? void 0 : _c.attributeName;
|
241
|
+
const sortKeyName = (_d = keySchema === null || keySchema === void 0 ? void 0 : keySchema[1]) === null || _d === void 0 ? void 0 : _d.attributeName;
|
242
|
+
const partitionKeyType = (_f = (_e = attrDefs.find((attr) => attr.attributeName === partitionKeyName)) === null || _e === void 0 ? void 0 : _e.attributeType) !== null && _f !== void 0 ? _f : 'S';
|
243
|
+
const sortKeyType = sortKeyName ? (_h = (_g = attrDefs.find((attr) => attr.attributeName === sortKeyName)) === null || _g === void 0 ? void 0 : _g.attributeType) !== null && _h !== void 0 ? _h : 'S' : undefined;
|
244
|
+
if (!ctx.transformParameters.secondaryKeyAsGSI && primaryKeyPartitionKeyName === partitionKeyName) {
|
245
|
+
table.addLocalSecondaryIndex({
|
246
|
+
indexName: name,
|
247
|
+
projectionType: 'ALL',
|
248
|
+
sortKey: sortKeyName
|
249
|
+
? {
|
250
|
+
name: sortKeyName,
|
251
|
+
type: sortKeyType,
|
252
|
+
}
|
253
|
+
: undefined,
|
254
|
+
});
|
255
|
+
}
|
256
|
+
else {
|
257
|
+
table.addGlobalSecondaryIndex({
|
258
|
+
indexName: name,
|
259
|
+
projectionType: 'ALL',
|
260
|
+
partitionKey: {
|
261
|
+
name: partitionKeyName,
|
262
|
+
type: partitionKeyType,
|
263
|
+
},
|
264
|
+
sortKey: sortKeyName
|
265
|
+
? {
|
266
|
+
name: sortKeyName,
|
267
|
+
type: sortKeyType,
|
268
|
+
}
|
269
|
+
: undefined,
|
270
|
+
readCapacity: cdk.Fn.ref(graphql_transformer_common_1.ResourceConstants.PARAMETERS.DynamoDBModelTableReadIOPS),
|
271
|
+
writeCapacity: cdk.Fn.ref(graphql_transformer_common_1.ResourceConstants.PARAMETERS.DynamoDBModelTableWriteIOPS),
|
272
|
+
});
|
273
|
+
const cfnTable = table.table;
|
274
|
+
cfnTable.globalSecondaryIndexes = appendIndex(cfnTable.globalSecondaryIndexes, {
|
275
|
+
indexName: name,
|
276
|
+
keySchema,
|
277
|
+
projection: { projectionType: 'ALL' },
|
278
|
+
provisionedThroughput: cdk.Fn.conditionIf(graphql_transformer_common_1.ResourceConstants.CONDITIONS.ShouldUsePayPerRequestBilling, cdk.Fn.ref('AWS::NoValue'), {
|
279
|
+
ReadCapacityUnits: cdk.Fn.ref(graphql_transformer_common_1.ResourceConstants.PARAMETERS.DynamoDBModelTableReadIOPS),
|
280
|
+
WriteCapacityUnits: cdk.Fn.ref(graphql_transformer_common_1.ResourceConstants.PARAMETERS.DynamoDBModelTableWriteIOPS),
|
281
|
+
}),
|
282
|
+
});
|
283
|
+
}
|
284
|
+
}
|
285
|
+
exports.appendSecondaryIndex = appendSecondaryIndex;
|
286
|
+
function appendIndex(list, newIndex) {
|
287
|
+
if (Array.isArray(list)) {
|
288
|
+
list.push(newIndex);
|
289
|
+
return list;
|
290
|
+
}
|
291
|
+
return [newIndex];
|
292
|
+
}
|
293
|
+
function updateResolversForIndex(config, ctx, resolverMap) {
|
294
|
+
const { name, queryField, object } = config;
|
295
|
+
if (!name) {
|
296
|
+
throw new Error('Expected name while updating index resolvers.');
|
297
|
+
}
|
298
|
+
const createResolver = getResolverObject(config, ctx, 'create');
|
299
|
+
const updateResolver = getResolverObject(config, ctx, 'update');
|
300
|
+
const deleteResolver = getResolverObject(config, ctx, 'delete');
|
301
|
+
const syncResolver = getResolverObject(config, ctx, 'sync');
|
302
|
+
const dbType = getDBType(ctx, object.name.value);
|
303
|
+
const isDynamoDB = dbType === 'DDB';
|
304
|
+
if (isDynamoDB && createResolver) {
|
305
|
+
const checks = [validateIndexArgumentSnippet(config, 'create'), ensureCompositeKeySnippet(config, true)];
|
306
|
+
if (checks[0] || checks[1]) {
|
307
|
+
addIndexToResolverSlot(createResolver, [mergeInputsAndDefaultsSnippet(), ...checks]);
|
308
|
+
}
|
309
|
+
}
|
310
|
+
if (isDynamoDB && updateResolver) {
|
311
|
+
const checks = [validateIndexArgumentSnippet(config, 'update'), ensureCompositeKeySnippet(config, true)];
|
312
|
+
if (checks[0] || checks[1]) {
|
313
|
+
addIndexToResolverSlot(updateResolver, [mergeInputsAndDefaultsSnippet(), ...checks]);
|
314
|
+
}
|
315
|
+
}
|
316
|
+
if (isDynamoDB && deleteResolver) {
|
317
|
+
const checks = [ensureCompositeKeySnippet(config, false)];
|
318
|
+
if (checks[0]) {
|
319
|
+
addIndexToResolverSlot(deleteResolver, [mergeInputsAndDefaultsSnippet(), ...checks]);
|
320
|
+
}
|
321
|
+
}
|
322
|
+
if (queryField) {
|
323
|
+
makeQueryResolver(config, ctx, dbType);
|
324
|
+
}
|
325
|
+
if (isDynamoDB && syncResolver) {
|
326
|
+
makeSyncResolver(name, config, ctx, syncResolver, resolverMap);
|
327
|
+
}
|
328
|
+
}
|
329
|
+
exports.updateResolversForIndex = updateResolversForIndex;
|
330
|
+
function makeQueryResolver(config, ctx, dbType) {
|
331
|
+
const { RDSLambdaDataSourceLogicalID } = graphql_transformer_common_1.ResourceConstants.RESOURCES;
|
332
|
+
const isDynamoDB = dbType === graphql_transformer_core_1.DDB_DB_TYPE;
|
333
|
+
const { name, object, queryField } = config;
|
334
|
+
if (!(name && queryField)) {
|
335
|
+
throw new Error('Expected name and queryField to be defined while generating resolver.');
|
336
|
+
}
|
337
|
+
const modelName = object.name.value;
|
338
|
+
const dbInfo = getDBInfo(ctx, modelName);
|
339
|
+
let dataSourceName = `${object.name.value}Table`;
|
340
|
+
if (dbType === graphql_transformer_core_1.MYSQL_DB_TYPE) {
|
341
|
+
dataSourceName = RDSLambdaDataSourceLogicalID;
|
342
|
+
}
|
343
|
+
const dataSource = ctx.api.host.getDataSource(dataSourceName);
|
344
|
+
const queryTypeName = ctx.output.getQueryTypeName();
|
345
|
+
let stackId = object.name.value;
|
346
|
+
if (isDynamoDB) {
|
347
|
+
const table = getTable(ctx, object);
|
348
|
+
stackId = table.stack.node.id;
|
349
|
+
}
|
350
|
+
if (!dataSource) {
|
351
|
+
throw new Error(`Could not find datasource with name ${dataSourceName} in context.`);
|
352
|
+
}
|
353
|
+
const resolverResourceId = graphql_transformer_common_1.ResolverResourceIDs.ResolverResourceID(queryTypeName, queryField);
|
354
|
+
const resolver = ctx.resolvers.generateQueryResolver(queryTypeName, queryField, resolverResourceId, dataSource, graphql_transformer_core_1.MappingTemplate.s3MappingTemplateFromString((0, exports.getVTLGenerator)(dbInfo).generateIndexQueryRequestTemplate(config, ctx, modelName, queryField), `${queryTypeName}.${queryField}.req.vtl`), graphql_transformer_core_1.MappingTemplate.s3MappingTemplateFromString((0, graphql_mapping_template_1.print)((0, graphql_mapping_template_1.compoundExpression)([
|
355
|
+
(0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.ref)('ctx.error'), (0, graphql_mapping_template_1.raw)('$util.error($ctx.error.message, $ctx.error.type)')),
|
356
|
+
(0, graphql_mapping_template_1.raw)('$util.toJson($ctx.result)'),
|
357
|
+
])), `${queryTypeName}.${queryField}.res.vtl`));
|
358
|
+
resolver.addToSlot('postAuth', graphql_transformer_core_1.MappingTemplate.s3MappingTemplateFromString((0, exports.generateAuthExpressionForSandboxMode)(ctx.transformParameters.sandboxModeEnabled), `${queryTypeName}.${queryField}.{slotName}.{slotIndex}.res.vtl`));
|
359
|
+
resolver.setScope(ctx.stackManager.getScopeFor(resolverResourceId, stackId));
|
360
|
+
ctx.resolvers.addResolver(object.name.value, queryField, resolver);
|
361
|
+
}
|
362
|
+
function validateIndexArgumentSnippet(config, keyOperation) {
|
363
|
+
const { name, sortKeyFields } = config;
|
364
|
+
if (sortKeyFields.length < 2) {
|
365
|
+
return '';
|
366
|
+
}
|
367
|
+
return (0, graphql_mapping_template_1.printBlock)(`Validate ${keyOperation} mutation for @index '${name}'`)((0, graphql_mapping_template_1.compoundExpression)([
|
368
|
+
(0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(graphql_transformer_common_1.ResourceConstants.SNIPPETS.HasSeenSomeKeyArg), (0, graphql_mapping_template_1.bool)(false)),
|
369
|
+
(0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)('keyFieldNames'), (0, graphql_mapping_template_1.list)(sortKeyFields.map((f) => (0, graphql_mapping_template_1.str)(f)))),
|
370
|
+
(0, graphql_mapping_template_1.forEach)((0, graphql_mapping_template_1.ref)('keyFieldName'), (0, graphql_mapping_template_1.ref)('keyFieldNames'), [
|
371
|
+
(0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.raw)('$mergedValues.containsKey("$keyFieldName")'), (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(graphql_transformer_common_1.ResourceConstants.SNIPPETS.HasSeenSomeKeyArg), (0, graphql_mapping_template_1.bool)(true)), true),
|
372
|
+
]),
|
373
|
+
(0, graphql_mapping_template_1.forEach)((0, graphql_mapping_template_1.ref)('keyFieldName'), (0, graphql_mapping_template_1.ref)('keyFieldNames'), [
|
374
|
+
(0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.raw)(`$${graphql_transformer_common_1.ResourceConstants.SNIPPETS.HasSeenSomeKeyArg} && !$mergedValues.containsKey("$keyFieldName")`), (0, graphql_mapping_template_1.raw)(`$util.error("When ${keyOperation.replace(/.$/, 'ing')} any part of the composite sort key for @index '${name}',` +
|
375
|
+
" you must provide all fields for the key. Missing key: '$keyFieldName'.\")")),
|
376
|
+
]),
|
377
|
+
]));
|
378
|
+
}
|
379
|
+
function mergeInputsAndDefaultsSnippet() {
|
380
|
+
return (0, graphql_mapping_template_1.printBlock)('Merge default values and inputs')((0, graphql_model_transformer_1.generateApplyDefaultsToInputTemplate)('mergedValues'));
|
381
|
+
}
|
382
|
+
exports.mergeInputsAndDefaultsSnippet = mergeInputsAndDefaultsSnippet;
|
383
|
+
function addIndexToResolverSlot(resolver, lines, isSync = false) {
|
384
|
+
const res = resolver;
|
385
|
+
res.addToSlot('preAuth', graphql_transformer_core_1.MappingTemplate.s3MappingTemplateFromString(`${lines.join('\n')}\n${!isSync ? '{}' : ''}`, `${res.typeName}.${res.fieldName}.{slotName}.{slotIndex}.req.vtl`));
|
386
|
+
}
|
387
|
+
exports.addIndexToResolverSlot = addIndexToResolverSlot;
|
388
|
+
function makeSyncResolver(name, config, ctx, syncResolver, resolverMap) {
|
389
|
+
if (!ctx.isProjectUsingDataStore())
|
390
|
+
return;
|
391
|
+
if (resolverMap.has(syncResolver)) {
|
392
|
+
const prevSnippet = resolverMap.get(syncResolver);
|
393
|
+
resolverMap.set(syncResolver, joinSnippets([prevSnippet, (0, graphql_mapping_template_1.print)(setSyncQueryMapSnippet(name, config))]));
|
394
|
+
}
|
395
|
+
else {
|
396
|
+
resolverMap.set(syncResolver, (0, graphql_mapping_template_1.print)(setSyncQueryMapSnippet(name, config)));
|
397
|
+
}
|
398
|
+
}
|
399
|
+
function joinSnippets(lines) {
|
400
|
+
return lines.join('\n');
|
401
|
+
}
|
402
|
+
function setSyncQueryMapSnippet(name, config) {
|
403
|
+
const { field, sortKeyFields } = config;
|
404
|
+
const expressions = [];
|
405
|
+
const keys = [field.name.value, ...(sortKeyFields !== null && sortKeyFields !== void 0 ? sortKeyFields : [])];
|
406
|
+
expressions.push((0, graphql_mapping_template_1.raw)(`$util.qr($QueryMap.put('${keys.join('+')}' , '${name}'))`), (0, graphql_mapping_template_1.raw)(`$util.qr($PkMap.put('${field.name.value}' , '${name}'))`), (0, graphql_mapping_template_1.qref)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('SkMap.put'), (0, graphql_mapping_template_1.str)(name), (0, graphql_mapping_template_1.list)(sortKeyFields.map(graphql_mapping_template_1.str)))));
|
407
|
+
return (0, graphql_mapping_template_1.block)('Set query expression for @key', expressions);
|
408
|
+
}
|
409
|
+
function constructSyncVTL(syncVTLContent, resolver) {
|
410
|
+
const checks = [
|
411
|
+
(0, graphql_mapping_template_1.print)(generateSyncResolverInit()),
|
412
|
+
syncVTLContent,
|
413
|
+
(0, graphql_mapping_template_1.print)(setSyncQueryFilterSnippet()),
|
414
|
+
(0, graphql_mapping_template_1.print)(setSyncKeyExpressionForHashKey(graphql_transformer_common_1.ResourceConstants.SNIPPETS.ModelQueryExpression)),
|
415
|
+
(0, graphql_mapping_template_1.print)(setSyncKeyExpressionForRangeKey(graphql_transformer_common_1.ResourceConstants.SNIPPETS.ModelQueryExpression)),
|
416
|
+
(0, graphql_mapping_template_1.print)(makeSyncQueryResolver()),
|
417
|
+
];
|
418
|
+
addIndexToResolverSlot(resolver, checks, true);
|
419
|
+
}
|
420
|
+
exports.constructSyncVTL = constructSyncVTL;
|
421
|
+
function setSyncQueryFilterSnippet() {
|
422
|
+
const expressions = [];
|
423
|
+
expressions.push((0, graphql_mapping_template_1.compoundExpression)([
|
424
|
+
(0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)('filterArgsMap'), (0, graphql_mapping_template_1.ref)('ctx.args.filter.get("and")')),
|
425
|
+
generateDeltaTableTTLCheck('isLastSyncInDeltaTTLWindow', 'ctx.args.lastSync'),
|
426
|
+
(0, graphql_mapping_template_1.ifElse)((0, graphql_mapping_template_1.raw)('!$util.isNullOrEmpty($filterArgsMap) && !$isLastSyncInDeltaTTLWindow'), (0, graphql_mapping_template_1.compoundExpression)([
|
427
|
+
(0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)('json'), (0, graphql_mapping_template_1.raw)('$filterArgsMap')),
|
428
|
+
(0, graphql_mapping_template_1.forEach)((0, graphql_mapping_template_1.ref)('item'), (0, graphql_mapping_template_1.ref)('json'), [
|
429
|
+
(0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)('ind'), (0, graphql_mapping_template_1.ref)('foreach.index')),
|
430
|
+
(0, graphql_mapping_template_1.forEach)((0, graphql_mapping_template_1.ref)('entry'), (0, graphql_mapping_template_1.ref)('item.entrySet()'), [
|
431
|
+
(0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.raw)('$ind == 0 && !$util.isNullOrEmpty($entry.value.eq) && !$util.isNullOrEmpty($PkMap.get($entry.key))'), (0, graphql_mapping_template_1.compoundExpression)([
|
432
|
+
(0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)('pk'), (0, graphql_mapping_template_1.ref)('entry.key')),
|
433
|
+
(0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)('scan'), (0, graphql_mapping_template_1.bool)(false)),
|
434
|
+
(0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)('queryRequestVariables.partitionKey'), (0, graphql_mapping_template_1.ref)('pk')),
|
435
|
+
(0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)('queryRequestVariables.sortKeys'), (0, graphql_mapping_template_1.ref)('SkMap.get($PkMap.get($pk))')),
|
436
|
+
(0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)('queryRequestVariables.partitionKeyFilter'), (0, graphql_mapping_template_1.obj)({})),
|
437
|
+
(0, graphql_mapping_template_1.raw)(`$util.qr($queryRequestVariables.partitionKeyFilter.put($pk, {'eq': $entry.value.eq}))`),
|
438
|
+
(0, graphql_mapping_template_1.raw)('$util.qr($ctx.args.put($pk,$entry.value.eq))'),
|
439
|
+
(0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)('index'), (0, graphql_mapping_template_1.ref)('PkMap.get($pk)')),
|
440
|
+
])),
|
441
|
+
(0, graphql_mapping_template_1.ifElse)((0, graphql_mapping_template_1.raw)('$ind == 1 && !$util.isNullOrEmpty($pk) && !$util.isNullOrEmpty($QueryMap.get("${pk}+$entry.key"))'), (0, graphql_mapping_template_1.compoundExpression)([
|
442
|
+
(0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)('sk'), (0, graphql_mapping_template_1.ref)('entry.key')),
|
443
|
+
(0, graphql_mapping_template_1.raw)('$util.qr($ctx.args.put($sk,$entry.value))'),
|
444
|
+
(0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)('index'), (0, graphql_mapping_template_1.ref)('QueryMap.get("${pk}+$sk")')),
|
445
|
+
]), (0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.raw)('$ind > 0'), (0, graphql_mapping_template_1.qref)('$filterMap.put($entry.key,$entry.value)'))),
|
446
|
+
]),
|
447
|
+
]),
|
448
|
+
]), (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)('filterMap'), (0, graphql_mapping_template_1.raw)('$ctx.args.filter'))),
|
449
|
+
]));
|
450
|
+
return (0, graphql_mapping_template_1.block)('Set query expression for @key', expressions);
|
451
|
+
}
|
452
|
+
const generateDeltaTableTTLCheck = (deltaTTLCheckRefName, lastSyncRefName) => {
|
453
|
+
return (0, graphql_mapping_template_1.compoundExpression)([
|
454
|
+
(0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(deltaTTLCheckRefName), (0, graphql_mapping_template_1.bool)(false)),
|
455
|
+
(0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)('minLastSync'), (0, graphql_mapping_template_1.raw)(`$util.time.nowEpochMilliSeconds() - $ctx.stash.deltaSyncTableTtl * 60 * 1000`)),
|
456
|
+
(0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.and)([
|
457
|
+
(0, graphql_mapping_template_1.not)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('util.isNull'), (0, graphql_mapping_template_1.ref)(lastSyncRefName))),
|
458
|
+
(0, graphql_mapping_template_1.notEquals)((0, graphql_mapping_template_1.ref)(lastSyncRefName), (0, graphql_mapping_template_1.int)(0)),
|
459
|
+
(0, graphql_mapping_template_1.raw)(`$minLastSync <= $${lastSyncRefName}`),
|
460
|
+
]), (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(deltaTTLCheckRefName), (0, graphql_mapping_template_1.bool)(true))),
|
461
|
+
]);
|
462
|
+
};
|
463
|
+
function setSyncKeyExpressionForHashKey(queryExprReference) {
|
464
|
+
const expressions = [];
|
465
|
+
expressions.push((0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(graphql_transformer_common_1.ResourceConstants.SNIPPETS.ModelQueryExpression), (0, graphql_mapping_template_1.obj)({})), (0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.raw)('!$util.isNull($pk)'), (0, graphql_mapping_template_1.compoundExpression)([
|
466
|
+
(0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(`${queryExprReference}.expression`), (0, graphql_mapping_template_1.str)('#pk = :pk')),
|
467
|
+
(0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(`${queryExprReference}.expressionNames`), (0, graphql_mapping_template_1.obj)({ '#pk': (0, graphql_mapping_template_1.str)('$pk') })),
|
468
|
+
(0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(`${queryExprReference}.expressionValues`), (0, graphql_mapping_template_1.obj)({ ':pk': (0, graphql_mapping_template_1.ref)('util.parseJson($util.dynamodb.toDynamoDBJson($ctx.args.get($pk)))') })),
|
469
|
+
])));
|
470
|
+
return (0, graphql_mapping_template_1.block)('Set Primary Key initialization @key', expressions);
|
471
|
+
}
|
472
|
+
function setSyncKeyExpressionForRangeKey(queryExprReference) {
|
473
|
+
return (0, graphql_mapping_template_1.block)('Applying Key Condition', [
|
474
|
+
(0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.raw)('!$util.isNull($ctx.args.get($sk)) && !$util.isNull($ctx.args.get($sk).beginsWith)'), (0, graphql_mapping_template_1.compoundExpression)([
|
475
|
+
(0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(`${queryExprReference}.expression`), (0, graphql_mapping_template_1.raw)(`"$${queryExprReference}.expression AND begins_with(#sortKey, :sortKey)"`)),
|
476
|
+
(0, graphql_mapping_template_1.qref)(`$${queryExprReference}.expressionNames.put("#sortKey", $sk)`),
|
477
|
+
(0, graphql_mapping_template_1.qref)(`$${queryExprReference}.expressionValues.put(":sortKey", $util.parseJson($util.dynamodb.toDynamoDBJson($ctx.args.get($sk).beginsWith)))`),
|
478
|
+
])),
|
479
|
+
(0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.raw)('!$util.isNull($ctx.args.get($sk)) && !$util.isNull($ctx.args.get($sk).between)'), (0, graphql_mapping_template_1.compoundExpression)([
|
480
|
+
(0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(`${queryExprReference}.expression`), (0, graphql_mapping_template_1.raw)(`"$${queryExprReference}.expression AND #sortKey BETWEEN :sortKey0 AND :sortKey1"`)),
|
481
|
+
(0, graphql_mapping_template_1.qref)(`$${queryExprReference}.expressionNames.put("#sortKey", $sk)`),
|
482
|
+
(0, graphql_mapping_template_1.qref)(`$${queryExprReference}.expressionValues.put(":sortKey", $util.parseJson($util.dynamodb.toDynamoDBJson($ctx.args.get($sk).between[0])))`),
|
483
|
+
(0, graphql_mapping_template_1.qref)(`$${queryExprReference}.expressionValues.put(":sortKey", $util.parseJson($util.dynamodb.toDynamoDBJson($ctx.args.get($sk).between[1])))`),
|
484
|
+
])),
|
485
|
+
(0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.raw)('!$util.isNull($ctx.args.get($sk)) && !$util.isNull($ctx.args.get($sk).eq)'), (0, graphql_mapping_template_1.compoundExpression)([
|
486
|
+
(0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(`${queryExprReference}.expression`), (0, graphql_mapping_template_1.raw)(`"$${queryExprReference}.expression AND #sortKey = :sortKey"`)),
|
487
|
+
(0, graphql_mapping_template_1.qref)(`$${queryExprReference}.expressionNames.put("#sortKey", $sk)`),
|
488
|
+
(0, graphql_mapping_template_1.qref)(`$${queryExprReference}.expressionValues.put(":sortKey", $util.parseJson($util.dynamodb.toDynamoDBJson($ctx.args.get($sk).eq)))`),
|
489
|
+
])),
|
490
|
+
(0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.raw)('!$util.isNull($ctx.args.get($sk)) && !$util.isNull($ctx.args.get($sk).lt)'), (0, graphql_mapping_template_1.compoundExpression)([
|
491
|
+
(0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(`${queryExprReference}.expression`), (0, graphql_mapping_template_1.raw)(`"$${queryExprReference}.expression AND #sortKey < :sortKey"`)),
|
492
|
+
(0, graphql_mapping_template_1.qref)(`$${queryExprReference}.expressionNames.put("#sortKey", $sk)`),
|
493
|
+
(0, graphql_mapping_template_1.qref)(`$${queryExprReference}.expressionValues.put(":sortKey", $util.parseJson($util.dynamodb.toDynamoDBJson($ctx.args.get($sk).lt)))`),
|
494
|
+
])),
|
495
|
+
(0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.raw)('!$util.isNull($ctx.args.get($sk)) && !$util.isNull($ctx.args.get($sk).le)'), (0, graphql_mapping_template_1.compoundExpression)([
|
496
|
+
(0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(`${queryExprReference}.expression`), (0, graphql_mapping_template_1.raw)(`"$${queryExprReference}.expression AND #sortKey <= :sortKey"`)),
|
497
|
+
(0, graphql_mapping_template_1.qref)(`$${queryExprReference}.expressionNames.put("#sortKey", $sk)`),
|
498
|
+
(0, graphql_mapping_template_1.qref)(`$${queryExprReference}.expressionValues.put(":sortKey", $util.parseJson($util.dynamodb.toDynamoDBJson($ctx.args.get($sk).le)))`),
|
499
|
+
])),
|
500
|
+
(0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.raw)('!$util.isNull($ctx.args.get($sk)) && !$util.isNull($ctx.args.get($sk).gt)'), (0, graphql_mapping_template_1.compoundExpression)([
|
501
|
+
(0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(`${queryExprReference}.expression`), (0, graphql_mapping_template_1.raw)(`"$${queryExprReference}.expression AND #sortKey > :sortKey"`)),
|
502
|
+
(0, graphql_mapping_template_1.qref)(`$${queryExprReference}.expressionNames.put("#sortKey", $sk)`),
|
503
|
+
(0, graphql_mapping_template_1.qref)(`$${queryExprReference}.expressionValues.put(":sortKey", $util.parseJson($util.dynamodb.toDynamoDBJson($ctx.args.get($sk).gt)))`),
|
504
|
+
])),
|
505
|
+
(0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.raw)('!$util.isNull($ctx.args.get($sk)) && !$util.isNull($ctx.args.get($sk).ge)'), (0, graphql_mapping_template_1.compoundExpression)([
|
506
|
+
(0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(`${queryExprReference}.expression`), (0, graphql_mapping_template_1.raw)(`"$${queryExprReference}.expression AND #sortKey >= :sortKey"`)),
|
507
|
+
(0, graphql_mapping_template_1.qref)(`$${queryExprReference}.expressionNames.put("#sortKey", $sk)`),
|
508
|
+
(0, graphql_mapping_template_1.qref)(`$${queryExprReference}.expressionValues.put(":sortKey", $util.parseJson($util.dynamodb.toDynamoDBJson($ctx.args.get($sk).ge)))`),
|
509
|
+
])),
|
510
|
+
]);
|
511
|
+
}
|
512
|
+
function makeSyncQueryResolver() {
|
513
|
+
const requestVariable = 'ctx.stash.QueryRequest';
|
514
|
+
const queryRequestVariables = 'ctx.stash.QueryRequestVariables';
|
515
|
+
const expressions = [];
|
516
|
+
expressions.push((0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.raw)('!$scan'), (0, graphql_mapping_template_1.compoundExpression)([
|
517
|
+
(0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)('limit'), (0, graphql_mapping_template_1.ref)(`util.defaultIfNull($context.args.limit, ${graphql_transformer_common_1.ResourceConstants.DEFAULT_PAGE_LIMIT})`)),
|
518
|
+
(0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(queryRequestVariables), (0, graphql_mapping_template_1.ref)('queryRequestVariables')),
|
519
|
+
(0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(requestVariable), (0, graphql_mapping_template_1.obj)({
|
520
|
+
version: (0, graphql_mapping_template_1.str)(graphql_mapping_template_1.RESOLVER_VERSION_ID),
|
521
|
+
operation: (0, graphql_mapping_template_1.str)('Sync'),
|
522
|
+
limit: (0, graphql_mapping_template_1.ref)('limit'),
|
523
|
+
lastSync: (0, graphql_mapping_template_1.ref)('util.defaultIfNull($ctx.args.lastSync, null)'),
|
524
|
+
query: (0, graphql_mapping_template_1.ref)(graphql_transformer_common_1.ResourceConstants.SNIPPETS.ModelQueryExpression),
|
525
|
+
})),
|
526
|
+
(0, graphql_mapping_template_1.ifElse)((0, graphql_mapping_template_1.raw)(`!$util.isNull($ctx.args.sortDirection)
|
527
|
+
&& $ctx.args.sortDirection == "DESC"`), (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(`${requestVariable}.scanIndexForward`), (0, graphql_mapping_template_1.bool)(false)), (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(`${requestVariable}.scanIndexForward`), (0, graphql_mapping_template_1.bool)(true))),
|
528
|
+
(0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.ref)('context.args.nextToken'), (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(`${requestVariable}.nextToken`), (0, graphql_mapping_template_1.ref)('context.args.nextToken')), true),
|
529
|
+
(0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.and)([(0, graphql_mapping_template_1.raw)('!$util.isNullOrEmpty($filterMap)'), (0, graphql_mapping_template_1.notEquals)((0, graphql_mapping_template_1.toJson)((0, graphql_mapping_template_1.ref)('filterMap')), (0, graphql_mapping_template_1.toJson)((0, graphql_mapping_template_1.obj)({})))]), (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(`${requestVariable}.filter`), (0, graphql_mapping_template_1.ref)('filterMap'))),
|
530
|
+
(0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.raw)('$index != "dbTable"'), (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(`${requestVariable}.index`), (0, graphql_mapping_template_1.ref)('index'))),
|
531
|
+
])), (0, graphql_mapping_template_1.raw)(`$util.toJson({})`));
|
532
|
+
return (0, graphql_mapping_template_1.block)(' Set query expression for @key', expressions);
|
533
|
+
}
|
534
|
+
function generateSyncResolverInit() {
|
535
|
+
const expressions = [];
|
536
|
+
const requestVariable = 'ctx.stash.QueryRequest';
|
537
|
+
expressions.push((0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)('index'), (0, graphql_mapping_template_1.str)('')), (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)('scan'), (0, graphql_mapping_template_1.bool)(true)), (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)('filterMap'), (0, graphql_mapping_template_1.obj)({})), (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)('QueryMap'), (0, graphql_mapping_template_1.obj)({})), (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)('PkMap'), (0, graphql_mapping_template_1.obj)({})), (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)('SkMap'), (0, graphql_mapping_template_1.obj)({})), (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)('filterArgsMap'), (0, graphql_mapping_template_1.obj)({})), (0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.ref)(requestVariable), (0, graphql_mapping_template_1.raw)('#return')), (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)('queryRequestVariables'), (0, graphql_mapping_template_1.obj)({})));
|
538
|
+
return (0, graphql_mapping_template_1.block)('Set map initialization for @key', expressions);
|
539
|
+
}
|
540
|
+
const generateAuthExpressionForSandboxMode = (enabled) => {
|
541
|
+
let exp;
|
542
|
+
if (enabled)
|
543
|
+
exp = (0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.notEquals)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('util.authType')), (0, graphql_mapping_template_1.str)(API_KEY)), (0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('util.unauthorized')));
|
544
|
+
else
|
545
|
+
exp = (0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('util.unauthorized'));
|
546
|
+
return (0, graphql_mapping_template_1.printBlock)(`Sandbox Mode ${enabled ? 'Enabled' : 'Disabled'}`)((0, graphql_mapping_template_1.compoundExpression)([(0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.not)((0, graphql_mapping_template_1.ref)('ctx.stash.get("hasAuth")')), exp), (0, graphql_mapping_template_1.toJson)((0, graphql_mapping_template_1.obj)({}))]));
|
547
|
+
};
|
548
|
+
exports.generateAuthExpressionForSandboxMode = generateAuthExpressionForSandboxMode;
|
549
|
+
function getDBInfo(ctx, modelName) {
|
550
|
+
const dbInfo = ctx.modelToDatasourceMap.get(modelName);
|
551
|
+
const result = dbInfo !== null && dbInfo !== void 0 ? dbInfo : { dbType: 'DDB', provisionDB: true };
|
552
|
+
return result;
|
553
|
+
}
|
554
|
+
exports.getDBInfo = getDBInfo;
|
555
|
+
function getDBType(ctx, modelName) {
|
556
|
+
const dbInfo = getDBInfo(ctx, modelName);
|
557
|
+
const dbType = dbInfo ? dbInfo.dbType : 'DDB';
|
558
|
+
return dbType;
|
559
|
+
}
|
560
|
+
exports.getDBType = getDBType;
|
561
|
+
const getVTLGenerator = (dbInfo) => {
|
562
|
+
const dbType = dbInfo ? dbInfo.dbType : 'DDB';
|
563
|
+
if (dbType === 'MySQL') {
|
564
|
+
return new generators_1.RDSIndexVTLGenerator();
|
565
|
+
}
|
566
|
+
return new generators_1.DynamoDBIndexVTLGenerator();
|
567
|
+
};
|
568
|
+
exports.getVTLGenerator = getVTLGenerator;
|
569
|
+
//# sourceMappingURL=resolvers.js.map
|