Skip to content

Commit

Permalink
fix: change GraphQL unlink to use update action instead of delete
Browse files Browse the repository at this point in the history
  • Loading branch information
awinberg-aws committed Jul 25, 2023
1 parent 690f928 commit 0a4d469
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4232,7 +4232,7 @@ import { getOverrideProps } from \\"@aws-amplify/ui-react/internal\\";
import { fetchByPath, validateField } from \\"./utils\\";
import { API } from \\"aws-amplify\\";
import { commentsByPostID, getPost, listComments } from \\"../graphql/queries\\";
import { deleteComment, updateComment, updatePost } from \\"../graphql/mutations\\";
import { updateComment, updatePost } from \\"../graphql/mutations\\";
function ArrayField({
items = [],
onChange,
Expand Down Expand Up @@ -4620,10 +4620,11 @@ export default function PostUpdateForm(props) {
}
promises.push(
API.graphql({
query: deleteComment,
query: updateComment,
variables: {
input: {
id: original.id,
postID: null,
},
},
})
Expand Down Expand Up @@ -7739,7 +7740,6 @@ import {
} from \\"../graphql/queries\\";
import {
createCPKTeacherCPKClass,
deleteCPKProject,
deleteCPKTeacherCPKClass,
updateCPKProject,
updateCPKTeacher,
Expand Down Expand Up @@ -8321,10 +8321,11 @@ export default function UpdateCPKTeacherForm(props) {
}
promises.push(
API.graphql({
query: deleteCPKProject,
query: updateCPKProject,
variables: {
input: {
specialProjectId: original.specialProjectId,
cPKTeacherID: null,
},
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {
getRecordName,
} from './form-state';
import { buildBaseCollectionVariableStatement } from '../../react-studio-template-renderer-helper';
import { ImportCollection, ImportSource } from '../../imports';
import { ImportCollection } from '../../imports';
import { lowerCaseFirst, getSetNameIdentifier, capitalizeFirstLetter } from '../../helpers';
import { isManyToManyRelationship } from './map-from-fieldConfigs';
import { extractModelAndKeys, getIDValueCallChain, getMatchEveryModelFieldCallExpression } from './model-values';
Expand Down Expand Up @@ -1233,7 +1233,7 @@ export const buildHasManyRelationshipStatements = (
fieldName = fieldConfigMetaData.sanitizedFieldName || fieldName;
const { relatedModelName, relatedModelFields, belongsToFieldOnRelatedModel } =
fieldConfigMetaData.relationship as HasManyRelationshipType;
const relatedModelVariableName = importCollection.getMappedAlias(ImportSource.LOCAL_MODELS, relatedModelName);
const relatedModelVariableName = importCollection.getMappedModelAlias(relatedModelName);
const linkedDataName = getLinkedDataName(fieldName);
const dataToLink = `${lowerCaseFirst(fieldName)}ToLink`;
const dataToUnLink = `${lowerCaseFirst(fieldName)}ToUnLink`;
Expand Down Expand Up @@ -1566,16 +1566,25 @@ export const buildHasManyRelationshipStatements = (
undefined,
[
dataApi === 'GraphQL'
? getGraphqlCallExpression(ActionType.DELETE, relatedModelName, importCollection, {
inputs: keys.map((key) =>
factory.createPropertyAssignment(
factory.createIdentifier(key),
factory.createPropertyAccessExpression(
factory.createIdentifier('original'),
? getGraphqlCallExpression(ActionType.UPDATE, relatedModelName, importCollection, {
inputs: keys
.map((key) =>
factory.createPropertyAssignment(
factory.createIdentifier(key),
factory.createPropertyAccessExpression(
factory.createIdentifier('original'),
factory.createIdentifier(key),
),
),
)
.concat(
relatedModelFields.map((key) =>
factory.createPropertyAssignment(
factory.createIdentifier(key),
factory.createNull(),
),
),
),
),
})
: getUpdateRelatedModelExpression(
thisModelRecord,
Expand Down

0 comments on commit 0a4d469

Please sign in to comment.