@aws-amplify/graphql-index-transformer 0.7.2-geo.0 → 0.8.0-gql-ext1.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +16 -2
- package/lib/graphql-index-transformer.js +9 -9
- package/lib/graphql-index-transformer.js.map +1 -1
- package/lib/graphql-primary-key-transformer.js +14 -14
- package/lib/graphql-primary-key-transformer.js.map +1 -1
- package/lib/resolvers.d.ts +1 -0
- package/lib/resolvers.d.ts.map +1 -1
- package/lib/resolvers.js +151 -140
- package/lib/resolvers.js.map +1 -1
- package/lib/schema.d.ts.map +1 -1
- package/lib/schema.js +44 -38
- package/lib/schema.js.map +1 -1
- package/lib/utils.js +1 -1
- package/lib/utils.js.map +1 -1
- package/package.json +7 -7
package/lib/resolvers.js
CHANGED
@@ -22,7 +22,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
22
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
23
23
|
};
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
25
|
-
exports.constructSyncVTL = exports.updateResolversForIndex = exports.appendSecondaryIndex = exports.updateResolvers = exports.replaceDdbPrimaryKey = void 0;
|
25
|
+
exports.generateAuthExpressionForSandboxMode = exports.constructSyncVTL = exports.updateResolversForIndex = exports.appendSecondaryIndex = exports.updateResolvers = exports.replaceDdbPrimaryKey = void 0;
|
26
26
|
const assert_1 = __importDefault(require("assert"));
|
27
27
|
const graphql_model_transformer_1 = require("@aws-amplify/graphql-model-transformer");
|
28
28
|
const graphql_transformer_core_1 = require("@aws-amplify/graphql-transformer-core");
|
@@ -31,6 +31,7 @@ const graphql_1 = require("graphql");
|
|
31
31
|
const graphql_mapping_template_1 = require("graphql-mapping-template");
|
32
32
|
const graphql_transformer_common_1 = require("graphql-transformer-common");
|
33
33
|
const utils_1 = require("./utils");
|
34
|
+
const API_KEY = 'API Key Authorization';
|
34
35
|
function replaceDdbPrimaryKey(config, ctx) {
|
35
36
|
var _a, _b, _c;
|
36
37
|
const { field, object } = config;
|
@@ -74,7 +75,7 @@ function updateResolvers(config, ctx, resolverMap) {
|
|
74
75
|
}
|
75
76
|
if (listResolver) {
|
76
77
|
addIndexToResolverSlot(listResolver, [
|
77
|
-
graphql_mapping_template_1.print(setQuerySnippet(config, ctx, true)),
|
78
|
+
(0, graphql_mapping_template_1.print)(setQuerySnippet(config, ctx, true)),
|
78
79
|
`$util.qr($ctx.stash.put("${graphql_transformer_common_1.ResourceConstants.SNIPPETS.ModelQueryExpression}", $${graphql_transformer_common_1.ResourceConstants.SNIPPETS.ModelQueryExpression}))`,
|
79
80
|
]);
|
80
81
|
}
|
@@ -104,7 +105,7 @@ function getTable(context, object) {
|
|
104
105
|
const ddbDataSource = context.dataSources.get(object);
|
105
106
|
const tableName = graphql_transformer_common_1.ModelResourceIDs.ModelTableResourceID(object.name.value);
|
106
107
|
const table = ddbDataSource.ds.stack.node.findChild(tableName);
|
107
|
-
assert_1.default(table);
|
108
|
+
(0, assert_1.default)(table);
|
108
109
|
return table;
|
109
110
|
}
|
110
111
|
function getDdbKeySchema(config) {
|
@@ -115,12 +116,12 @@ function getDdbKeySchema(config) {
|
|
115
116
|
return schema;
|
116
117
|
}
|
117
118
|
function attributeTypeFromType(type, ctx) {
|
118
|
-
const baseTypeName = graphql_transformer_common_1.getBaseType(type);
|
119
|
+
const baseTypeName = (0, graphql_transformer_common_1.getBaseType)(type);
|
119
120
|
const ofType = ctx.output.getType(baseTypeName);
|
120
121
|
if (ofType && ofType.kind === graphql_1.Kind.ENUM_TYPE_DEFINITION) {
|
121
122
|
return 'S';
|
122
123
|
}
|
123
|
-
return graphql_transformer_common_1.attributeTypeFromScalar(type);
|
124
|
+
return (0, graphql_transformer_common_1.attributeTypeFromScalar)(type);
|
124
125
|
}
|
125
126
|
function attributeDefinitions(config, ctx) {
|
126
127
|
const { field, sortKey, sortKeyFields } = config;
|
@@ -144,7 +145,7 @@ function getSortKeyName(config) {
|
|
144
145
|
}
|
145
146
|
function getResolverObject(config, ctx, op) {
|
146
147
|
var _a;
|
147
|
-
const resolverName = utils_1.lookupResolverName(config, ctx, op);
|
148
|
+
const resolverName = (0, utils_1.lookupResolverName)(config, ctx, op);
|
148
149
|
if (!resolverName) {
|
149
150
|
return null;
|
150
151
|
}
|
@@ -156,15 +157,15 @@ function getResolverObject(config, ctx, op) {
|
|
156
157
|
}
|
157
158
|
function setPrimaryKeySnippet(config, isMutation) {
|
158
159
|
const cmds = [
|
159
|
-
graphql_mapping_template_1.qref(graphql_mapping_template_1.methodCall(graphql_mapping_template_1.ref('ctx.stash.metadata.put'), graphql_mapping_template_1.str(graphql_transformer_common_1.ResourceConstants.SNIPPETS.ModelObjectKey), modelObjectKeySnippet(config, isMutation))),
|
160
|
+
(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))),
|
160
161
|
];
|
161
|
-
return graphql_mapping_template_1.printBlock('Set the primary key')(graphql_mapping_template_1.compoundExpression(cmds));
|
162
|
+
return (0, graphql_mapping_template_1.printBlock)('Set the primary key')((0, graphql_mapping_template_1.compoundExpression)(cmds));
|
162
163
|
}
|
163
164
|
function modelObjectKeySnippet(config, isMutation) {
|
164
165
|
const { field, sortKeyFields } = config;
|
165
166
|
const argsPrefix = isMutation ? 'mergedValues' : 'ctx.args';
|
166
167
|
const modelObject = {
|
167
|
-
[field.name.value]: graphql_mapping_template_1.ref(`util.dynamodb.toDynamoDB($${argsPrefix}.${field.name.value})`),
|
168
|
+
[field.name.value]: (0, graphql_mapping_template_1.ref)(`util.dynamodb.toDynamoDB($${argsPrefix}.${field.name.value})`),
|
168
169
|
};
|
169
170
|
if (sortKeyFields.length > 1) {
|
170
171
|
const compositeSortKey = getSortKeyName(config);
|
@@ -173,12 +174,12 @@ function modelObjectKeySnippet(config, isMutation) {
|
|
173
174
|
return `\${${argsPrefix}.${keyField}}`;
|
174
175
|
})
|
175
176
|
.join(graphql_transformer_common_1.ModelResourceIDs.ModelCompositeKeySeparator());
|
176
|
-
modelObject[compositeSortKey] = graphql_mapping_template_1.ref(`util.dynamodb.toDynamoDB("${compositeSortKeyValue}")`);
|
177
|
+
modelObject[compositeSortKey] = (0, graphql_mapping_template_1.ref)(`util.dynamodb.toDynamoDB("${compositeSortKeyValue}")`);
|
177
178
|
}
|
178
179
|
else if (sortKeyFields.length === 1) {
|
179
|
-
modelObject[sortKeyFields[0]] = graphql_mapping_template_1.ref(`util.dynamodb.toDynamoDB($${argsPrefix}.${sortKeyFields[0]})`);
|
180
|
+
modelObject[sortKeyFields[0]] = (0, graphql_mapping_template_1.ref)(`util.dynamodb.toDynamoDB($${argsPrefix}.${sortKeyFields[0]})`);
|
180
181
|
}
|
181
|
-
return graphql_mapping_template_1.obj(modelObject);
|
182
|
+
return (0, graphql_mapping_template_1.obj)(modelObject);
|
182
183
|
}
|
183
184
|
function ensureCompositeKeySnippet(config, conditionallySetSortKey) {
|
184
185
|
const { sortKeyFields } = config;
|
@@ -187,19 +188,19 @@ function ensureCompositeKeySnippet(config, conditionallySetSortKey) {
|
|
187
188
|
}
|
188
189
|
const argsPrefix = 'mergedValues';
|
189
190
|
const condensedSortKey = getSortKeyName(config);
|
190
|
-
const dynamoDBFriendlySortKeyName = graphql_transformer_common_1.toCamelCase(sortKeyFields.map(f => graphql_transformer_common_1.graphqlName(f)));
|
191
|
+
const dynamoDBFriendlySortKeyName = (0, graphql_transformer_common_1.toCamelCase)(sortKeyFields.map(f => (0, graphql_transformer_common_1.graphqlName)(f)));
|
191
192
|
const condensedSortKeyValue = sortKeyFields
|
192
193
|
.map(keyField => {
|
193
194
|
return `\${${argsPrefix}.${keyField}}`;
|
194
195
|
})
|
195
196
|
.join(graphql_transformer_common_1.ModelResourceIDs.ModelCompositeKeySeparator());
|
196
|
-
return graphql_mapping_template_1.print(graphql_mapping_template_1.compoundExpression([
|
197
|
-
graphql_mapping_template_1.ifElse(graphql_mapping_template_1.raw(`$util.isNull($ctx.stash.metadata.${graphql_transformer_common_1.ResourceConstants.SNIPPETS.DynamoDBNameOverrideMap})`), graphql_mapping_template_1.qref(graphql_mapping_template_1.methodCall(graphql_mapping_template_1.ref('ctx.stash.metadata.put'), graphql_mapping_template_1.str(graphql_transformer_common_1.ResourceConstants.SNIPPETS.DynamoDBNameOverrideMap), graphql_mapping_template_1.obj({
|
198
|
-
[condensedSortKey]: graphql_mapping_template_1.str(dynamoDBFriendlySortKeyName),
|
199
|
-
}))), graphql_mapping_template_1.qref(graphql_mapping_template_1.methodCall(graphql_mapping_template_1.ref(`ctx.stash.metadata.${graphql_transformer_common_1.ResourceConstants.SNIPPETS.DynamoDBNameOverrideMap}.put`), graphql_mapping_template_1.str(condensedSortKey), graphql_mapping_template_1.str(dynamoDBFriendlySortKeyName)))),
|
197
|
+
return (0, graphql_mapping_template_1.print)((0, graphql_mapping_template_1.compoundExpression)([
|
198
|
+
(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.obj)({
|
199
|
+
[condensedSortKey]: (0, graphql_mapping_template_1.str)(dynamoDBFriendlySortKeyName),
|
200
|
+
}))), (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.str)(condensedSortKey), (0, graphql_mapping_template_1.str)(dynamoDBFriendlySortKeyName)))),
|
200
201
|
conditionallySetSortKey
|
201
|
-
? graphql_mapping_template_1.iff(graphql_mapping_template_1.ref(graphql_transformer_common_1.ResourceConstants.SNIPPETS.HasSeenSomeKeyArg), graphql_mapping_template_1.qref(`$ctx.args.input.put("${condensedSortKey}","${condensedSortKeyValue}")`))
|
202
|
-
: graphql_mapping_template_1.qref(`$ctx.args.input.put("${condensedSortKey}","${condensedSortKeyValue}")`),
|
202
|
+
? (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}")`))
|
203
|
+
: (0, graphql_mapping_template_1.qref)(`$ctx.args.input.put("${condensedSortKey}","${condensedSortKeyValue}")`),
|
203
204
|
]));
|
204
205
|
}
|
205
206
|
function setQuerySnippet(config, ctx, isListResolver) {
|
@@ -209,15 +210,15 @@ function setQuerySnippet(config, ctx, isListResolver) {
|
|
209
210
|
const keyTypes = keyFields.map(k => attributeTypeFromType(k.type, ctx));
|
210
211
|
const expressions = [];
|
211
212
|
if (keyNames.length === 1) {
|
212
|
-
const sortDirectionValidation = graphql_mapping_template_1.iff(graphql_mapping_template_1.raw(`!$util.isNull($ctx.args.sortDirection)`), graphql_mapping_template_1.raw(`$util.error("sortDirection is not supported for List operations without a Sort key defined.", "InvalidArgumentsError")`));
|
213
|
+
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")`));
|
213
214
|
expressions.push(sortDirectionValidation);
|
214
215
|
}
|
215
216
|
else if (isListResolver === true && keyNames.length >= 1) {
|
216
|
-
const sortDirectionValidation = graphql_mapping_template_1.iff(graphql_mapping_template_1.and([graphql_mapping_template_1.raw(`$util.isNull($ctx.args.${keyNames[0]})`), graphql_mapping_template_1.raw(`!$util.isNull($ctx.args.sortDirection)`)]), graphql_mapping_template_1.raw(`$util.error("When providing argument 'sortDirection' you must also provide argument '${keyNames[0]}'.", "InvalidArgumentsError")`));
|
217
|
+
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")`));
|
217
218
|
expressions.push(sortDirectionValidation);
|
218
219
|
}
|
219
|
-
expressions.push(graphql_mapping_template_1.set(graphql_mapping_template_1.ref(graphql_transformer_common_1.ResourceConstants.SNIPPETS.ModelQueryExpression), graphql_mapping_template_1.obj({})), graphql_transformer_common_1.applyKeyExpressionForCompositeKey(keyNames, keyTypes, graphql_transformer_common_1.ResourceConstants.SNIPPETS.ModelQueryExpression));
|
220
|
-
return graphql_mapping_template_1.block(`Set query expression for key`, expressions);
|
220
|
+
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));
|
221
|
+
return (0, graphql_mapping_template_1.block)(`Set query expression for key`, expressions);
|
221
222
|
}
|
222
223
|
function appendSecondaryIndex(config, ctx) {
|
223
224
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
@@ -317,38 +318,39 @@ function makeQueryResolver(config, ctx) {
|
|
317
318
|
const dataSource = ctx.api.host.getDataSource(`${object.name.value}Table`);
|
318
319
|
const queryTypeName = ctx.output.getQueryTypeName();
|
319
320
|
const table = getTable(ctx, object);
|
320
|
-
const authFilter = graphql_mapping_template_1.ref('ctx.stash.authFilter');
|
321
|
+
const authFilter = (0, graphql_mapping_template_1.ref)('ctx.stash.authFilter');
|
321
322
|
const requestVariable = 'QueryRequest';
|
322
|
-
assert_1.default(dataSource);
|
323
|
-
const resolver = ctx.resolvers.generateQueryResolver(queryTypeName, queryField, graphql_transformer_common_1.ResolverResourceIDs.ResolverResourceID(queryTypeName, queryField), dataSource, graphql_transformer_core_1.MappingTemplate.s3MappingTemplateFromString(graphql_mapping_template_1.print(graphql_mapping_template_1.compoundExpression([
|
323
|
+
(0, assert_1.default)(dataSource);
|
324
|
+
const resolver = ctx.resolvers.generateQueryResolver(queryTypeName, queryField, graphql_transformer_common_1.ResolverResourceIDs.ResolverResourceID(queryTypeName, queryField), dataSource, graphql_transformer_core_1.MappingTemplate.s3MappingTemplateFromString((0, graphql_mapping_template_1.print)((0, graphql_mapping_template_1.compoundExpression)([
|
324
325
|
setQuerySnippet(config, ctx, false),
|
325
|
-
graphql_mapping_template_1.set(graphql_mapping_template_1.ref('limit'), graphql_mapping_template_1.ref(`util.defaultIfNull($context.args.limit, ${graphql_transformer_common_1.ResourceConstants.DEFAULT_PAGE_LIMIT})`)),
|
326
|
-
graphql_mapping_template_1.set(graphql_mapping_template_1.ref(requestVariable), graphql_mapping_template_1.obj({
|
327
|
-
version: graphql_mapping_template_1.str(graphql_mapping_template_1.RESOLVER_VERSION_ID),
|
328
|
-
operation: graphql_mapping_template_1.str('Query'),
|
329
|
-
limit: graphql_mapping_template_1.ref('limit'),
|
330
|
-
query: graphql_mapping_template_1.ref(graphql_transformer_common_1.ResourceConstants.SNIPPETS.ModelQueryExpression),
|
331
|
-
index: graphql_mapping_template_1.str(name),
|
326
|
+
(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})`)),
|
327
|
+
(0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(requestVariable), (0, graphql_mapping_template_1.obj)({
|
328
|
+
version: (0, graphql_mapping_template_1.str)(graphql_mapping_template_1.RESOLVER_VERSION_ID),
|
329
|
+
operation: (0, graphql_mapping_template_1.str)('Query'),
|
330
|
+
limit: (0, graphql_mapping_template_1.ref)('limit'),
|
331
|
+
query: (0, graphql_mapping_template_1.ref)(graphql_transformer_common_1.ResourceConstants.SNIPPETS.ModelQueryExpression),
|
332
|
+
index: (0, graphql_mapping_template_1.str)(name),
|
332
333
|
})),
|
333
|
-
graphql_mapping_template_1.ifElse(graphql_mapping_template_1.raw(`!$util.isNull($ctx.args.sortDirection)
|
334
|
-
&& $ctx.args.sortDirection == "DESC"`), graphql_mapping_template_1.set(graphql_mapping_template_1.ref(`${requestVariable}.scanIndexForward`), graphql_mapping_template_1.bool(false)), graphql_mapping_template_1.set(graphql_mapping_template_1.ref(`${requestVariable}.scanIndexForward`), graphql_mapping_template_1.bool(true))),
|
335
|
-
graphql_mapping_template_1.iff(graphql_mapping_template_1.ref('context.args.nextToken'), graphql_mapping_template_1.set(graphql_mapping_template_1.ref(`${requestVariable}.nextToken`), graphql_mapping_template_1.ref('context.args.nextToken')), true),
|
336
|
-
graphql_mapping_template_1.ifElse(graphql_mapping_template_1.not(graphql_mapping_template_1.isNullOrEmpty(authFilter)), graphql_mapping_template_1.compoundExpression([
|
337
|
-
graphql_mapping_template_1.set(graphql_mapping_template_1.ref('filter'), authFilter),
|
338
|
-
graphql_mapping_template_1.iff(graphql_mapping_template_1.not(graphql_mapping_template_1.isNullOrEmpty(graphql_mapping_template_1.ref('ctx.args.filter'))), graphql_mapping_template_1.set(graphql_mapping_template_1.ref('filter'), graphql_mapping_template_1.obj({ and: graphql_mapping_template_1.list([graphql_mapping_template_1.ref('filter'), graphql_mapping_template_1.ref('ctx.args.filter')]) }))),
|
339
|
-
]), graphql_mapping_template_1.iff(graphql_mapping_template_1.not(graphql_mapping_template_1.isNullOrEmpty(graphql_mapping_template_1.ref('ctx.args.filter'))), graphql_mapping_template_1.set(graphql_mapping_template_1.ref('filter'), graphql_mapping_template_1.ref('ctx.args.filter')))),
|
340
|
-
graphql_mapping_template_1.iff(graphql_mapping_template_1.not(graphql_mapping_template_1.isNullOrEmpty(graphql_mapping_template_1.ref('filter'))), graphql_mapping_template_1.compoundExpression([
|
341
|
-
graphql_mapping_template_1.set(graphql_mapping_template_1.ref(`filterExpression`), graphql_mapping_template_1.methodCall(graphql_mapping_template_1.ref('util.parseJson'), graphql_mapping_template_1.methodCall(graphql_mapping_template_1.ref('util.transform.toDynamoDBFilterExpression'), graphql_mapping_template_1.ref('filter')))),
|
342
|
-
graphql_mapping_template_1.iff(graphql_mapping_template_1.not(graphql_mapping_template_1.methodCall(graphql_mapping_template_1.ref('util.isNullOrBlank'), graphql_mapping_template_1.ref('filterExpression.expression'))), graphql_mapping_template_1.compoundExpression([
|
343
|
-
graphql_mapping_template_1.iff(graphql_mapping_template_1.equals(graphql_mapping_template_1.methodCall(graphql_mapping_template_1.ref('filterEpression.expressionValues.size')), graphql_mapping_template_1.int(0)), graphql_mapping_template_1.qref(graphql_mapping_template_1.methodCall(graphql_mapping_template_1.ref('filterEpression.remove'), graphql_mapping_template_1.str('expressionValues')))),
|
344
|
-
graphql_mapping_template_1.set(graphql_mapping_template_1.ref(`${requestVariable}.filter`), graphql_mapping_template_1.ref(`filterExpression`)),
|
334
|
+
(0, graphql_mapping_template_1.ifElse)((0, graphql_mapping_template_1.raw)(`!$util.isNull($ctx.args.sortDirection)
|
335
|
+
&& $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))),
|
336
|
+
(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),
|
337
|
+
(0, graphql_mapping_template_1.ifElse)((0, graphql_mapping_template_1.not)((0, graphql_mapping_template_1.isNullOrEmpty)(authFilter)), (0, graphql_mapping_template_1.compoundExpression)([
|
338
|
+
(0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)('filter'), authFilter),
|
339
|
+
(0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.not)((0, graphql_mapping_template_1.isNullOrEmpty)((0, graphql_mapping_template_1.ref)('ctx.args.filter'))), (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)('filter'), (0, graphql_mapping_template_1.obj)({ and: (0, graphql_mapping_template_1.list)([(0, graphql_mapping_template_1.ref)('filter'), (0, graphql_mapping_template_1.ref)('ctx.args.filter')]) }))),
|
340
|
+
]), (0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.not)((0, graphql_mapping_template_1.isNullOrEmpty)((0, graphql_mapping_template_1.ref)('ctx.args.filter'))), (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)('filter'), (0, graphql_mapping_template_1.ref)('ctx.args.filter')))),
|
341
|
+
(0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.not)((0, graphql_mapping_template_1.isNullOrEmpty)((0, graphql_mapping_template_1.ref)('filter'))), (0, graphql_mapping_template_1.compoundExpression)([
|
342
|
+
(0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(`filterExpression`), (0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('util.parseJson'), (0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('util.transform.toDynamoDBFilterExpression'), (0, graphql_mapping_template_1.ref)('filter')))),
|
343
|
+
(0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.not)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('util.isNullOrBlank'), (0, graphql_mapping_template_1.ref)('filterExpression.expression'))), (0, graphql_mapping_template_1.compoundExpression)([
|
344
|
+
(0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.equals)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('filterEpression.expressionValues.size')), (0, graphql_mapping_template_1.int)(0)), (0, graphql_mapping_template_1.qref)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('filterEpression.remove'), (0, graphql_mapping_template_1.str)('expressionValues')))),
|
345
|
+
(0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(`${requestVariable}.filter`), (0, graphql_mapping_template_1.ref)(`filterExpression`)),
|
345
346
|
])),
|
346
347
|
])),
|
347
|
-
graphql_mapping_template_1.raw(`$util.toJson($${requestVariable})`),
|
348
|
-
])), `${queryTypeName}.${queryField}.req.vtl`), graphql_transformer_core_1.MappingTemplate.s3MappingTemplateFromString(graphql_mapping_template_1.print(graphql_mapping_template_1.compoundExpression([
|
349
|
-
graphql_mapping_template_1.iff(graphql_mapping_template_1.ref('ctx.error'), graphql_mapping_template_1.raw('$util.error($ctx.error.message, $ctx.error.type)')),
|
350
|
-
graphql_mapping_template_1.raw('$util.toJson($ctx.result)'),
|
348
|
+
(0, graphql_mapping_template_1.raw)(`$util.toJson($${requestVariable})`),
|
349
|
+
])), `${queryTypeName}.${queryField}.req.vtl`), graphql_transformer_core_1.MappingTemplate.s3MappingTemplateFromString((0, graphql_mapping_template_1.print)((0, graphql_mapping_template_1.compoundExpression)([
|
350
|
+
(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)')),
|
351
|
+
(0, graphql_mapping_template_1.raw)('$util.toJson($ctx.result)'),
|
351
352
|
])), `${queryTypeName}.${queryField}.res.vtl`));
|
353
|
+
resolver.addToSlot('postAuth', graphql_transformer_core_1.MappingTemplate.s3MappingTemplateFromString((0, exports.generateAuthExpressionForSandboxMode)(ctx.sandboxModeEnabled), `${queryTypeName}.${queryField}.{slotName}.{slotIndex}.res.vtl`));
|
352
354
|
resolver.mapToStack(table.stack);
|
353
355
|
ctx.resolvers.addResolver(object.name.value, queryField, resolver);
|
354
356
|
}
|
@@ -357,20 +359,20 @@ function validateIndexArgumentSnippet(config, keyOperation) {
|
|
357
359
|
if (sortKeyFields.length < 2) {
|
358
360
|
return '';
|
359
361
|
}
|
360
|
-
return graphql_mapping_template_1.printBlock(`Validate ${keyOperation} mutation for @index '${name}'`)(graphql_mapping_template_1.compoundExpression([
|
361
|
-
graphql_mapping_template_1.set(graphql_mapping_template_1.ref(graphql_transformer_common_1.ResourceConstants.SNIPPETS.HasSeenSomeKeyArg), graphql_mapping_template_1.bool(false)),
|
362
|
-
graphql_mapping_template_1.set(graphql_mapping_template_1.ref('keyFieldNames'), graphql_mapping_template_1.list(sortKeyFields.map(f => graphql_mapping_template_1.str(f)))),
|
363
|
-
graphql_mapping_template_1.forEach(graphql_mapping_template_1.ref('keyFieldName'), graphql_mapping_template_1.ref('keyFieldNames'), [
|
364
|
-
graphql_mapping_template_1.iff(graphql_mapping_template_1.raw(`$ctx.args.input.containsKey("$keyFieldName")`), graphql_mapping_template_1.set(graphql_mapping_template_1.ref(graphql_transformer_common_1.ResourceConstants.SNIPPETS.HasSeenSomeKeyArg), graphql_mapping_template_1.bool(true)), true),
|
362
|
+
return (0, graphql_mapping_template_1.printBlock)(`Validate ${keyOperation} mutation for @index '${name}'`)((0, graphql_mapping_template_1.compoundExpression)([
|
363
|
+
(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)),
|
364
|
+
(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)))),
|
365
|
+
(0, graphql_mapping_template_1.forEach)((0, graphql_mapping_template_1.ref)('keyFieldName'), (0, graphql_mapping_template_1.ref)('keyFieldNames'), [
|
366
|
+
(0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.raw)(`$ctx.args.input.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),
|
365
367
|
]),
|
366
|
-
graphql_mapping_template_1.forEach(graphql_mapping_template_1.ref('keyFieldName'), graphql_mapping_template_1.ref('keyFieldNames'), [
|
367
|
-
graphql_mapping_template_1.iff(graphql_mapping_template_1.raw(`$${graphql_transformer_common_1.ResourceConstants.SNIPPETS.HasSeenSomeKeyArg} && !$ctx.args.input.containsKey("$keyFieldName")`), graphql_mapping_template_1.raw(`$util.error("When ${keyOperation.replace(/.$/, 'ing')} any part of the composite sort key for @index '${name}',` +
|
368
|
+
(0, graphql_mapping_template_1.forEach)((0, graphql_mapping_template_1.ref)('keyFieldName'), (0, graphql_mapping_template_1.ref)('keyFieldNames'), [
|
369
|
+
(0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.raw)(`$${graphql_transformer_common_1.ResourceConstants.SNIPPETS.HasSeenSomeKeyArg} && !$ctx.args.input.containsKey("$keyFieldName")`), (0, graphql_mapping_template_1.raw)(`$util.error("When ${keyOperation.replace(/.$/, 'ing')} any part of the composite sort key for @index '${name}',` +
|
368
370
|
` you must provide all fields for the key. Missing key: '$keyFieldName'.")`)),
|
369
371
|
]),
|
370
372
|
]));
|
371
373
|
}
|
372
374
|
function mergeInputsAndDefaultsSnippet() {
|
373
|
-
return graphql_mapping_template_1.printBlock('Merge default values and inputs')(graphql_model_transformer_1.generateApplyDefaultsToInputTemplate('mergedValues'));
|
375
|
+
return (0, graphql_mapping_template_1.printBlock)('Merge default values and inputs')((0, graphql_model_transformer_1.generateApplyDefaultsToInputTemplate)('mergedValues'));
|
374
376
|
}
|
375
377
|
function addIndexToResolverSlot(resolver, lines, isSync = false) {
|
376
378
|
const res = resolver;
|
@@ -381,10 +383,10 @@ function makeSyncResolver(name, config, ctx, syncResolver, resolverMap) {
|
|
381
383
|
return;
|
382
384
|
if (resolverMap.has(syncResolver)) {
|
383
385
|
const prevSnippet = resolverMap.get(syncResolver);
|
384
|
-
resolverMap.set(syncResolver, joinSnippets([prevSnippet, graphql_mapping_template_1.print(setSyncQueryMapSnippet(name, config))]));
|
386
|
+
resolverMap.set(syncResolver, joinSnippets([prevSnippet, (0, graphql_mapping_template_1.print)(setSyncQueryMapSnippet(name, config))]));
|
385
387
|
}
|
386
388
|
else {
|
387
|
-
resolverMap.set(syncResolver, graphql_mapping_template_1.print(setSyncQueryMapSnippet(name, config)));
|
389
|
+
resolverMap.set(syncResolver, (0, graphql_mapping_template_1.print)(setSyncQueryMapSnippet(name, config)));
|
388
390
|
}
|
389
391
|
}
|
390
392
|
function joinSnippets(lines) {
|
@@ -394,124 +396,133 @@ function setSyncQueryMapSnippet(name, config) {
|
|
394
396
|
const { field, sortKeyFields } = config;
|
395
397
|
const expressions = [];
|
396
398
|
const keys = [field.name.value, ...(sortKeyFields !== null && sortKeyFields !== void 0 ? sortKeyFields : [])];
|
397
|
-
expressions.push(graphql_mapping_template_1.raw(`$util.qr($QueryMap.put('${keys.join('+')}' , '${name}'))`), graphql_mapping_template_1.raw(`$util.qr($PkMap.put('${field.name.value}' , '${name}'))`));
|
398
|
-
return graphql_mapping_template_1.block(`Set query expression for @key`, expressions);
|
399
|
+
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}'))`));
|
400
|
+
return (0, graphql_mapping_template_1.block)(`Set query expression for @key`, expressions);
|
399
401
|
}
|
400
402
|
function constructSyncVTL(syncVTLContent, resolver) {
|
401
403
|
const checks = [
|
402
|
-
graphql_mapping_template_1.print(generateSyncResolverInit()),
|
404
|
+
(0, graphql_mapping_template_1.print)(generateSyncResolverInit()),
|
403
405
|
syncVTLContent,
|
404
|
-
graphql_mapping_template_1.print(setSyncQueryFilterSnippet()),
|
405
|
-
graphql_mapping_template_1.print(setSyncKeyExpressionForHashKey(graphql_transformer_common_1.ResourceConstants.SNIPPETS.ModelQueryExpression)),
|
406
|
-
graphql_mapping_template_1.print(setSyncKeyExpressionForRangeKey(graphql_transformer_common_1.ResourceConstants.SNIPPETS.ModelQueryExpression)),
|
407
|
-
graphql_mapping_template_1.print(makeSyncQueryResolver()),
|
406
|
+
(0, graphql_mapping_template_1.print)(setSyncQueryFilterSnippet()),
|
407
|
+
(0, graphql_mapping_template_1.print)(setSyncKeyExpressionForHashKey(graphql_transformer_common_1.ResourceConstants.SNIPPETS.ModelQueryExpression)),
|
408
|
+
(0, graphql_mapping_template_1.print)(setSyncKeyExpressionForRangeKey(graphql_transformer_common_1.ResourceConstants.SNIPPETS.ModelQueryExpression)),
|
409
|
+
(0, graphql_mapping_template_1.print)(makeSyncQueryResolver()),
|
408
410
|
];
|
409
411
|
addIndexToResolverSlot(resolver, checks, true);
|
410
412
|
}
|
411
413
|
exports.constructSyncVTL = constructSyncVTL;
|
412
414
|
function setSyncQueryFilterSnippet() {
|
413
415
|
const expressions = [];
|
414
|
-
expressions.push(graphql_mapping_template_1.compoundExpression([
|
415
|
-
graphql_mapping_template_1.set(graphql_mapping_template_1.ref('filterArgsMap'), graphql_mapping_template_1.ref('ctx.args.filter.get("and")')),
|
416
|
-
graphql_mapping_template_1.ifElse(graphql_mapping_template_1.raw(`!$util.isNullOrEmpty($filterArgsMap) && ($util.isNull($ctx.args.lastSync) || $ctx.args.lastSync == 0)`), graphql_mapping_template_1.compoundExpression([
|
417
|
-
graphql_mapping_template_1.set(graphql_mapping_template_1.ref('json'), graphql_mapping_template_1.raw(`$filterArgsMap`)),
|
418
|
-
graphql_mapping_template_1.forEach(graphql_mapping_template_1.ref('item'), graphql_mapping_template_1.ref(`json`), [
|
419
|
-
graphql_mapping_template_1.set(graphql_mapping_template_1.ref('ind'), graphql_mapping_template_1.ref('foreach.index')),
|
420
|
-
graphql_mapping_template_1.forEach(graphql_mapping_template_1.ref('entry'), graphql_mapping_template_1.ref('item.entrySet()'), [
|
421
|
-
graphql_mapping_template_1.iff(graphql_mapping_template_1.raw(`$ind == 0 && !$util.isNullOrEmpty($entry.value.eq) && !$util.isNullOrEmpty($PkMap.get($entry.key))`), graphql_mapping_template_1.compoundExpression([
|
422
|
-
graphql_mapping_template_1.set(graphql_mapping_template_1.ref('pk'), graphql_mapping_template_1.ref('entry.key')),
|
423
|
-
graphql_mapping_template_1.set(graphql_mapping_template_1.ref('scan'), graphql_mapping_template_1.bool(false)),
|
424
|
-
graphql_mapping_template_1.raw('$util.qr($ctx.args.put($pk,$entry.value.eq))'),
|
425
|
-
graphql_mapping_template_1.set(graphql_mapping_template_1.ref('index'), graphql_mapping_template_1.ref('PkMap.get($pk)')),
|
416
|
+
expressions.push((0, graphql_mapping_template_1.compoundExpression)([
|
417
|
+
(0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)('filterArgsMap'), (0, graphql_mapping_template_1.ref)('ctx.args.filter.get("and")')),
|
418
|
+
(0, graphql_mapping_template_1.ifElse)((0, graphql_mapping_template_1.raw)(`!$util.isNullOrEmpty($filterArgsMap) && ($util.isNull($ctx.args.lastSync) || $ctx.args.lastSync == 0)`), (0, graphql_mapping_template_1.compoundExpression)([
|
419
|
+
(0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)('json'), (0, graphql_mapping_template_1.raw)(`$filterArgsMap`)),
|
420
|
+
(0, graphql_mapping_template_1.forEach)((0, graphql_mapping_template_1.ref)('item'), (0, graphql_mapping_template_1.ref)(`json`), [
|
421
|
+
(0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)('ind'), (0, graphql_mapping_template_1.ref)('foreach.index')),
|
422
|
+
(0, graphql_mapping_template_1.forEach)((0, graphql_mapping_template_1.ref)('entry'), (0, graphql_mapping_template_1.ref)('item.entrySet()'), [
|
423
|
+
(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)([
|
424
|
+
(0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)('pk'), (0, graphql_mapping_template_1.ref)('entry.key')),
|
425
|
+
(0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)('scan'), (0, graphql_mapping_template_1.bool)(false)),
|
426
|
+
(0, graphql_mapping_template_1.raw)('$util.qr($ctx.args.put($pk,$entry.value.eq))'),
|
427
|
+
(0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)('index'), (0, graphql_mapping_template_1.ref)('PkMap.get($pk)')),
|
426
428
|
])),
|
427
|
-
graphql_mapping_template_1.ifElse(graphql_mapping_template_1.raw('$ind == 1 && !$util.isNullOrEmpty($pk) && !$util.isNullOrEmpty($QueryMap.get("${pk}+$entry.key"))'), graphql_mapping_template_1.compoundExpression([
|
428
|
-
graphql_mapping_template_1.set(graphql_mapping_template_1.ref('sk'), graphql_mapping_template_1.ref('entry.key')),
|
429
|
-
graphql_mapping_template_1.raw('$util.qr($ctx.args.put($sk,$entry.value))'),
|
430
|
-
graphql_mapping_template_1.set(graphql_mapping_template_1.ref('index'), graphql_mapping_template_1.ref('QueryMap.get("${pk}+$sk")')),
|
431
|
-
]), graphql_mapping_template_1.iff(graphql_mapping_template_1.raw('$ind > 0'), graphql_mapping_template_1.qref('$filterMap.put($entry.key,$entry.value)'))),
|
429
|
+
(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)([
|
430
|
+
(0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)('sk'), (0, graphql_mapping_template_1.ref)('entry.key')),
|
431
|
+
(0, graphql_mapping_template_1.raw)('$util.qr($ctx.args.put($sk,$entry.value))'),
|
432
|
+
(0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)('index'), (0, graphql_mapping_template_1.ref)('QueryMap.get("${pk}+$sk")')),
|
433
|
+
]), (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)'))),
|
432
434
|
]),
|
433
435
|
]),
|
434
|
-
]), graphql_mapping_template_1.set(graphql_mapping_template_1.ref(`filterMap`), graphql_mapping_template_1.raw(`$ctx.args.filter`))),
|
436
|
+
]), (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(`filterMap`), (0, graphql_mapping_template_1.raw)(`$ctx.args.filter`))),
|
435
437
|
]));
|
436
|
-
return graphql_mapping_template_1.block(`Set query expression for @key`, expressions);
|
438
|
+
return (0, graphql_mapping_template_1.block)(`Set query expression for @key`, expressions);
|
437
439
|
}
|
438
440
|
function setSyncKeyExpressionForHashKey(queryExprReference) {
|
439
441
|
const expressions = [];
|
440
|
-
expressions.push(graphql_mapping_template_1.set(graphql_mapping_template_1.ref(graphql_transformer_common_1.ResourceConstants.SNIPPETS.ModelQueryExpression), graphql_mapping_template_1.obj({})), graphql_mapping_template_1.iff(graphql_mapping_template_1.raw(`!$util.isNull($pk)`), graphql_mapping_template_1.compoundExpression([
|
441
|
-
graphql_mapping_template_1.set(graphql_mapping_template_1.ref(`${queryExprReference}.expression`), graphql_mapping_template_1.str(`#pk = :pk`)),
|
442
|
-
graphql_mapping_template_1.set(graphql_mapping_template_1.ref(`${queryExprReference}.expressionNames`), graphql_mapping_template_1.obj({ [`#pk`]: graphql_mapping_template_1.str('$pk') })),
|
443
|
-
graphql_mapping_template_1.set(graphql_mapping_template_1.ref(`${queryExprReference}.expressionValues`), graphql_mapping_template_1.obj({ [`:pk`]: graphql_mapping_template_1.ref('util.parseJson($util.dynamodb.toDynamoDBJson($ctx.args.get($pk)))') })),
|
442
|
+
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)([
|
443
|
+
(0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(`${queryExprReference}.expression`), (0, graphql_mapping_template_1.str)(`#pk = :pk`)),
|
444
|
+
(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') })),
|
445
|
+
(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)))') })),
|
444
446
|
])));
|
445
|
-
return graphql_mapping_template_1.block(`Set Primary Key initialization @key`, expressions);
|
447
|
+
return (0, graphql_mapping_template_1.block)(`Set Primary Key initialization @key`, expressions);
|
446
448
|
}
|
447
449
|
function setSyncKeyExpressionForRangeKey(queryExprReference) {
|
448
|
-
return graphql_mapping_template_1.block('Applying Key Condition', [
|
449
|
-
graphql_mapping_template_1.iff(graphql_mapping_template_1.raw(`!$util.isNull($ctx.args.get($sk)) && !$util.isNull($ctx.args.get($sk).beginsWith)`), graphql_mapping_template_1.compoundExpression([
|
450
|
-
graphql_mapping_template_1.set(graphql_mapping_template_1.ref(`${queryExprReference}.expression`), graphql_mapping_template_1.raw(`"$${queryExprReference}.expression AND begins_with(#sortKey, :sortKey)"`)),
|
451
|
-
graphql_mapping_template_1.qref(`$${queryExprReference}.expressionNames.put("#sortKey", $sk)`),
|
452
|
-
graphql_mapping_template_1.qref(`$${queryExprReference}.expressionValues.put(":sortKey", $util.parseJson($util.dynamodb.toDynamoDBJson($ctx.args.get($sk).beginsWith)))`),
|
450
|
+
return (0, graphql_mapping_template_1.block)('Applying Key Condition', [
|
451
|
+
(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)([
|
452
|
+
(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)"`)),
|
453
|
+
(0, graphql_mapping_template_1.qref)(`$${queryExprReference}.expressionNames.put("#sortKey", $sk)`),
|
454
|
+
(0, graphql_mapping_template_1.qref)(`$${queryExprReference}.expressionValues.put(":sortKey", $util.parseJson($util.dynamodb.toDynamoDBJson($ctx.args.get($sk).beginsWith)))`),
|
453
455
|
])),
|
454
|
-
graphql_mapping_template_1.iff(graphql_mapping_template_1.raw(`!$util.isNull($ctx.args.get($sk)) && !$util.isNull($ctx.args.get($sk).between)`), graphql_mapping_template_1.compoundExpression([
|
455
|
-
graphql_mapping_template_1.set(graphql_mapping_template_1.ref(`${queryExprReference}.expression`), graphql_mapping_template_1.raw(`"$${queryExprReference}.expression AND #sortKey BETWEEN :sortKey0 AND :sortKey1"`)),
|
456
|
-
graphql_mapping_template_1.qref(`$${queryExprReference}.expressionNames.put("#sortKey", $sk)`),
|
457
|
-
graphql_mapping_template_1.qref(`$${queryExprReference}.expressionValues.put(":sortKey", $util.parseJson($util.dynamodb.toDynamoDBJson($ctx.args.get($sk).between[0])))`),
|
458
|
-
graphql_mapping_template_1.qref(`$${queryExprReference}.expressionValues.put(":sortKey", $util.parseJson($util.dynamodb.toDynamoDBJson($ctx.args.get($sk).between[1])))`),
|
456
|
+
(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)([
|
457
|
+
(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"`)),
|
458
|
+
(0, graphql_mapping_template_1.qref)(`$${queryExprReference}.expressionNames.put("#sortKey", $sk)`),
|
459
|
+
(0, graphql_mapping_template_1.qref)(`$${queryExprReference}.expressionValues.put(":sortKey", $util.parseJson($util.dynamodb.toDynamoDBJson($ctx.args.get($sk).between[0])))`),
|
460
|
+
(0, graphql_mapping_template_1.qref)(`$${queryExprReference}.expressionValues.put(":sortKey", $util.parseJson($util.dynamodb.toDynamoDBJson($ctx.args.get($sk).between[1])))`),
|
459
461
|
])),
|
460
|
-
graphql_mapping_template_1.iff(graphql_mapping_template_1.raw(`!$util.isNull($ctx.args.get($sk)) && !$util.isNull($ctx.args.get($sk).eq)`), graphql_mapping_template_1.compoundExpression([
|
461
|
-
graphql_mapping_template_1.set(graphql_mapping_template_1.ref(`${queryExprReference}.expression`), graphql_mapping_template_1.raw(`"$${queryExprReference}.expression AND #sortKey = :sortKey"`)),
|
462
|
-
graphql_mapping_template_1.qref(`$${queryExprReference}.expressionNames.put("#sortKey", $sk)`),
|
463
|
-
graphql_mapping_template_1.qref(`$${queryExprReference}.expressionValues.put(":sortKey", $util.parseJson($util.dynamodb.toDynamoDBJson($ctx.args.get($sk).eq)))`),
|
462
|
+
(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)([
|
463
|
+
(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"`)),
|
464
|
+
(0, graphql_mapping_template_1.qref)(`$${queryExprReference}.expressionNames.put("#sortKey", $sk)`),
|
465
|
+
(0, graphql_mapping_template_1.qref)(`$${queryExprReference}.expressionValues.put(":sortKey", $util.parseJson($util.dynamodb.toDynamoDBJson($ctx.args.get($sk).eq)))`),
|
464
466
|
])),
|
465
|
-
graphql_mapping_template_1.iff(graphql_mapping_template_1.raw(`!$util.isNull($ctx.args.get($sk)) && !$util.isNull($ctx.args.get($sk).lt)`), graphql_mapping_template_1.compoundExpression([
|
466
|
-
graphql_mapping_template_1.set(graphql_mapping_template_1.ref(`${queryExprReference}.expression`), graphql_mapping_template_1.raw(`"$${queryExprReference}.expression AND #sortKey < :sortKey"`)),
|
467
|
-
graphql_mapping_template_1.qref(`$${queryExprReference}.expressionNames.put("#sortKey", $sk)`),
|
468
|
-
graphql_mapping_template_1.qref(`$${queryExprReference}.expressionValues.put(":sortKey", $util.parseJson($util.dynamodb.toDynamoDBJson($ctx.args.get($sk).lt)))`),
|
467
|
+
(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)([
|
468
|
+
(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"`)),
|
469
|
+
(0, graphql_mapping_template_1.qref)(`$${queryExprReference}.expressionNames.put("#sortKey", $sk)`),
|
470
|
+
(0, graphql_mapping_template_1.qref)(`$${queryExprReference}.expressionValues.put(":sortKey", $util.parseJson($util.dynamodb.toDynamoDBJson($ctx.args.get($sk).lt)))`),
|
469
471
|
])),
|
470
|
-
graphql_mapping_template_1.iff(graphql_mapping_template_1.raw(`!$util.isNull($ctx.args.get($sk)) && !$util.isNull($ctx.args.get($sk).le)`), graphql_mapping_template_1.compoundExpression([
|
471
|
-
graphql_mapping_template_1.set(graphql_mapping_template_1.ref(`${queryExprReference}.expression`), graphql_mapping_template_1.raw(`"$${queryExprReference}.expression AND #sortKey <= :sortKey"`)),
|
472
|
-
graphql_mapping_template_1.qref(`$${queryExprReference}.expressionNames.put("#sortKey", $sk)`),
|
473
|
-
graphql_mapping_template_1.qref(`$${queryExprReference}.expressionValues.put(":sortKey", $util.parseJson($util.dynamodb.toDynamoDBJson($ctx.args.get($sk).le)))`),
|
472
|
+
(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)([
|
473
|
+
(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"`)),
|
474
|
+
(0, graphql_mapping_template_1.qref)(`$${queryExprReference}.expressionNames.put("#sortKey", $sk)`),
|
475
|
+
(0, graphql_mapping_template_1.qref)(`$${queryExprReference}.expressionValues.put(":sortKey", $util.parseJson($util.dynamodb.toDynamoDBJson($ctx.args.get($sk).le)))`),
|
474
476
|
])),
|
475
|
-
graphql_mapping_template_1.iff(graphql_mapping_template_1.raw(`!$util.isNull($ctx.args.get($sk)) && !$util.isNull($ctx.args.get($sk).gt)`), graphql_mapping_template_1.compoundExpression([
|
476
|
-
graphql_mapping_template_1.set(graphql_mapping_template_1.ref(`${queryExprReference}.expression`), graphql_mapping_template_1.raw(`"$${queryExprReference}.expression AND #sortKey > :sortKey"`)),
|
477
|
-
graphql_mapping_template_1.qref(`$${queryExprReference}.expressionNames.put("#sortKey", $sk)`),
|
478
|
-
graphql_mapping_template_1.qref(`$${queryExprReference}.expressionValues.put(":sortKey", $util.parseJson($util.dynamodb.toDynamoDBJson($ctx.args.get($sk).gt)))`),
|
477
|
+
(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)([
|
478
|
+
(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"`)),
|
479
|
+
(0, graphql_mapping_template_1.qref)(`$${queryExprReference}.expressionNames.put("#sortKey", $sk)`),
|
480
|
+
(0, graphql_mapping_template_1.qref)(`$${queryExprReference}.expressionValues.put(":sortKey", $util.parseJson($util.dynamodb.toDynamoDBJson($ctx.args.get($sk).gt)))`),
|
479
481
|
])),
|
480
|
-
graphql_mapping_template_1.iff(graphql_mapping_template_1.raw(`!$util.isNull($ctx.args.get($sk)) && !$util.isNull($ctx.args.get($sk).ge)`), graphql_mapping_template_1.compoundExpression([
|
481
|
-
graphql_mapping_template_1.set(graphql_mapping_template_1.ref(`${queryExprReference}.expression`), graphql_mapping_template_1.raw(`"$${queryExprReference}.expression AND #sortKey >= :sortKey"`)),
|
482
|
-
graphql_mapping_template_1.qref(`$${queryExprReference}.expressionNames.put("#sortKey", $sk)`),
|
483
|
-
graphql_mapping_template_1.qref(`$${queryExprReference}.expressionValues.put(":sortKey", $util.parseJson($util.dynamodb.toDynamoDBJson($ctx.args.get($sk).ge)))`),
|
482
|
+
(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)([
|
483
|
+
(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"`)),
|
484
|
+
(0, graphql_mapping_template_1.qref)(`$${queryExprReference}.expressionNames.put("#sortKey", $sk)`),
|
485
|
+
(0, graphql_mapping_template_1.qref)(`$${queryExprReference}.expressionValues.put(":sortKey", $util.parseJson($util.dynamodb.toDynamoDBJson($ctx.args.get($sk).ge)))`),
|
484
486
|
])),
|
485
487
|
]);
|
486
488
|
}
|
487
489
|
function makeSyncQueryResolver() {
|
488
490
|
const requestVariable = 'QueryRequest';
|
489
491
|
const expressions = [];
|
490
|
-
expressions.push(graphql_mapping_template_1.ifElse(graphql_mapping_template_1.raw('!$scan'), graphql_mapping_template_1.compoundExpression([
|
491
|
-
graphql_mapping_template_1.set(graphql_mapping_template_1.ref('limit'), graphql_mapping_template_1.ref(`util.defaultIfNull($context.args.limit, ${graphql_transformer_common_1.ResourceConstants.DEFAULT_PAGE_LIMIT})`)),
|
492
|
-
graphql_mapping_template_1.set(graphql_mapping_template_1.ref(requestVariable), graphql_mapping_template_1.obj({
|
493
|
-
version: graphql_mapping_template_1.str(graphql_mapping_template_1.RESOLVER_VERSION_ID),
|
494
|
-
operation: graphql_mapping_template_1.str('Sync'),
|
495
|
-
limit: graphql_mapping_template_1.ref('limit'),
|
496
|
-
query: graphql_mapping_template_1.ref(graphql_transformer_common_1.ResourceConstants.SNIPPETS.ModelQueryExpression),
|
492
|
+
expressions.push((0, graphql_mapping_template_1.ifElse)((0, graphql_mapping_template_1.raw)('!$scan'), (0, graphql_mapping_template_1.compoundExpression)([
|
493
|
+
(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})`)),
|
494
|
+
(0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(requestVariable), (0, graphql_mapping_template_1.obj)({
|
495
|
+
version: (0, graphql_mapping_template_1.str)(graphql_mapping_template_1.RESOLVER_VERSION_ID),
|
496
|
+
operation: (0, graphql_mapping_template_1.str)('Sync'),
|
497
|
+
limit: (0, graphql_mapping_template_1.ref)('limit'),
|
498
|
+
query: (0, graphql_mapping_template_1.ref)(graphql_transformer_common_1.ResourceConstants.SNIPPETS.ModelQueryExpression),
|
497
499
|
})),
|
498
|
-
graphql_mapping_template_1.ifElse(graphql_mapping_template_1.raw(`!$util.isNull($ctx.args.sortDirection)
|
499
|
-
&& $ctx.args.sortDirection == "DESC"`), graphql_mapping_template_1.set(graphql_mapping_template_1.ref(`${requestVariable}.scanIndexForward`), graphql_mapping_template_1.bool(false)), graphql_mapping_template_1.set(graphql_mapping_template_1.ref(`${requestVariable}.scanIndexForward`), graphql_mapping_template_1.bool(true))),
|
500
|
-
graphql_mapping_template_1.iff(graphql_mapping_template_1.ref('context.args.nextToken'), graphql_mapping_template_1.set(graphql_mapping_template_1.ref(`${requestVariable}.nextToken`), graphql_mapping_template_1.ref('context.args.nextToken')), true),
|
501
|
-
graphql_mapping_template_1.iff(graphql_mapping_template_1.raw('!$util.isNullOrEmpty($filterMap)'), graphql_mapping_template_1.set(graphql_mapping_template_1.ref(`${requestVariable}.filter`), graphql_mapping_template_1.ref('util.parseJson($util.transform.toDynamoDBFilterExpression($filterMap))'))),
|
502
|
-
graphql_mapping_template_1.iff(graphql_mapping_template_1.raw(`$index != "dbTable"`), graphql_mapping_template_1.set(graphql_mapping_template_1.ref(`${requestVariable}.index`), graphql_mapping_template_1.ref('index'))),
|
503
|
-
graphql_mapping_template_1.raw(`$util.toJson($${requestVariable})`),
|
500
|
+
(0, graphql_mapping_template_1.ifElse)((0, graphql_mapping_template_1.raw)(`!$util.isNull($ctx.args.sortDirection)
|
501
|
+
&& $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))),
|
502
|
+
(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),
|
503
|
+
(0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.raw)('!$util.isNullOrEmpty($filterMap)'), (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(`${requestVariable}.filter`), (0, graphql_mapping_template_1.ref)('util.parseJson($util.transform.toDynamoDBFilterExpression($filterMap))'))),
|
504
|
+
(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'))),
|
505
|
+
(0, graphql_mapping_template_1.raw)(`$util.toJson($${requestVariable})`),
|
504
506
|
]), graphql_mapping_template_1.DynamoDBMappingTemplate.syncItem({
|
505
|
-
filter: graphql_mapping_template_1.ifElse(graphql_mapping_template_1.raw('!$util.isNullOrEmpty($ctx.args.filter)'), graphql_mapping_template_1.ref('util.transform.toDynamoDBFilterExpression($ctx.args.filter)'), graphql_mapping_template_1.nul()),
|
506
|
-
limit: graphql_mapping_template_1.ref(`util.defaultIfNull($ctx.args.limit, ${graphql_transformer_common_1.ResourceConstants.DEFAULT_SYNC_QUERY_PAGE_LIMIT})`),
|
507
|
-
lastSync: graphql_mapping_template_1.ref('util.toJson($util.defaultIfNull($ctx.args.lastSync, null))'),
|
508
|
-
nextToken: graphql_mapping_template_1.ref('util.toJson($util.defaultIfNull($ctx.args.nextToken, null))'),
|
507
|
+
filter: (0, graphql_mapping_template_1.ifElse)((0, graphql_mapping_template_1.raw)('!$util.isNullOrEmpty($ctx.args.filter)'), (0, graphql_mapping_template_1.ref)('util.transform.toDynamoDBFilterExpression($ctx.args.filter)'), (0, graphql_mapping_template_1.nul)()),
|
508
|
+
limit: (0, graphql_mapping_template_1.ref)(`util.defaultIfNull($ctx.args.limit, ${graphql_transformer_common_1.ResourceConstants.DEFAULT_SYNC_QUERY_PAGE_LIMIT})`),
|
509
|
+
lastSync: (0, graphql_mapping_template_1.ref)('util.toJson($util.defaultIfNull($ctx.args.lastSync, null))'),
|
510
|
+
nextToken: (0, graphql_mapping_template_1.ref)('util.toJson($util.defaultIfNull($ctx.args.nextToken, null))'),
|
509
511
|
})));
|
510
|
-
return graphql_mapping_template_1.block(` Set query expression for @key`, expressions);
|
512
|
+
return (0, graphql_mapping_template_1.block)(` Set query expression for @key`, expressions);
|
511
513
|
}
|
512
514
|
function generateSyncResolverInit() {
|
513
515
|
const expressions = [];
|
514
|
-
expressions.push(graphql_mapping_template_1.set(graphql_mapping_template_1.ref('index'), graphql_mapping_template_1.str('')), graphql_mapping_template_1.set(graphql_mapping_template_1.ref('scan'), graphql_mapping_template_1.bool(true)), graphql_mapping_template_1.set(graphql_mapping_template_1.ref('filterMap'), graphql_mapping_template_1.obj({})), graphql_mapping_template_1.set(graphql_mapping_template_1.ref('QueryMap'), graphql_mapping_template_1.obj({})), graphql_mapping_template_1.set(graphql_mapping_template_1.ref('PkMap'), graphql_mapping_template_1.obj({})), graphql_mapping_template_1.set(graphql_mapping_template_1.ref('filterArgsMap'), graphql_mapping_template_1.obj({})));
|
515
|
-
return graphql_mapping_template_1.block(`Set map initialization for @key`, expressions);
|
516
|
+
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)('filterArgsMap'), (0, graphql_mapping_template_1.obj)({})));
|
517
|
+
return (0, graphql_mapping_template_1.block)(`Set map initialization for @key`, expressions);
|
516
518
|
}
|
519
|
+
const generateAuthExpressionForSandboxMode = (enabled) => {
|
520
|
+
let exp;
|
521
|
+
if (enabled)
|
522
|
+
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')));
|
523
|
+
else
|
524
|
+
exp = (0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('util.unauthorized'));
|
525
|
+
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)({}))]));
|
526
|
+
};
|
527
|
+
exports.generateAuthExpressionForSandboxMode = generateAuthExpressionForSandboxMode;
|
517
528
|
//# sourceMappingURL=resolvers.js.map
|