From 5c77029cb021690a4f617b83b4999ed55bf9dea1 Mon Sep 17 00:00:00 2001 From: Adrien de Peretti Date: Mon, 23 Oct 2023 19:21:07 +0200 Subject: [PATCH] fix(orchestration): field alias should represent the isList in the result (#5449) * fix(orchestration): field alias should represent the isList in the result * push last fix * Create witty-rocks-heal.md * Update remote-joiner.ts Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com> --------- Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com> --- .changeset/witty-rocks-heal.md | 5 +++++ packages/orchestration/src/joiner/remote-joiner.ts | 10 ++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 .changeset/witty-rocks-heal.md diff --git a/.changeset/witty-rocks-heal.md b/.changeset/witty-rocks-heal.md new file mode 100644 index 0000000000..9710c6c901 --- /dev/null +++ b/.changeset/witty-rocks-heal.md @@ -0,0 +1,5 @@ +--- +"@medusajs/orchestration": patch +--- + +fix(orchestration): field alias should represent the isList in the result diff --git a/packages/orchestration/src/joiner/remote-joiner.ts b/packages/orchestration/src/joiner/remote-joiner.ts index 307811692e..47b9da14d6 100644 --- a/packages/orchestration/src/joiner/remote-joiner.ts +++ b/packages/orchestration/src/joiner/remote-joiner.ts @@ -30,6 +30,7 @@ export class RemoteJoiner { location: string[] property: string path: string[] + isList?: boolean }[] = [] private static filterFields( @@ -389,13 +390,15 @@ export class RemoteJoiner { } if (Array.isArray(currentItems)) { - if (currentItems.length < 2) { + if (currentItems.length < 2 && !alias.isList) { locationItem[alias.property] = currentItems.shift() } else { locationItem[alias.property] = currentItems } } else { - locationItem[alias.property] = currentItems + locationItem[alias.property] = alias.isList + ? [currentItems] + : currentItems } if (parentRemoveItems !== null) { @@ -596,6 +599,9 @@ export class RemoteJoiner { location: currentPath, property: prop, path: fullPath, + isList: !!serviceConfig.relationships?.find( + (relationship) => relationship.alias === fullPath[0] + )?.isList, }) const extMapping = expands as unknown[]