Skip to content

Commit

Permalink
refactor: adds guards for fields with null values
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Zimmerman committed Nov 25, 2024
1 parent dc072dd commit 0f0a66f
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/runtime/src/cross/mutator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ async function doApplyMutation(
logging
);

if (r) {
if (r && typeof r === 'object') {
if (!arrayCloned) {
resultData = [...resultData];
arrayCloned = true;
Expand All @@ -160,9 +160,12 @@ async function doApplyMutation(
updated = true;
}
}
} else {
} else if (resultData !== null && typeof resultData === 'object') {
// Clone resultData to prevent mutations affecting the loop
const currentData = { ...resultData };

// iterate over each field and apply mutation to nested data models
for (const [key, value] of Object.entries(resultData)) {
for (const [key, value] of Object.entries(currentData)) {
const fieldInfo = modelFields[key];
if (!fieldInfo?.isDataModel) {
continue;
Expand All @@ -178,7 +181,7 @@ async function doApplyMutation(
logging
);

if (r) {
if (r && typeof r === 'object') {
resultData = { ...resultData, [key]: r };
updated = true;
}
Expand Down

0 comments on commit 0f0a66f

Please sign in to comment.