UNPKG

@aws-amplify/graphql-model-transformer

Version:
38 lines 4.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.generateDefaultResponseMappingTemplate = exports.generateConditionSlot = void 0; const graphql_mapping_template_1 = require("graphql-mapping-template"); const definitions_1 = require("../../definitions"); const generateConditionSlot = (inputConditionObjectName, conditionOutputVariableName) => { const statements = [ (0, graphql_mapping_template_1.comment)('Start condition block'), (0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.and)([(0, graphql_mapping_template_1.ref)(inputConditionObjectName), (0, graphql_mapping_template_1.notEquals)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)(`${inputConditionObjectName}.size`)), (0, graphql_mapping_template_1.int)(0))]), (0, graphql_mapping_template_1.compoundExpression)([ (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)('mergedConditions'), (0, graphql_mapping_template_1.obj)({ and: (0, graphql_mapping_template_1.ref)(inputConditionObjectName) })), (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(conditionOutputVariableName), (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.toDynamoDBConditionExpression'), (0, graphql_mapping_template_1.ref)('mergedConditions')))), (0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.and)([ (0, graphql_mapping_template_1.ref)(`${conditionOutputVariableName}.expressionValues`), (0, graphql_mapping_template_1.equals)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)(`${conditionOutputVariableName}.expressionValues.size`)), (0, graphql_mapping_template_1.int)(0)), ]), (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(conditionOutputVariableName), (0, graphql_mapping_template_1.obj)({ expression: (0, graphql_mapping_template_1.ref)(`${conditionOutputVariableName}.expression`), expressionNames: (0, graphql_mapping_template_1.ref)(`${conditionOutputVariableName}.expressionNames`), }))), (0, graphql_mapping_template_1.comment)('End condition block'), ])), ]; return (0, graphql_mapping_template_1.compoundExpression)(statements); }; exports.generateConditionSlot = generateConditionSlot; const generateDefaultResponseMappingTemplate = (isSyncEnabled, mutation = false) => { const statements = []; if (mutation) statements.push((0, graphql_mapping_template_1.qref)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('ctx.result.put'), (0, graphql_mapping_template_1.str)(definitions_1.OPERATION_KEY), (0, graphql_mapping_template_1.str)('Mutation')))); if (isSyncEnabled) { statements.push((0, graphql_mapping_template_1.ifElse)((0, graphql_mapping_template_1.ref)('ctx.error'), (0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('util.error'), (0, graphql_mapping_template_1.ref)('ctx.error.message'), (0, graphql_mapping_template_1.ref)('ctx.error.type'), (0, graphql_mapping_template_1.ref)('ctx.result')), (0, graphql_mapping_template_1.toJson)((0, graphql_mapping_template_1.ref)('ctx.result')))); } else { statements.push((0, graphql_mapping_template_1.ifElse)((0, graphql_mapping_template_1.ref)('ctx.error'), (0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('util.error'), (0, graphql_mapping_template_1.ref)('ctx.error.message'), (0, graphql_mapping_template_1.ref)('ctx.error.type')), (0, graphql_mapping_template_1.toJson)((0, graphql_mapping_template_1.ref)('ctx.result')))); } return (0, graphql_mapping_template_1.printBlock)('ResponseTemplate')((0, graphql_mapping_template_1.compoundExpression)(statements)); }; exports.generateDefaultResponseMappingTemplate = generateDefaultResponseMappingTemplate; //# sourceMappingURL=common.js.map