Skip to content

Commit

Permalink
fix(orchestration): field alias should represent the isList in the re…
Browse files Browse the repository at this point in the history
…sult (#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>
  • Loading branch information
adrien2p and olivermrbl authored Oct 23, 2023
1 parent c67d490 commit 5c77029
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/witty-rocks-heal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/orchestration": patch
---

fix(orchestration): field alias should represent the isList in the result
10 changes: 8 additions & 2 deletions packages/orchestration/src/joiner/remote-joiner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export class RemoteJoiner {
location: string[]
property: string
path: string[]
isList?: boolean
}[] = []

private static filterFields(
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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[]
Expand Down

0 comments on commit 5c77029

Please sign in to comment.