Skip to content

Commit

Permalink
fix(binding): merge has-many sub-mutations in mutation generator
Browse files Browse the repository at this point in the history
  • Loading branch information
matej21 committed Feb 26, 2024
1 parent abebdc2 commit 55d41d3
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions packages/binding/src/core/MutationGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
}

}
Expand All @@ -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
}
Expand Down

0 comments on commit 55d41d3

Please sign in to comment.