feat(medusa): Allow empty fields/expand (#3220)
This commit is contained in:
@@ -39,7 +39,7 @@ export function getRetrieveConfig<TModel extends BaseEntity>(
|
||||
|
||||
return {
|
||||
select: includeFields.length ? includeFields : defaultFields,
|
||||
relations: expandFields.length ? expandFields : defaultRelations,
|
||||
relations: isDefined(expand) ? expandFields : defaultRelations,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ export function getListConfig<TModel extends BaseEntity>(
|
||||
|
||||
return {
|
||||
select: includeFields.length ? includeFields : defaultFields,
|
||||
relations: expandFields.length ? expandFields : defaultRelations,
|
||||
relations: isDefined(expand) ? expandFields : defaultRelations,
|
||||
skip: offset,
|
||||
take: limit,
|
||||
order: orderBy,
|
||||
@@ -88,13 +88,13 @@ export function prepareListQuery<
|
||||
const { order, fields, expand, limit, offset } = validated
|
||||
|
||||
let expandRelations: string[] | undefined = undefined
|
||||
if (expand) {
|
||||
expandRelations = expand.split(",")
|
||||
if (isDefined(expand)) {
|
||||
expandRelations = expand.split(",").filter((v) => v)
|
||||
}
|
||||
|
||||
let expandFields: (keyof TEntity)[] | undefined = undefined
|
||||
if (fields) {
|
||||
expandFields = fields.split(",") as (keyof TEntity)[]
|
||||
if (isDefined(fields)) {
|
||||
expandFields = (fields.split(",") as (keyof TEntity)[]).filter((v) => v)
|
||||
}
|
||||
|
||||
if (expandFields?.length && queryConfig?.allowedFields?.length) {
|
||||
@@ -144,14 +144,14 @@ export function prepareRetrieveQuery<
|
||||
>(validated: T, queryConfig?: QueryConfig<TEntity>) {
|
||||
const { fields, expand } = validated
|
||||
|
||||
let expandRelations: string[] = []
|
||||
if (expand) {
|
||||
expandRelations = expand.split(",")
|
||||
let expandRelations: string[] | undefined = undefined
|
||||
if (isDefined(expand)) {
|
||||
expandRelations = expand.split(",").filter((v) => v)
|
||||
}
|
||||
|
||||
let expandFields: (keyof TEntity)[] | undefined = undefined
|
||||
if (fields) {
|
||||
expandFields = fields.split(",") as (keyof TEntity)[]
|
||||
if (isDefined(fields)) {
|
||||
expandFields = (fields.split(",") as (keyof TEntity)[]).filter((v) => v)
|
||||
}
|
||||
|
||||
if (expandFields?.length && queryConfig?.allowedFields?.length) {
|
||||
|
||||
Reference in New Issue
Block a user