fix(modules-sdk): Select all should send undefined instead of an empty array (#6982)
This commit is contained in:
@@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/modules-sdk": patch
|
||||||
|
"@medusajs/orchestration": patch
|
||||||
|
"@medusajs/types": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix(modules-sdk): Select all should send undefined instead of an empty array
|
||||||
@@ -28,4 +28,20 @@ describe("Remote query", () => {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("should properly handle fields and relations transformation for top level entity", () => {
|
||||||
|
const expand = {
|
||||||
|
fields: ["*"],
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = RemoteQuery.getAllFieldsAndRelations(expand)
|
||||||
|
|
||||||
|
expect(result).toEqual({
|
||||||
|
select: undefined,
|
||||||
|
relations: [],
|
||||||
|
args: {
|
||||||
|
"": undefined,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -10,12 +10,11 @@ import {
|
|||||||
LoadedModule,
|
LoadedModule,
|
||||||
ModuleJoinerConfig,
|
ModuleJoinerConfig,
|
||||||
RemoteExpandProperty,
|
RemoteExpandProperty,
|
||||||
|
RemoteJoinerOptions,
|
||||||
RemoteJoinerQuery,
|
RemoteJoinerQuery,
|
||||||
RemoteNestedExpands,
|
RemoteNestedExpands,
|
||||||
} from "@medusajs/types"
|
} from "@medusajs/types"
|
||||||
import { isString, toPascalCase } from "@medusajs/utils"
|
import { isString, toPascalCase } from "@medusajs/utils"
|
||||||
|
|
||||||
import { RemoteJoinerOptions } from "@medusajs/types"
|
|
||||||
import { MedusaModule } from "./medusa-module"
|
import { MedusaModule } from "./medusa-module"
|
||||||
|
|
||||||
export class RemoteQuery {
|
export class RemoteQuery {
|
||||||
@@ -85,7 +84,7 @@ export class RemoteQuery {
|
|||||||
prefix = "",
|
prefix = "",
|
||||||
args: JoinerArgument = {} as JoinerArgument
|
args: JoinerArgument = {} as JoinerArgument
|
||||||
): {
|
): {
|
||||||
select: string[]
|
select?: string[]
|
||||||
relations: string[]
|
relations: string[]
|
||||||
args: JoinerArgument
|
args: JoinerArgument
|
||||||
} {
|
} {
|
||||||
@@ -96,7 +95,7 @@ export class RemoteQuery {
|
|||||||
|
|
||||||
for (const field of expand.fields ?? []) {
|
for (const field of expand.fields ?? []) {
|
||||||
if (field === "*") {
|
if (field === "*") {
|
||||||
expand.fields = []
|
expand.fields = undefined
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
fields.add(prefix ? `${prefix}.${field}` : field)
|
fields.add(prefix ? `${prefix}.${field}` : field)
|
||||||
@@ -116,11 +115,12 @@ export class RemoteQuery {
|
|||||||
args
|
args
|
||||||
)
|
)
|
||||||
|
|
||||||
result.select.forEach(fields.add, fields)
|
result.select?.forEach(fields.add, fields)
|
||||||
relations = relations.concat(result.relations)
|
relations = relations.concat(result.relations)
|
||||||
}
|
}
|
||||||
|
|
||||||
return { select: [...fields], relations, args }
|
const allFields = Array.from(fields)
|
||||||
|
return { select: allFields.length ? allFields : undefined, relations, args }
|
||||||
}
|
}
|
||||||
|
|
||||||
private hasPagination(options: { [attr: string]: unknown }): boolean {
|
private hasPagination(options: { [attr: string]: unknown }): boolean {
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ export class RemoteJoiner {
|
|||||||
|
|
||||||
private static filterFields(
|
private static filterFields(
|
||||||
data: any,
|
data: any,
|
||||||
fields: string[],
|
fields?: string[],
|
||||||
expands?: RemoteNestedExpands
|
expands?: RemoteNestedExpands
|
||||||
): Record<string, unknown> | undefined {
|
): Record<string, unknown> | undefined {
|
||||||
if (!fields || !data) {
|
if (!fields || !data) {
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ export interface RemoteJoinerOptions {
|
|||||||
|
|
||||||
export interface RemoteNestedExpands {
|
export interface RemoteNestedExpands {
|
||||||
[key: string]: {
|
[key: string]: {
|
||||||
fields: string[]
|
fields?: string[]
|
||||||
args?: JoinerArgument[]
|
args?: JoinerArgument[]
|
||||||
expands?: RemoteNestedExpands
|
expands?: RemoteNestedExpands
|
||||||
}
|
}
|
||||||
@@ -101,7 +101,7 @@ export interface RemoteExpandProperty {
|
|||||||
parent: string
|
parent: string
|
||||||
parentConfig?: JoinerServiceConfig
|
parentConfig?: JoinerServiceConfig
|
||||||
serviceConfig: JoinerServiceConfig
|
serviceConfig: JoinerServiceConfig
|
||||||
fields: string[]
|
fields?: string[]
|
||||||
args?: JoinerArgument[]
|
args?: JoinerArgument[]
|
||||||
expands?: RemoteNestedExpands
|
expands?: RemoteNestedExpands
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user