From 55d41d3660079cacb523daba0bf842e4b60ae200 Mon Sep 17 00:00:00 2001 From: David Matejka Date: Mon, 26 Feb 2024 13:49:28 +0100 Subject: [PATCH] fix(binding): merge has-many sub-mutations in mutation generator --- .../binding/src/core/MutationGenerator.ts | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/packages/binding/src/core/MutationGenerator.ts b/packages/binding/src/core/MutationGenerator.ts index abadc35489..5cee207e46 100644 --- a/packages/binding/src/core/MutationGenerator.ts +++ b/packages/binding/src/core/MutationGenerator.ts @@ -366,7 +366,12 @@ export class MutationGenerator { field.marker, ) if (input !== undefined) { - result[field.marker.parameters.field] = input + const current = result[field.marker.parameters.field] + if (Array.isArray(input) && Array.isArray(current)) { + current.push(...input) + } else { + result[field.marker.parameters.field] = input + } } break } @@ -376,7 +381,12 @@ export class MutationGenerator { field.fieldState, ) if (input !== undefined) { - result[field.marker.parameters.field] = input + const current = result[field.marker.parameters.field] + if (Array.isArray(current)) { + current.push(...input) + } else { + result[field.marker.parameters.field] = input + } } break } @@ -534,7 +544,12 @@ export class MutationGenerator { } else { const relationData = this.getUpdateManyRelationForReducedInput(currentState, fieldState, persistedValue, processedPlaceholdersByEntity, placeholderName, reducedBy) if (relationData !== undefined) { - result[marker.parameters.field] = relationData + const current = result[marker.parameters.field] + if (Array.isArray(current)) { + current.push(...relationData) + } else { + result[marker.parameters.field] = relationData + } } } @@ -555,7 +570,12 @@ export class MutationGenerator { } const relationData = this.getUpdateManyRelationInput(fieldState, persistedEntityIds, processedPlaceholdersByEntity) if (relationData !== undefined) { - result[marker.parameters.field] = relationData + const current = result[marker.parameters.field] + if (Array.isArray(current)) { + current.push(...relationData) + } else { + result[marker.parameters.field] = relationData + } } break }