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[]