@aws-amplify/graphql-sql-transformer
Advanced tools
Comparing version 0.2.8 to 0.3.0-gen2-release.0
@@ -6,4 +6,10 @@ # Change Log | ||
## [0.2.8](https://github.com/aws-amplify/amplify-category-api/compare/@aws-amplify/graphql-sql-transformer@0.2.7...@aws-amplify/graphql-sql-transformer@0.2.8) (2024-03-28) | ||
# [0.3.0-gen2-release.0](https://github.com/aws-amplify/amplify-category-api/compare/@aws-amplify/graphql-sql-transformer@0.2.8-gen2-release.0...@aws-amplify/graphql-sql-transformer@0.3.0-gen2-release.0) (2024-03-28) | ||
### Features | ||
- iam access support for searchable, index and sql directives ([#2398](https://github.com/aws-amplify/amplify-category-api/issues/2398)) ([c2a3d92](https://github.com/aws-amplify/amplify-category-api/commit/c2a3d92e89891e9585aa1c26731f132171e271be)) | ||
## [0.2.8-gen2-release.0](https://github.com/aws-amplify/amplify-category-api/compare/@aws-amplify/graphql-sql-transformer@0.2.7...@aws-amplify/graphql-sql-transformer@0.2.8-gen2-release.0) (2024-03-27) | ||
**Note:** Version bump only for package @aws-amplify/graphql-sql-transformer | ||
@@ -10,0 +16,0 @@ |
@@ -28,3 +28,2 @@ "use strict"; | ||
const graphql_transformer_core_1 = require("@aws-amplify/graphql-transformer-core"); | ||
const graphql_directives_1 = require("@aws-amplify/graphql-directives"); | ||
const cdk = __importStar(require("aws-cdk-lib")); | ||
@@ -34,5 +33,8 @@ const graphql_mapping_template_1 = require("graphql-mapping-template"); | ||
const SQL_DIRECTIVE_STACK = 'CustomSQLStack'; | ||
const directiveDefinition = ` | ||
directive @sql(statement: String, reference: String) on FIELD_DEFINITION | ||
`; | ||
class SqlTransformer extends graphql_transformer_core_1.TransformerPluginBase { | ||
constructor() { | ||
super('amplify-sql-transformer', graphql_directives_1.SqlDirective.definition); | ||
super('amplify-sql-transformer', directiveDefinition); | ||
this.sqlDirectiveFields = new Map(); | ||
@@ -86,3 +88,3 @@ this.field = (parent, definition, directive, ctx) => { | ||
const resolver = context.resolvers.generateQueryResolver(config.resolverTypeName, config.resolverFieldName, resolverResourceId, dataSource, graphql_transformer_core_1.MappingTemplate.s3MappingTemplateFromString((0, exports.generateSqlLambdaRequestTemplate)(statement, 'RAW_SQL', config.resolverFieldName), `${config.resolverTypeName}.${config.resolverFieldName}.req.vtl`), graphql_transformer_core_1.MappingTemplate.s3MappingTemplateFromString((0, exports.generateSqlLambdaResponseMappingTemplate)(), `${config.resolverTypeName}.${config.resolverFieldName}.res.vtl`)); | ||
resolver.addToSlot('postAuth', graphql_transformer_core_1.MappingTemplate.s3MappingTemplateFromString(generateAuthExpressionForSandboxMode(context.transformParameters.sandboxModeEnabled), `${config.resolverTypeName}.${config.resolverFieldName}.{slotName}.{slotIndex}.req.vtl`)); | ||
resolver.addToSlot('postAuth', graphql_transformer_core_1.MappingTemplate.s3MappingTemplateFromString(generateAuthExpressionForSandboxMode(context.transformParameters.sandboxModeEnabled, context.synthParameters.enableIamAccess), `${config.resolverTypeName}.${config.resolverFieldName}.{slotName}.{slotIndex}.req.vtl`)); | ||
resolver.setScope(context.stackManager.getScopeFor(resolverResourceId, SQL_DIRECTIVE_STACK)); | ||
@@ -96,10 +98,19 @@ context.resolvers.addResolver(config.resolverTypeName, config.resolverFieldName, resolver); | ||
exports.SqlTransformer = SqlTransformer; | ||
const generateAuthExpressionForSandboxMode = (enabled) => { | ||
let exp; | ||
const generateAuthExpressionForSandboxMode = (isSandboxModeEnabled, genericIamAccessEnabled) => { | ||
const API_KEY = 'API Key Authorization'; | ||
if (enabled) | ||
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'))); | ||
else | ||
exp = (0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('util.unauthorized')); | ||
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)({}))])); | ||
const IAM_AUTH_TYPE = 'IAM Authorization'; | ||
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'}`)((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)({}))])); | ||
}; | ||
@@ -106,0 +117,0 @@ const getStatementFromStatementAttribute = (config) => { |
{ | ||
"name": "@aws-amplify/graphql-sql-transformer", | ||
"version": "0.2.8", | ||
"version": "0.3.0-gen2-release.0", | ||
"description": "Amplify GraphQL @sql transformer", | ||
@@ -31,12 +31,11 @@ "repository": { | ||
"dependencies": { | ||
"@aws-amplify/graphql-directives": "1.0.1", | ||
"@aws-amplify/graphql-model-transformer": "2.7.0", | ||
"@aws-amplify/graphql-transformer-core": "2.5.1", | ||
"@aws-amplify/graphql-transformer-interfaces": "3.5.0", | ||
"@aws-amplify/graphql-model-transformer": "2.7.0-gen2-release.1", | ||
"@aws-amplify/graphql-transformer-core": "2.5.1-gen2-release.1", | ||
"@aws-amplify/graphql-transformer-interfaces": "3.5.0-gen2-release.1", | ||
"graphql": "^15.5.0", | ||
"graphql-mapping-template": "4.20.15", | ||
"graphql-transformer-common": "4.29.0" | ||
"graphql-transformer-common": "4.29.0-gen2-release.0" | ||
}, | ||
"devDependencies": { | ||
"@aws-amplify/graphql-transformer-test-utils": "0.4.7" | ||
"@aws-amplify/graphql-transformer-test-utils": "0.4.7-gen2-release.1" | ||
}, | ||
@@ -84,3 +83,3 @@ "peerDependencies": { | ||
}, | ||
"gitHead": "ac8990dd06d7b6a29c079e84a7c1e23ec5708fc1" | ||
"gitHead": "8ca8bbf65e77c30c0089ca4c91b8b28f27f22973" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
41910
8
184
+ Added@aws-amplify/graphql-model-transformer@2.7.0-gen2-release.1(transitive)
+ Added@aws-amplify/graphql-transformer-core@2.5.1-gen2-release.1(transitive)
+ Added@aws-amplify/graphql-transformer-interfaces@3.5.0-gen2-release.1(transitive)
+ Addedgraphql-transformer-common@4.29.0-gen2-release.0(transitive)
- Removed@aws-amplify/graphql-directives@1.0.1(transitive)
- Removed@aws-amplify/graphql-model-transformer@2.7.0(transitive)
- Removed@aws-amplify/graphql-transformer-core@2.5.1(transitive)
- Removed@aws-amplify/graphql-transformer-interfaces@3.5.0(transitive)
- Removedgraphql-transformer-common@4.29.0(transitive)
Updated@aws-amplify/graphql-model-transformer@2.7.0-gen2-release.1
Updated@aws-amplify/graphql-transformer-core@2.5.1-gen2-release.1
Updated@aws-amplify/graphql-transformer-interfaces@3.5.0-gen2-release.1