diff --git a/packages/amplify-graphql-auth-transformer/src/vtl-generator/ddb/resolvers/helpers.ts b/packages/amplify-graphql-auth-transformer/src/vtl-generator/ddb/resolvers/helpers.ts index 1f5811012b..1d060e5baf 100644 --- a/packages/amplify-graphql-auth-transformer/src/vtl-generator/ddb/resolvers/helpers.ts +++ b/packages/amplify-graphql-auth-transformer/src/vtl-generator/ddb/resolvers/helpers.ts @@ -352,6 +352,9 @@ export const getOwnerClaimReference = (ownerClaim: string, refName: string): str return ownerRef; }; +/** + * Creates field resolver for owner + */ /** * Creates field resolver for owner */ @@ -359,27 +362,9 @@ export const generateFieldResolverForOwner = (entity: string): string => { const expressions: Expression[] = [ ifElse( methodCall(ref('util.isList'), ref(`ctx.source.${entity}`)), - compoundExpression([ - set(ref('ownerEntitiesList'), list([])), - set(ref(entity), ref(`ctx.source.${entity}`)), - forEach(ref('entities'), ref(entity), [ - set(ref('ownerEntities'), ref(`entities.split("${IDENTITY_CLAIM_DELIMITER}")`)), - set(ref('ownerEntitiesLastIdx'), raw('$ownerEntities.size() - 1')), - set(ref('ownerEntitiesLast'), ref('ownerEntities[$ownerEntitiesLastIdx]')), - qref(methodCall(ref('ownerEntitiesList.add'), ref('ownerEntitiesLast'))), - ]), - qref(methodCall(ref(`ctx.source.${entity}.put`), ref('ownerEntitiesList'))), - toJson(ref('ownerEntitiesList')), - ]), - compoundExpression([ - set(ref('ownerEntities'), ref(`ctx.source.${entity}.split("${IDENTITY_CLAIM_DELIMITER}")`)), - set(ref('ownerEntitiesLastIdx'), raw('$ownerEntities.size() - 1')), - set(ref('ownerEntitiesLast'), ref('ownerEntities[$ownerEntitiesLastIdx]')), - qref(methodCall(ref('ctx.source.put'), str(entity), ref('ownerEntitiesLast'))), - toJson(ref(`ctx.source.${entity}`)), - ]), + toJson(ref(`ctx.source.${entity}`)), + toJson(ref(`ctx.source.${entity}`)), ), ]; - return printBlock('Parse owner field auth for Get')(compoundExpression(expressions)); }; diff --git a/packages/amplify-graphql-auth-transformer/src/vtl-generator/rds/resolvers/common.ts b/packages/amplify-graphql-auth-transformer/src/vtl-generator/rds/resolvers/common.ts index 1f59812c88..a4d4df8214 100644 --- a/packages/amplify-graphql-auth-transformer/src/vtl-generator/rds/resolvers/common.ts +++ b/packages/amplify-graphql-auth-transformer/src/vtl-generator/rds/resolvers/common.ts @@ -259,6 +259,9 @@ export const setDeniedFieldFlag = (operation: string, subscriptionsEnabled: bool return ''; }; +/** + * Creates field resolver for owner + */ /** * Creates field resolver for owner */ @@ -266,28 +269,10 @@ export const generateFieldResolverForOwner = (entity: string): string => { const expressions: Expression[] = [ ifElse( methodCall(ref('util.isList'), ref(`ctx.source.${entity}`)), - compoundExpression([ - set(ref('ownerEntitiesList'), list([])), - set(ref(entity), ref(`ctx.source.${entity}`)), - forEach(ref('entities'), ref(entity), [ - set(ref('ownerEntities'), ref(`entities.split("${IDENTITY_CLAIM_DELIMITER}")`)), - set(ref('ownerEntitiesLastIdx'), raw('$ownerEntities.size() - 1')), - set(ref('ownerEntitiesLast'), ref('ownerEntities[$ownerEntitiesLastIdx]')), - qref(methodCall(ref('ownerEntitiesList.add'), ref('ownerEntitiesLast'))), - ]), - qref(methodCall(ref(`ctx.source.${entity}.put`), ref('ownerEntitiesList'))), - toJson(ref('ownerEntitiesList')), - ]), - compoundExpression([ - set(ref('ownerEntities'), ref(`ctx.source.${entity}.split("${IDENTITY_CLAIM_DELIMITER}")`)), - set(ref('ownerEntitiesLastIdx'), raw('$ownerEntities.size() - 1')), - set(ref('ownerEntitiesLast'), ref('ownerEntities[$ownerEntitiesLastIdx]')), - qref(methodCall(ref('ctx.source.put'), str(entity), ref('ownerEntitiesLast'))), - toJson(ref(`ctx.source.${entity}`)), - ]), + toJson(ref(`ctx.source.${entity}`)), + toJson(ref(`ctx.source.${entity}`)), ), ]; - return printBlock('Parse owner field auth for Get')(compoundExpression(expressions)); };