@aws-amplify/graphql-model-transformer
Version:
Amplify graphql @model transformer
32 lines • 2.98 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.defaultAutoId = exports.generateResolverKey = exports.generatePostAuthExpression = void 0;
const graphql_mapping_template_1 = require("graphql-mapping-template");
const API_KEY = 'API Key Authorization';
const IAM_AUTH_TYPE = 'IAM Authorization';
const generatePostAuthExpression = (isSandboxModeEnabled, genericIamAccessEnabled) => {
const expressions = [];
if (isSandboxModeEnabled) {
expressions.push((0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.equals)((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.ret)((0, graphql_mapping_template_1.toJson)((0, graphql_mapping_template_1.obj)({})))));
}
if (genericIamAccessEnabled) {
const isNonCognitoIAMPrincipal = (0, graphql_mapping_template_1.and)([
(0, graphql_mapping_template_1.equals)((0, graphql_mapping_template_1.ref)('util.authType()'), (0, graphql_mapping_template_1.str)(IAM_AUTH_TYPE)),
(0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('util.isNull'), (0, graphql_mapping_template_1.ref)('ctx.identity.cognitoIdentityPoolId')),
(0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('util.isNull'), (0, graphql_mapping_template_1.ref)('ctx.identity.cognitoIdentityId')),
]);
expressions.push((0, graphql_mapping_template_1.iff)(isNonCognitoIAMPrincipal, (0, graphql_mapping_template_1.ret)((0, graphql_mapping_template_1.toJson)((0, graphql_mapping_template_1.obj)({})))));
}
expressions.push((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('util.unauthorized')));
return (0, graphql_mapping_template_1.printBlock)(`Sandbox Mode ${isSandboxModeEnabled ? 'Enabled' : 'Disabled'}, IAM Access ${genericIamAccessEnabled ? '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")')), (0, graphql_mapping_template_1.compoundExpression)(expressions)), (0, graphql_mapping_template_1.toJson)((0, graphql_mapping_template_1.obj)({}))]));
};
exports.generatePostAuthExpression = generatePostAuthExpression;
const generateResolverKey = (typeName, fieldName) => {
return `${typeName}.${fieldName}`;
};
exports.generateResolverKey = generateResolverKey;
const defaultAutoId = () => {
return (0, graphql_mapping_template_1.qref)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('ctx.stash.defaultValues.put'), (0, graphql_mapping_template_1.str)('id'), (0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('util.autoId'))));
};
exports.defaultAutoId = defaultAutoId;
//# sourceMappingURL=common.js.map