@aws-amplify/graphql-model-transformer
Advanced tools
Comparing version 0.6.5-amplify-export2.0 to 0.6.5-ext1.0
@@ -6,10 +6,15 @@ # Change Log | ||
## [0.6.5-amplify-export2.0](https://github.com/aws-amplify/amplify-cli/compare/@aws-amplify/graphql-model-transformer@0.6.4...@aws-amplify/graphql-model-transformer@0.6.5-amplify-export2.0) (2021-10-18) | ||
## [0.6.5-ext1.0](https://github.com/aws-amplify/amplify-cli/compare/@aws-amplify/graphql-model-transformer@0.6.2...@aws-amplify/graphql-model-transformer@0.6.5-ext1.0) (2021-10-18) | ||
**Note:** Version bump only for package @aws-amplify/graphql-model-transformer | ||
### Bug Fixes | ||
* **graphql-model-transformer:** [@model](https://github.com/model) conflict resolution ([#8035](https://github.com/aws-amplify/amplify-cli/issues/8035)) ([f3bdc4a](https://github.com/aws-amplify/amplify-cli/commit/f3bdc4ac1fcf596f634d9d2e968785e76f7b138c)) | ||
* **graphql-model-transformer:** iam role name does not exceed 64 characters ([#8244](https://github.com/aws-amplify/amplify-cli/issues/8244)) ([812a671](https://github.com/aws-amplify/amplify-cli/commit/812a67163d6dd33160bf7ace9afd538c83a7af1a)) | ||
* **graphql-model-transformer:** remove unnecessary warnings for resolver config per type ([#8265](https://github.com/aws-amplify/amplify-cli/issues/8265)) ([2f2f0a5](https://github.com/aws-amplify/amplify-cli/commit/2f2f0a5bea59278219c1f4ebb5276927dc5a0fbd)) | ||
## [0.6.4](https://github.com/aws-amplify/amplify-cli/compare/@aws-amplify/graphql-model-transformer@0.6.3...@aws-amplify/graphql-model-transformer@0.6.4) (2021-10-10) | ||
@@ -16,0 +21,0 @@ |
@@ -13,3 +13,2 @@ export declare const STRING_CONDITIONS: string[]; | ||
export declare const ATTRIBUTE_TYPES: string[]; | ||
export declare const OPERATION_KEY = "__operation"; | ||
//# sourceMappingURL=definitions.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.OPERATION_KEY = exports.ATTRIBUTE_TYPES = exports.BOOLEAN_FUNCTIONS = exports.FLOAT_FUNCTIONS = exports.INT_FUNCTIONS = exports.ID_FUNCTIONS = exports.STRING_FUNCTIONS = exports.SIZE_CONDITIONS = exports.BOOLEAN_CONDITIONS = exports.FLOAT_CONDITIONS = exports.INT_CONDITIONS = exports.ID_CONDITIONS = exports.STRING_CONDITIONS = void 0; | ||
exports.ATTRIBUTE_TYPES = exports.BOOLEAN_FUNCTIONS = exports.FLOAT_FUNCTIONS = exports.INT_FUNCTIONS = exports.ID_FUNCTIONS = exports.STRING_FUNCTIONS = exports.SIZE_CONDITIONS = exports.BOOLEAN_CONDITIONS = exports.FLOAT_CONDITIONS = exports.INT_CONDITIONS = exports.ID_CONDITIONS = exports.STRING_CONDITIONS = void 0; | ||
exports.STRING_CONDITIONS = ['ne', 'eq', 'le', 'lt', 'ge', 'gt', 'contains', 'notContains', 'between', 'beginsWith']; | ||
@@ -16,3 +16,2 @@ exports.ID_CONDITIONS = ['ne', 'eq', 'le', 'lt', 'ge', 'gt', 'contains', 'notContains', 'between', 'beginsWith']; | ||
exports.ATTRIBUTE_TYPES = ['binary', 'binarySet', 'bool', 'list', 'map', 'number', 'numberSet', 'string', 'stringSet', '_null']; | ||
exports.OPERATION_KEY = '__operation'; | ||
//# sourceMappingURL=definitions.js.map |
@@ -17,13 +17,13 @@ import { SyncConfig, TransformerModelBase } from '@aws-amplify/graphql-transformer-core'; | ||
}>; | ||
mutations: OptionalAndNullable<{ | ||
mutations: { | ||
create: OptionalAndNullable<string>; | ||
update: OptionalAndNullable<string>; | ||
delete: OptionalAndNullable<string>; | ||
}>; | ||
subscriptions: OptionalAndNullable<{ | ||
} | null; | ||
subscriptions: { | ||
onCreate: OptionalAndNullable<string>[]; | ||
onUpdate: OptionalAndNullable<string>[]; | ||
onDelete: OptionalAndNullable<string>[]; | ||
level: SubscriptionLevel; | ||
}>; | ||
level: Partial<SubscriptionLevel>; | ||
} | null; | ||
timestamps: OptionalAndNullable<{ | ||
@@ -30,0 +30,0 @@ createdAt: OptionalAndNullable<string>; |
@@ -107,3 +107,3 @@ "use strict"; | ||
subscriptions: { | ||
level: SubscriptionLevel.on, | ||
level: SubscriptionLevel.public, | ||
onCreate: [this.ensureValidSubscriptionName(graphql_transformer_common_1.toCamelCase(['onCreate', typeName]))], | ||
@@ -147,3 +147,2 @@ onDelete: [this.ensureValidSubscriptionName(graphql_transformer_common_1.toCamelCase(['onDelete', typeName]))], | ||
this.generateResolvers = (context) => { | ||
var _a, _b; | ||
for (let type of this.typesWithModelDirective) { | ||
@@ -170,3 +169,2 @@ const def = context.output.getObject(type); | ||
} | ||
resolver.addToSlot('postAuth', graphql_transformer_core_1.MappingTemplate.s3MappingTemplateFromString(resolvers_1.generateAuthExpressionForSandboxMode(context), `${query.typeName}.${query.fieldName}.{slotName}.{slotIndex}.req.vtl`)); | ||
resolver.mapToStack(stack); | ||
@@ -189,31 +187,7 @@ context.resolvers.addResolver(query.typeName, query.fieldName, resolver); | ||
default: | ||
throw new Error('Unknown mutation field type'); | ||
throw new Error('Unknown query field type'); | ||
} | ||
resolver.addToSlot('postAuth', graphql_transformer_core_1.MappingTemplate.s3MappingTemplateFromString(resolvers_1.generateAuthExpressionForSandboxMode(context), `${mutation.typeName}.${mutation.fieldName}.{slotName}.{slotIndex}.req.vtl`)); | ||
resolver.mapToStack(stack); | ||
context.resolvers.addResolver(mutation.typeName, mutation.fieldName, resolver); | ||
} | ||
const subscriptionLevel = (_b = (_a = this.modelDirectiveConfig.get(def.name.value)) === null || _a === void 0 ? void 0 : _a.subscriptions) === null || _b === void 0 ? void 0 : _b.level; | ||
if (subscriptionLevel === SubscriptionLevel.on) { | ||
const subscriptionFields = this.getSubscriptionFieldNames(context, def); | ||
for (let subscription of subscriptionFields.values()) { | ||
let resolver; | ||
switch (subscription.type) { | ||
case graphql_transformer_interfaces_1.SubscriptionFieldType.ON_CREATE: | ||
resolver = this.generateOnCreateResolver(context, def, subscription.typeName, subscription.fieldName); | ||
break; | ||
case graphql_transformer_interfaces_1.SubscriptionFieldType.ON_UPDATE: | ||
resolver = this.generateOnUpdateResolver(context, def, subscription.typeName, subscription.fieldName); | ||
break; | ||
case graphql_transformer_interfaces_1.SubscriptionFieldType.ON_DELETE: | ||
resolver = this.generateOnDeleteResolver(context, def, subscription.typeName, subscription.fieldName); | ||
break; | ||
default: | ||
throw new Error('Unknown subscription field type'); | ||
} | ||
resolver.addToSlot('postAuth', graphql_transformer_core_1.MappingTemplate.s3MappingTemplateFromString(resolvers_1.generateAuthExpressionForSandboxMode(context), `${subscription.typeName}.${subscription.fieldName}.{slotName}.{slotIndex}.req.vtl`)); | ||
resolver.mapToStack(stack); | ||
context.resolvers.addResolver(subscription.typeName, subscription.fieldName, resolver); | ||
} | ||
} | ||
} | ||
@@ -226,3 +200,3 @@ }; | ||
if (!this.resolverMap[resolverKey]) { | ||
this.resolverMap[resolverKey] = ctx.resolvers.generateQueryResolver(typeName, fieldName, dataSource, graphql_transformer_core_1.MappingTemplate.s3MappingTemplateFromString(query_1.generateGetRequestTemplate(), `${typeName}.${fieldName}.req.vtl`), graphql_transformer_core_1.MappingTemplate.s3MappingTemplateFromString(query_1.generateGetResponseTemplate(isSyncEnabled), `${typeName}.${fieldName}.res.vtl`)); | ||
this.resolverMap[resolverKey] = ctx.resolvers.generateQueryResolver(typeName, fieldName, dataSource, graphql_transformer_core_1.MappingTemplate.s3MappingTemplateFromString(query_1.generateGetRequestTemplate(), `${typeName}.${fieldName}.req.vtl`), graphql_transformer_core_1.MappingTemplate.s3MappingTemplateFromString(resolvers_1.generateDefaultResponseMappingTemplate(isSyncEnabled), `${typeName}.${fieldName}.res.vtl`)); | ||
} | ||
@@ -245,3 +219,3 @@ return this.resolverMap[resolverKey]; | ||
if (!this.resolverMap[resolverKey]) { | ||
const resolver = ctx.resolvers.generateMutationResolver(typeName, fieldName, dataSource, graphql_transformer_core_1.MappingTemplate.s3MappingTemplateFromString(resolvers_1.generateUpdateRequestTemplate(typeName, isSyncEnabled), `${typeName}.${fieldName}.req.vtl`), graphql_transformer_core_1.MappingTemplate.s3MappingTemplateFromString(resolvers_1.generateDefaultResponseMappingTemplate(isSyncEnabled, true), `${typeName}.${fieldName}.res.vtl`)); | ||
const resolver = ctx.resolvers.generateMutationResolver(typeName, fieldName, dataSource, graphql_transformer_core_1.MappingTemplate.s3MappingTemplateFromString(resolvers_1.generateUpdateRequestTemplate(typeName, isSyncEnabled), `${typeName}.${fieldName}.req.vtl`), graphql_transformer_core_1.MappingTemplate.s3MappingTemplateFromString(resolvers_1.generateDefaultResponseMappingTemplate(isSyncEnabled), `${typeName}.${fieldName}.res.vtl`)); | ||
resolver.addToSlot('init', graphql_transformer_core_1.MappingTemplate.s3MappingTemplateFromString(resolvers_1.generateUpdateInitSlotTemplate(type.name.value, this.modelDirectiveConfig.get(type.name.value)), `${typeName}.${fieldName}.{slotName}.{slotIndex}.req.vtl`)); | ||
@@ -257,3 +231,3 @@ this.resolverMap[resolverKey] = resolver; | ||
if (!this.resolverMap[resolverKey]) { | ||
this.resolverMap[resolverKey] = ctx.resolvers.generateMutationResolver(typeName, fieldName, dataSource, graphql_transformer_core_1.MappingTemplate.s3MappingTemplateFromString(resolvers_1.generateDeleteRequestTemplate(isSyncEnabled), `${typeName}.${fieldName}.req.vtl`), graphql_transformer_core_1.MappingTemplate.s3MappingTemplateFromString(resolvers_1.generateDefaultResponseMappingTemplate(isSyncEnabled, true), `${typeName}.${fieldName}.res.vtl`)); | ||
this.resolverMap[resolverKey] = ctx.resolvers.generateMutationResolver(typeName, fieldName, dataSource, graphql_transformer_core_1.MappingTemplate.s3MappingTemplateFromString(resolvers_1.generateDeleteRequestTemplate(isSyncEnabled), `${typeName}.${fieldName}.req.vtl`), graphql_transformer_core_1.MappingTemplate.s3MappingTemplateFromString(resolvers_1.generateDefaultResponseMappingTemplate(isSyncEnabled), `${typeName}.${fieldName}.res.vtl`)); | ||
} | ||
@@ -451,3 +425,3 @@ return this.resolverMap[resolverKey]; | ||
if (!this.resolverMap[resolverKey]) { | ||
const resolver = ctx.resolvers.generateMutationResolver(typeName, fieldName, dataSource, graphql_transformer_core_1.MappingTemplate.s3MappingTemplateFromString(resolvers_1.generateCreateRequestTemplate(type.name.value), `${typeName}.${fieldName}.req.vtl`), graphql_transformer_core_1.MappingTemplate.s3MappingTemplateFromString(resolvers_1.generateDefaultResponseMappingTemplate(isSyncEnabled, true), `${typeName}.${fieldName}.res.vtl`)); | ||
const resolver = ctx.resolvers.generateMutationResolver(typeName, fieldName, dataSource, graphql_transformer_core_1.MappingTemplate.s3MappingTemplateFromString(resolvers_1.generateCreateRequestTemplate(type.name.value), `${typeName}.${fieldName}.req.vtl`), graphql_transformer_core_1.MappingTemplate.s3MappingTemplateFromString(resolvers_1.generateDefaultResponseMappingTemplate(isSyncEnabled), `${typeName}.${fieldName}.res.vtl`)); | ||
this.resolverMap[resolverKey] = resolver; | ||
@@ -454,0 +428,0 @@ resolver.addToSlot('init', graphql_transformer_core_1.MappingTemplate.s3MappingTemplateFromString(resolvers_1.generateCreateInitSlotTemplate(type.name.value, this.modelDirectiveConfig.get(type.name.value)), `${typeName}.${fieldName}.{slotName}.{slotIndex}.req.vtl`)); |
@@ -1,5 +0,4 @@ | ||
export { ModelTransformer, ModelDirectiveConfiguration, SubscriptionLevel } from './graphql-model-transformer'; | ||
export { OPERATION_KEY } from './definitions'; | ||
export { ModelTransformer } from './graphql-model-transformer'; | ||
export * from './graphql-types'; | ||
export * from './resolvers'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -13,10 +13,7 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.OPERATION_KEY = exports.SubscriptionLevel = exports.ModelTransformer = void 0; | ||
exports.ModelTransformer = void 0; | ||
var graphql_model_transformer_1 = require("./graphql-model-transformer"); | ||
Object.defineProperty(exports, "ModelTransformer", { enumerable: true, get: function () { return graphql_model_transformer_1.ModelTransformer; } }); | ||
Object.defineProperty(exports, "SubscriptionLevel", { enumerable: true, get: function () { return graphql_model_transformer_1.SubscriptionLevel; } }); | ||
var definitions_1 = require("./definitions"); | ||
Object.defineProperty(exports, "OPERATION_KEY", { enumerable: true, get: function () { return definitions_1.OPERATION_KEY; } }); | ||
__exportStar(require("./graphql-types"), exports); | ||
__exportStar(require("./resolvers"), exports); | ||
//# sourceMappingURL=index.js.map |
import { CompoundExpressionNode } from 'graphql-mapping-template'; | ||
export declare const generateConditionSlot: (inputConditionObjectName: string, conditionOutputVariableName: string) => CompoundExpressionNode; | ||
export declare const generateDefaultResponseMappingTemplate: (isSyncEnabled: boolean, mutation?: boolean) => string; | ||
export declare const generateDefaultResponseMappingTemplate: (isSyncEnabled: boolean) => string; | ||
export declare const generateResolverKey: (typeName: string, fieldName: string) => string; | ||
export declare const generateAuthExpressionForSandboxMode: (ctx: any) => string; | ||
//# sourceMappingURL=common.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.generateAuthExpressionForSandboxMode = exports.generateResolverKey = exports.generateDefaultResponseMappingTemplate = exports.generateConditionSlot = void 0; | ||
exports.generateResolverKey = exports.generateDefaultResponseMappingTemplate = exports.generateConditionSlot = void 0; | ||
const graphql_mapping_template_1 = require("graphql-mapping-template"); | ||
const definitions_1 = require("../definitions"); | ||
const API_KEY = 'API Key Authorization'; | ||
const generateConditionSlot = (inputConditionObjectName, conditionOutputVariableName) => { | ||
@@ -26,6 +24,4 @@ const statements = [ | ||
exports.generateConditionSlot = generateConditionSlot; | ||
const generateDefaultResponseMappingTemplate = (isSyncEnabled, mutation = false) => { | ||
const generateDefaultResponseMappingTemplate = (isSyncEnabled) => { | ||
const statements = []; | ||
if (mutation) | ||
statements.push(graphql_mapping_template_1.qref(graphql_mapping_template_1.methodCall(graphql_mapping_template_1.ref('ctx.result.put'), graphql_mapping_template_1.str(definitions_1.OPERATION_KEY), graphql_mapping_template_1.str('Mutation')))); | ||
if (isSyncEnabled) { | ||
@@ -37,3 +33,3 @@ statements.push(graphql_mapping_template_1.ifElse(graphql_mapping_template_1.ref('ctx.error'), graphql_mapping_template_1.methodCall(graphql_mapping_template_1.ref('util.error'), graphql_mapping_template_1.ref('ctx.error.message'), graphql_mapping_template_1.ref('ctx.error.type'), graphql_mapping_template_1.ref('ctx.result')), graphql_mapping_template_1.toJson(graphql_mapping_template_1.ref('ctx.result')))); | ||
} | ||
return graphql_mapping_template_1.printBlock('ResponseTemplate')(graphql_mapping_template_1.compoundExpression(statements)); | ||
return graphql_mapping_template_1.printBlock('Get ResponseTemplate')(graphql_mapping_template_1.compoundExpression(statements)); | ||
}; | ||
@@ -45,12 +41,2 @@ exports.generateDefaultResponseMappingTemplate = generateDefaultResponseMappingTemplate; | ||
exports.generateResolverKey = generateResolverKey; | ||
const generateAuthExpressionForSandboxMode = (ctx) => { | ||
const enabled = ctx.resourceHelper.api.sandboxModeEnabled; | ||
let exp; | ||
if (enabled) | ||
exp = graphql_mapping_template_1.iff(graphql_mapping_template_1.notEquals(graphql_mapping_template_1.methodCall(graphql_mapping_template_1.ref('util.authType')), graphql_mapping_template_1.str(API_KEY)), graphql_mapping_template_1.methodCall(graphql_mapping_template_1.ref('util.unauthorized'))); | ||
else | ||
exp = graphql_mapping_template_1.methodCall(graphql_mapping_template_1.ref('util.unauthorized')); | ||
return graphql_mapping_template_1.printBlock(`Sandbox Mode ${enabled ? 'Enabled' : 'Disabled'}`)(graphql_mapping_template_1.compoundExpression([graphql_mapping_template_1.iff(graphql_mapping_template_1.not(graphql_mapping_template_1.ref('ctx.stash.get("hasAuth")')), exp), graphql_mapping_template_1.toJson(graphql_mapping_template_1.obj({}))])); | ||
}; | ||
exports.generateAuthExpressionForSandboxMode = generateAuthExpressionForSandboxMode; | ||
//# sourceMappingURL=common.js.map |
@@ -90,2 +90,3 @@ "use strict"; | ||
const statements = [ | ||
...generateKeyConditionTemplate(false), | ||
graphql_mapping_template_1.comment('Set the default values to put request'), | ||
@@ -92,0 +93,0 @@ graphql_mapping_template_1.set(graphql_mapping_template_1.ref('mergedValues'), graphql_mapping_template_1.methodCall(graphql_mapping_template_1.ref('util.defaultIfNull'), graphql_mapping_template_1.ref('ctx.stash.defaultValues'), graphql_mapping_template_1.obj({}))), |
export declare const generateGetRequestTemplate: () => string; | ||
export declare const generateGetResponseTemplate: (isSyncEnabled: boolean) => string; | ||
export declare const generateListRequestTemplate: () => string; | ||
export declare const generateSyncRequestTemplate: () => string; | ||
//# sourceMappingURL=query.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.generateSyncRequestTemplate = exports.generateListRequestTemplate = exports.generateGetResponseTemplate = exports.generateGetRequestTemplate = void 0; | ||
exports.generateSyncRequestTemplate = exports.generateListRequestTemplate = exports.generateGetRequestTemplate = void 0; | ||
const graphql_mapping_template_1 = require("graphql-mapping-template"); | ||
const graphql_transformer_common_1 = require("graphql-transformer-common"); | ||
const authFilter = graphql_mapping_template_1.ref('ctx.stash.authFilter'); | ||
const generateGetRequestTemplate = () => { | ||
const statements = [ | ||
graphql_mapping_template_1.set(graphql_mapping_template_1.ref('GetRequest'), graphql_mapping_template_1.obj({ version: graphql_mapping_template_1.str('2018-05-29'), operation: graphql_mapping_template_1.str('Query') })), | ||
graphql_mapping_template_1.ifElse(graphql_mapping_template_1.ref('ctx.stash.metadata.modelObjectKey'), graphql_mapping_template_1.compoundExpression([ | ||
graphql_mapping_template_1.set(graphql_mapping_template_1.ref('expression'), graphql_mapping_template_1.str('')), | ||
graphql_mapping_template_1.set(graphql_mapping_template_1.ref('expressionNames'), graphql_mapping_template_1.obj({})), | ||
graphql_mapping_template_1.set(graphql_mapping_template_1.ref('expressionValues'), graphql_mapping_template_1.obj({})), | ||
graphql_mapping_template_1.forEach(graphql_mapping_template_1.ref('item'), graphql_mapping_template_1.ref('ctx.stash.metadata.modelObjectKey.entrySet()'), [ | ||
graphql_mapping_template_1.set(graphql_mapping_template_1.ref('expression'), graphql_mapping_template_1.str('$expression#keyCount$velocityCount = :valueCount$velocityCount AND ')), | ||
graphql_mapping_template_1.qref(graphql_mapping_template_1.methodCall(graphql_mapping_template_1.ref('expressionNames.put'), graphql_mapping_template_1.str('#keyCount$velocityCount'), graphql_mapping_template_1.ref('item.key'))), | ||
graphql_mapping_template_1.qref(graphql_mapping_template_1.methodCall(graphql_mapping_template_1.ref('expressionValues.put'), graphql_mapping_template_1.str(':valueCount$velocityCount'), graphql_mapping_template_1.ref('item.value'))), | ||
]), | ||
graphql_mapping_template_1.set(graphql_mapping_template_1.ref('expression'), graphql_mapping_template_1.methodCall(graphql_mapping_template_1.ref('expression.replaceAll'), graphql_mapping_template_1.str('AND $'), graphql_mapping_template_1.str(''))), | ||
graphql_mapping_template_1.set(graphql_mapping_template_1.ref('query'), graphql_mapping_template_1.obj({ expression: graphql_mapping_template_1.ref('expression'), expressionNames: graphql_mapping_template_1.ref('expressionNames'), expressionValues: graphql_mapping_template_1.ref('expressionValues') })), | ||
]), graphql_mapping_template_1.set(graphql_mapping_template_1.ref('query'), graphql_mapping_template_1.obj({ | ||
expression: graphql_mapping_template_1.str('id = :id'), | ||
expressionValues: graphql_mapping_template_1.obj({ | ||
':id': graphql_mapping_template_1.methodCall(graphql_mapping_template_1.ref('util.parseJson'), graphql_mapping_template_1.methodCall(graphql_mapping_template_1.ref('util.dynamodb.toDynamoDBJson'), graphql_mapping_template_1.ref('ctx.args.id'))), | ||
}), | ||
}))), | ||
graphql_mapping_template_1.qref(graphql_mapping_template_1.methodCall(graphql_mapping_template_1.ref('GetRequest.put'), graphql_mapping_template_1.str('query'), graphql_mapping_template_1.ref('query'))), | ||
graphql_mapping_template_1.iff(graphql_mapping_template_1.not(graphql_mapping_template_1.isNullOrEmpty(authFilter)), graphql_mapping_template_1.qref(graphql_mapping_template_1.methodCall(graphql_mapping_template_1.ref('GetRequest.put'), graphql_mapping_template_1.str('filter'), 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'), authFilter))))), | ||
graphql_mapping_template_1.set(graphql_mapping_template_1.ref('GetRequest'), graphql_mapping_template_1.obj({ version: graphql_mapping_template_1.str('2018-05-29'), operation: graphql_mapping_template_1.str('GetItem') })), | ||
graphql_mapping_template_1.ifElse(graphql_mapping_template_1.ref('ctx.stash.metadata.modelObjectKey'), graphql_mapping_template_1.set(graphql_mapping_template_1.ref('key'), graphql_mapping_template_1.ref('ctx.stash.metadata.modelObjectKey')), graphql_mapping_template_1.compoundExpression([graphql_mapping_template_1.set(graphql_mapping_template_1.ref('key'), graphql_mapping_template_1.obj({ id: graphql_mapping_template_1.methodCall(graphql_mapping_template_1.ref('util.dynamodb.toDynamoDB'), graphql_mapping_template_1.ref('ctx.args.id')) }))])), | ||
graphql_mapping_template_1.qref(graphql_mapping_template_1.methodCall(graphql_mapping_template_1.ref('GetRequest.put'), graphql_mapping_template_1.str('key'), graphql_mapping_template_1.ref('key'))), | ||
graphql_mapping_template_1.toJson(graphql_mapping_template_1.ref('GetRequest')), | ||
@@ -34,17 +16,2 @@ ]; | ||
exports.generateGetRequestTemplate = generateGetRequestTemplate; | ||
const generateGetResponseTemplate = (isSyncEnabled) => { | ||
const statements = new Array(); | ||
if (isSyncEnabled) { | ||
statements.push(graphql_mapping_template_1.iff(graphql_mapping_template_1.ref('ctx.error'), graphql_mapping_template_1.methodCall(graphql_mapping_template_1.ref('util.error'), graphql_mapping_template_1.ref('ctx.error.message'), graphql_mapping_template_1.ref('ctx.error.type'), graphql_mapping_template_1.ref('ctx.result')))); | ||
} | ||
else { | ||
statements.push(graphql_mapping_template_1.iff(graphql_mapping_template_1.ref('ctx.error'), graphql_mapping_template_1.methodCall(graphql_mapping_template_1.ref('util.error'), graphql_mapping_template_1.ref('ctx.error.message'), graphql_mapping_template_1.ref('ctx.error.type')))); | ||
} | ||
statements.push(graphql_mapping_template_1.ifElse(graphql_mapping_template_1.and([graphql_mapping_template_1.not(graphql_mapping_template_1.ref('ctx.result.items.isEmpty()')), graphql_mapping_template_1.equals(graphql_mapping_template_1.ref('ctx.result.scannedCount'), graphql_mapping_template_1.int(1))]), graphql_mapping_template_1.toJson(graphql_mapping_template_1.ref('ctx.result.items[0]')), graphql_mapping_template_1.compoundExpression([ | ||
graphql_mapping_template_1.iff(graphql_mapping_template_1.and([graphql_mapping_template_1.ref('ctx.result.items.isEmpty()'), graphql_mapping_template_1.equals(graphql_mapping_template_1.ref('ctx.result.scannedCount'), graphql_mapping_template_1.int(1))]), graphql_mapping_template_1.ref('util.unauthorized()')), | ||
graphql_mapping_template_1.toJson(graphql_mapping_template_1.nul()), | ||
]))); | ||
return graphql_mapping_template_1.printBlock('Get Response template')(graphql_mapping_template_1.compoundExpression(statements)); | ||
}; | ||
exports.generateGetResponseTemplate = generateGetResponseTemplate; | ||
const generateListRequestTemplate = () => { | ||
@@ -61,8 +28,4 @@ const requestVariable = 'ListRequest'; | ||
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'))), | ||
graphql_mapping_template_1.ifElse(graphql_mapping_template_1.not(graphql_mapping_template_1.isNullOrEmpty(authFilter)), graphql_mapping_template_1.compoundExpression([ | ||
graphql_mapping_template_1.set(graphql_mapping_template_1.ref('filter'), authFilter), | ||
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')]) }))), | ||
]), 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')))), | ||
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([ | ||
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')))), | ||
graphql_mapping_template_1.iff(graphql_mapping_template_1.ref('context.args.filter'), graphql_mapping_template_1.compoundExpression([ | ||
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('ctx.args.filter')))), | ||
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([ | ||
@@ -89,17 +52,6 @@ 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')))), | ||
return graphql_mapping_template_1.printBlock('Sync Request template')(graphql_mapping_template_1.compoundExpression([ | ||
graphql_mapping_template_1.ifElse(graphql_mapping_template_1.not(graphql_mapping_template_1.isNullOrEmpty(authFilter)), graphql_mapping_template_1.compoundExpression([ | ||
graphql_mapping_template_1.set(graphql_mapping_template_1.ref('filter'), authFilter), | ||
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')]) }))), | ||
]), 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')))), | ||
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([ | ||
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')))), | ||
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([ | ||
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')))), | ||
graphql_mapping_template_1.set(graphql_mapping_template_1.ref('filter'), graphql_mapping_template_1.ref('filterExpression')), | ||
])), | ||
])), | ||
graphql_mapping_template_1.obj({ | ||
version: graphql_mapping_template_1.str('2018-05-29'), | ||
operation: graphql_mapping_template_1.str('Sync'), | ||
filter: graphql_mapping_template_1.ifElse(graphql_mapping_template_1.ref('filter'), graphql_mapping_template_1.ref('util.toJson($filter)'), graphql_mapping_template_1.nul()), | ||
filter: graphql_mapping_template_1.ifElse(graphql_mapping_template_1.ref('context.args.filter'), graphql_mapping_template_1.ref('util.transform.toDynamoDBFilterExpression($ctx.args.filter)'), graphql_mapping_template_1.nul()), | ||
limit: graphql_mapping_template_1.ref(`util.defaultIfNull($ctx.args.limit, ${graphql_transformer_common_1.ResourceConstants.DEFAULT_SYNC_QUERY_PAGE_LIMIT})`), | ||
@@ -106,0 +58,0 @@ lastSync: graphql_mapping_template_1.ref('util.toJson($util.defaultIfNull($ctx.args.lastSync, null))'), |
{ | ||
"name": "@aws-amplify/graphql-model-transformer", | ||
"version": "0.6.5-amplify-export2.0", | ||
"version": "0.6.5-ext1.0", | ||
"description": "Amplify graphql @model transformer", | ||
@@ -31,4 +31,4 @@ "repository": { | ||
"dependencies": { | ||
"@aws-amplify/graphql-transformer-core": "0.9.3-amplify-export2.0", | ||
"@aws-amplify/graphql-transformer-interfaces": "1.10.1-amplify-export2.0", | ||
"@aws-amplify/graphql-transformer-core": "0.9.3-ext1.0", | ||
"@aws-amplify/graphql-transformer-interfaces": "1.10.1-ext1.0", | ||
"@aws-cdk/assets": "~1.124.0", | ||
@@ -61,4 +61,4 @@ "@aws-cdk/aws-applicationautoscaling": "~1.124.0", | ||
"graphql": "^14.5.8", | ||
"graphql-mapping-template": "4.18.4-amplify-export2.0", | ||
"graphql-transformer-common": "4.19.11-amplify-export2.0", | ||
"graphql-mapping-template": "4.18.3", | ||
"graphql-transformer-common": "4.19.11-ext1.0", | ||
"lodash": "^4.17.21", | ||
@@ -88,3 +88,3 @@ "md5": "^2.3.0" | ||
}, | ||
"gitHead": "9b61aadb895c0307ef3267ca868fc4a68e7a853a" | ||
"gitHead": "4e4b39edf00f3bfbd7b225d84a4b5b64f5965025" | ||
} |
@@ -884,3 +884,3 @@ import { ModelTransformer } from '@aws-amplify/graphql-model-transformer'; | ||
it('should generate sync resolver with ConflictHandlerType.Automerge', () => { | ||
it('should generate sync resolver with ConflictHandlerType.AUTOMERGE', () => { | ||
const validSchema = ` | ||
@@ -954,3 +954,3 @@ type Post @model { | ||
it('should generate sync resolver with ConflictHandlerType.Optimistic', () => { | ||
it('should generate sync resolver with ConflictHandlerType.OPTIMISTIC', () => { | ||
const validSchema = ` | ||
@@ -957,0 +957,0 @@ type Post @model { |
@@ -16,2 +16,2 @@ export const STRING_CONDITIONS = ['ne', 'eq', 'le', 'lt', 'ge', 'gt', 'contains', 'notContains', 'between', 'beginsWith']; | ||
export const OPERATION_KEY = '__operation'; | ||
@@ -57,3 +57,2 @@ import { InvalidDirectiveError, MappingTemplate, SyncConfig, SyncUtils, TransformerModelBase } from '@aws-amplify/graphql-transformer-core'; | ||
import { | ||
generateAuthExpressionForSandboxMode, | ||
generateCreateInitSlotTemplate, | ||
@@ -69,9 +68,4 @@ generateCreateRequestTemplate, | ||
} from './resolvers'; | ||
import { generateGetRequestTemplate, generateListRequestTemplate, generateSyncRequestTemplate } from './resolvers/query'; | ||
import { | ||
generateGetRequestTemplate, | ||
generateGetResponseTemplate, | ||
generateListRequestTemplate, | ||
generateSyncRequestTemplate, | ||
} from './resolvers/query'; | ||
import { | ||
DirectiveWrapper, | ||
@@ -99,13 +93,13 @@ FieldWrapper, | ||
}>; | ||
mutations: OptionalAndNullable<{ | ||
mutations: { | ||
create: OptionalAndNullable<string>; | ||
update: OptionalAndNullable<string>; | ||
delete: OptionalAndNullable<string>; | ||
}>; | ||
subscriptions: OptionalAndNullable<{ | ||
} | null; | ||
subscriptions: { | ||
onCreate: OptionalAndNullable<string>[]; | ||
onUpdate: OptionalAndNullable<string>[]; | ||
onDelete: OptionalAndNullable<string>[]; | ||
level: SubscriptionLevel; | ||
}>; | ||
level: Partial<SubscriptionLevel>; | ||
} | null; | ||
timestamps: OptionalAndNullable<{ | ||
@@ -181,9 +175,8 @@ createdAt: OptionalAndNullable<string>; | ||
} | ||
// todo: get model configuration with default values and store it in the map | ||
const typeName = definition.name.value; | ||
if (ctx.isProjectUsingDataStore()) { | ||
SyncUtils.validateResolverConfigForType(ctx, typeName); | ||
} | ||
const directiveWrapped: DirectiveWrapper = new DirectiveWrapper(directive); | ||
@@ -202,3 +195,3 @@ const options = directiveWrapped.getArguments({ | ||
subscriptions: { | ||
level: SubscriptionLevel.on, | ||
level: SubscriptionLevel.public, | ||
onCreate: [this.ensureValidSubscriptionName(toCamelCase(['onCreate', typeName]))], | ||
@@ -256,3 +249,4 @@ onDelete: [this.ensureValidSubscriptionName(toCamelCase(['onDelete', typeName]))], | ||
for (let type of this.typesWithModelDirective) { | ||
const def = context.output.getObject(type)!; | ||
const def = context.output.getObject(type); | ||
// This name is used by the mock functionality. Changing this can break mock. | ||
@@ -280,9 +274,3 @@ const tableLogicalName = `${def!.name.value}Table`; | ||
} | ||
resolver.addToSlot( | ||
'postAuth', | ||
MappingTemplate.s3MappingTemplateFromString( | ||
generateAuthExpressionForSandboxMode(context), | ||
`${query.typeName}.${query.fieldName}.{slotName}.{slotIndex}.req.vtl`, | ||
), | ||
); | ||
resolver.mapToStack(stack); | ||
@@ -306,45 +294,7 @@ context.resolvers.addResolver(query.typeName, query.fieldName, resolver); | ||
default: | ||
throw new Error('Unknown mutation field type'); | ||
throw new Error('Unknown query field type'); | ||
} | ||
resolver.addToSlot( | ||
'postAuth', | ||
MappingTemplate.s3MappingTemplateFromString( | ||
generateAuthExpressionForSandboxMode(context), | ||
`${mutation.typeName}.${mutation.fieldName}.{slotName}.{slotIndex}.req.vtl`, | ||
), | ||
); | ||
resolver.mapToStack(stack); | ||
context.resolvers.addResolver(mutation.typeName, mutation.fieldName, resolver); | ||
} | ||
const subscriptionLevel = this.modelDirectiveConfig.get(def.name.value)?.subscriptions?.level; | ||
// in order to create subscription resolvers the level needs to be on | ||
if (subscriptionLevel === SubscriptionLevel.on) { | ||
const subscriptionFields = this.getSubscriptionFieldNames(context, def!); | ||
for (let subscription of subscriptionFields.values()) { | ||
let resolver; | ||
switch (subscription.type) { | ||
case SubscriptionFieldType.ON_CREATE: | ||
resolver = this.generateOnCreateResolver(context, def, subscription.typeName, subscription.fieldName); | ||
break; | ||
case SubscriptionFieldType.ON_UPDATE: | ||
resolver = this.generateOnUpdateResolver(context, def, subscription.typeName, subscription.fieldName); | ||
break; | ||
case SubscriptionFieldType.ON_DELETE: | ||
resolver = this.generateOnDeleteResolver(context, def, subscription.typeName, subscription.fieldName); | ||
break; | ||
default: | ||
throw new Error('Unknown subscription field type'); | ||
} | ||
resolver.addToSlot( | ||
'postAuth', | ||
MappingTemplate.s3MappingTemplateFromString( | ||
generateAuthExpressionForSandboxMode(context), | ||
`${subscription.typeName}.${subscription.fieldName}.{slotName}.{slotIndex}.req.vtl`, | ||
), | ||
); | ||
resolver.mapToStack(stack); | ||
context.resolvers.addResolver(subscription.typeName, subscription.fieldName, resolver); | ||
} | ||
} | ||
} | ||
@@ -368,3 +318,6 @@ }; | ||
MappingTemplate.s3MappingTemplateFromString(generateGetRequestTemplate(), `${typeName}.${fieldName}.req.vtl`), | ||
MappingTemplate.s3MappingTemplateFromString(generateGetResponseTemplate(isSyncEnabled), `${typeName}.${fieldName}.res.vtl`), | ||
MappingTemplate.s3MappingTemplateFromString( | ||
generateDefaultResponseMappingTemplate(isSyncEnabled), | ||
`${typeName}.${fieldName}.res.vtl`, | ||
), | ||
); | ||
@@ -418,3 +371,3 @@ } | ||
MappingTemplate.s3MappingTemplateFromString( | ||
generateDefaultResponseMappingTemplate(isSyncEnabled, true), | ||
generateDefaultResponseMappingTemplate(isSyncEnabled), | ||
`${typeName}.${fieldName}.res.vtl`, | ||
@@ -451,3 +404,3 @@ ), | ||
MappingTemplate.s3MappingTemplateFromString( | ||
generateDefaultResponseMappingTemplate(isSyncEnabled, true), | ||
generateDefaultResponseMappingTemplate(isSyncEnabled), | ||
`${typeName}.${fieldName}.res.vtl`, | ||
@@ -762,3 +715,3 @@ ), | ||
MappingTemplate.s3MappingTemplateFromString( | ||
generateDefaultResponseMappingTemplate(isSyncEnabled, true), | ||
generateDefaultResponseMappingTemplate(isSyncEnabled), | ||
`${typeName}.${fieldName}.res.vtl`, | ||
@@ -1226,2 +1179,3 @@ ), | ||
} | ||
return role; | ||
@@ -1228,0 +1182,0 @@ } |
@@ -1,4 +0,3 @@ | ||
export { ModelTransformer, ModelDirectiveConfiguration, SubscriptionLevel } from './graphql-model-transformer'; | ||
export { OPERATION_KEY } from './definitions'; | ||
export { ModelTransformer } from './graphql-model-transformer'; | ||
export * from './graphql-types'; | ||
export * from './resolvers'; |
@@ -18,10 +18,4 @@ import { | ||
toJson, | ||
qref, | ||
str, | ||
not, | ||
} from 'graphql-mapping-template'; | ||
import { OPERATION_KEY } from '../definitions'; | ||
const API_KEY = 'API Key Authorization'; | ||
/** | ||
@@ -67,7 +61,5 @@ * Helper method to generate code that converts DynamoDB condition object to condition | ||
* Generate common response template used by most of the resolvers. | ||
* Append operation if response is coming from a mutation, this is to protect field resolver for subscriptions | ||
*/ | ||
export const generateDefaultResponseMappingTemplate = (isSyncEnabled: boolean, mutation = false): string => { | ||
export const generateDefaultResponseMappingTemplate = (isSyncEnabled: boolean): string => { | ||
const statements: Expression[] = []; | ||
if (mutation) statements.push(qref(methodCall(ref('ctx.result.put'), str(OPERATION_KEY), str('Mutation')))); | ||
if (isSyncEnabled) { | ||
@@ -87,7 +79,7 @@ statements.push( | ||
return printBlock('ResponseTemplate')(compoundExpression(statements)); | ||
return printBlock('Get ResponseTemplate')(compoundExpression(statements)); | ||
}; | ||
/** | ||
* Util function to generate resolver key used to keep track of all the resolvers in memory | ||
* Util function to gernate resolver key used to keep track of all the resolvers in memory | ||
* @param typeName Name of the type | ||
@@ -99,17 +91,1 @@ * @param fieldName Name of the field | ||
}; | ||
/** | ||
* Util function to generate sandbox mode expression | ||
* @param ctx context to get sandbox mode | ||
*/ | ||
export const generateAuthExpressionForSandboxMode = (ctx: any): string => { | ||
const enabled = ctx.resourceHelper.api.sandboxModeEnabled; | ||
let exp; | ||
if (enabled) exp = iff(notEquals(methodCall(ref('util.authType')), str(API_KEY)), methodCall(ref('util.unauthorized'))); | ||
else exp = methodCall(ref('util.unauthorized')); | ||
return printBlock(`Sandbox Mode ${enabled ? 'Enabled' : 'Disabled'}`)( | ||
compoundExpression([iff(not(ref('ctx.stash.get("hasAuth")')), exp), toJson(obj({}))]), | ||
); | ||
}; |
@@ -155,2 +155,4 @@ import { | ||
const statements: Expression[] = [ | ||
// set key the condition | ||
...generateKeyConditionTemplate(false), | ||
// Generate conditions | ||
@@ -176,2 +178,3 @@ comment('Set the default values to put request'), | ||
// add conditions | ||
iff(ref('context.args.condition'), qref(methodCall(ref('ctx.stash.conditions.add'), ref('context.args.condition')))), | ||
@@ -178,0 +181,0 @@ // key conditions |
@@ -19,10 +19,5 @@ import { | ||
and, | ||
isNullOrEmpty, | ||
list, | ||
forEach, | ||
nul, | ||
} from 'graphql-mapping-template'; | ||
import { ResourceConstants } from 'graphql-transformer-common'; | ||
const authFilter = ref('ctx.stash.authFilter'); | ||
/** | ||
@@ -33,41 +28,9 @@ * Generate get query resolver template | ||
const statements: Expression[] = [ | ||
set(ref('GetRequest'), obj({ version: str('2018-05-29'), operation: str('Query') })), | ||
set(ref('GetRequest'), obj({ version: str('2018-05-29'), operation: str('GetItem') })), | ||
ifElse( | ||
ref('ctx.stash.metadata.modelObjectKey'), | ||
compoundExpression([ | ||
set(ref('expression'), str('')), | ||
set(ref('expressionNames'), obj({})), | ||
set(ref('expressionValues'), obj({})), | ||
forEach(ref('item'), ref('ctx.stash.metadata.modelObjectKey.entrySet()'), [ | ||
set(ref('expression'), str('$expression#keyCount$velocityCount = :valueCount$velocityCount AND ')), | ||
qref(methodCall(ref('expressionNames.put'), str('#keyCount$velocityCount'), ref('item.key'))), | ||
qref(methodCall(ref('expressionValues.put'), str(':valueCount$velocityCount'), ref('item.value'))), | ||
]), | ||
set(ref('expression'), methodCall(ref('expression.replaceAll'), str('AND $'), str(''))), | ||
set( | ||
ref('query'), | ||
obj({ expression: ref('expression'), expressionNames: ref('expressionNames'), expressionValues: ref('expressionValues') }), | ||
), | ||
]), | ||
set( | ||
ref('query'), | ||
obj({ | ||
expression: str('id = :id'), | ||
expressionValues: obj({ | ||
':id': methodCall(ref('util.parseJson'), methodCall(ref('util.dynamodb.toDynamoDBJson'), ref('ctx.args.id'))), | ||
}), | ||
}), | ||
), | ||
set(ref('key'), ref('ctx.stash.metadata.modelObjectKey')), | ||
compoundExpression([set(ref('key'), obj({ id: methodCall(ref('util.dynamodb.toDynamoDB'), ref('ctx.args.id')) }))]), | ||
), | ||
qref(methodCall(ref('GetRequest.put'), str('query'), ref('query'))), | ||
iff( | ||
not(isNullOrEmpty(authFilter)), | ||
qref( | ||
methodCall( | ||
ref('GetRequest.put'), | ||
str('filter'), | ||
methodCall(ref('util.parseJson'), methodCall(ref('util.transform.toDynamoDBFilterExpression'), authFilter)), | ||
), | ||
), | ||
), | ||
qref(methodCall(ref('GetRequest.put'), str('key'), ref('key'))), | ||
toJson(ref('GetRequest')), | ||
@@ -79,24 +42,2 @@ ]; | ||
export const generateGetResponseTemplate = (isSyncEnabled: boolean): string => { | ||
const statements = new Array<Expression>(); | ||
if (isSyncEnabled) { | ||
statements.push( | ||
iff(ref('ctx.error'), methodCall(ref('util.error'), ref('ctx.error.message'), ref('ctx.error.type'), ref('ctx.result'))), | ||
); | ||
} else { | ||
statements.push(iff(ref('ctx.error'), methodCall(ref('util.error'), ref('ctx.error.message'), ref('ctx.error.type')))); | ||
} | ||
statements.push( | ||
ifElse( | ||
and([not(ref('ctx.result.items.isEmpty()')), equals(ref('ctx.result.scannedCount'), int(1))]), | ||
toJson(ref('ctx.result.items[0]')), | ||
compoundExpression([ | ||
iff(and([ref('ctx.result.items.isEmpty()'), equals(ref('ctx.result.scannedCount'), int(1))]), ref('util.unauthorized()')), | ||
toJson(nul()), | ||
]), | ||
), | ||
); | ||
return printBlock('Get Response template')(compoundExpression(statements)); | ||
}; | ||
export const generateListRequestTemplate = (): string => { | ||
@@ -116,16 +57,8 @@ const requestVariable = 'ListRequest'; | ||
iff(ref('context.args.nextToken'), set(ref(`${requestVariable}.nextToken`), ref('context.args.nextToken'))), | ||
ifElse( | ||
not(isNullOrEmpty(authFilter)), | ||
compoundExpression([ | ||
set(ref('filter'), authFilter), | ||
iff(not(isNullOrEmpty(ref('ctx.args.filter'))), set(ref('filter'), obj({ and: list([ref('filter'), ref('ctx.args.filter')]) }))), | ||
]), | ||
iff(not(isNullOrEmpty(ref('ctx.args.filter'))), set(ref('filter'), ref('ctx.args.filter'))), | ||
), | ||
iff( | ||
not(isNullOrEmpty(ref('filter'))), | ||
ref('context.args.filter'), | ||
compoundExpression([ | ||
set( | ||
ref(`filterExpression`), | ||
methodCall(ref('util.parseJson'), methodCall(ref('util.transform.toDynamoDBFilterExpression'), ref('filter'))), | ||
methodCall(ref('util.parseJson'), methodCall(ref('util.transform.toDynamoDBFilterExpression'), ref('ctx.args.filter'))), | ||
), | ||
@@ -169,33 +102,6 @@ iff( | ||
compoundExpression([ | ||
ifElse( | ||
not(isNullOrEmpty(authFilter)), | ||
compoundExpression([ | ||
set(ref('filter'), authFilter), | ||
iff(not(isNullOrEmpty(ref('ctx.args.filter'))), set(ref('filter'), obj({ and: list([ref('filter'), ref('ctx.args.filter')]) }))), | ||
]), | ||
iff(not(isNullOrEmpty(ref('ctx.args.filter'))), set(ref('filter'), ref('ctx.args.filter'))), | ||
), | ||
iff( | ||
not(isNullOrEmpty(ref('filter'))), | ||
compoundExpression([ | ||
set( | ||
ref(`filterExpression`), | ||
methodCall(ref('util.parseJson'), methodCall(ref('util.transform.toDynamoDBFilterExpression'), ref('filter'))), | ||
), | ||
iff( | ||
not(methodCall(ref('util.isNullOrBlank'), ref('filterExpression.expression'))), | ||
compoundExpression([ | ||
iff( | ||
equals(methodCall(ref('filterEpression.expressionValues.size')), int(0)), | ||
qref(methodCall(ref('filterEpression.remove'), str('expressionValues'))), | ||
), | ||
set(ref('filter'), ref('filterExpression')), | ||
]), | ||
), | ||
]), | ||
), | ||
obj({ | ||
version: str('2018-05-29'), | ||
operation: str('Sync'), | ||
filter: ifElse(ref('filter'), ref('util.toJson($filter)'), nul()), | ||
filter: ifElse(ref('context.args.filter'), ref('util.transform.toDynamoDBFilterExpression($ctx.args.filter)'), nul()), | ||
limit: ref(`util.defaultIfNull($ctx.args.limit, ${ResourceConstants.DEFAULT_SYNC_QUERY_PAGE_LIMIT})`), | ||
@@ -202,0 +108,0 @@ lastSync: ref('util.toJson($util.defaultIfNull($ctx.args.lastSync, null))'), |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
925686
5913
+ Added@aws-amplify/graphql-transformer-core@0.9.3-ext1.0(transitive)
+ Added@aws-amplify/graphql-transformer-interfaces@1.10.1-ext1.0(transitive)
+ Addedgraphql-mapping-template@4.18.3(transitive)
+ Addedgraphql-transformer-common@4.19.11-ext1.0(transitive)
- Removed@aws-amplify/graphql-transformer-core@0.9.3-amplify-export2.0(transitive)
- Removed@aws-amplify/graphql-transformer-interfaces@1.10.1-amplify-export2.0(transitive)
- Removedgraphql-mapping-template@4.18.4-amplify-export2.0(transitive)
- Removedgraphql-transformer-common@4.19.11-amplify-export2.0(transitive)
Updated@aws-amplify/graphql-transformer-interfaces@1.10.1-ext1.0