fix(medusa): Fix get-query-config backward compatiblity (#6913)
This commit is contained in:
@@ -24,6 +24,7 @@ export function prepareListQuery<
|
||||
T extends RequestQueryFields,
|
||||
TEntity extends BaseEntity
|
||||
>(validated: T, queryConfig: QueryConfig<TEntity> = {}) {
|
||||
// TODO: this function will be simplified a lot once we drop support for the old api
|
||||
const { order, fields, limit = 50, expand, offset = 0 } = validated
|
||||
let {
|
||||
allowed = [],
|
||||
@@ -126,11 +127,11 @@ export function prepareListQuery<
|
||||
)
|
||||
}
|
||||
|
||||
// TODO: maintain backward compatibility, remove in the future
|
||||
const { select, relations } = stringToSelectRelationObject(
|
||||
Array.from(allFields)
|
||||
)
|
||||
|
||||
// TODO: maintain backward compatibility, remove in the future
|
||||
let allRelations = new Set([
|
||||
...relations,
|
||||
...defaultRelations,
|
||||
@@ -141,21 +142,22 @@ export function prepareListQuery<
|
||||
allRelations = new Set(expand.split(",").filter(Boolean))
|
||||
}
|
||||
|
||||
const allAllowedRelations = new Set([
|
||||
...Array.from(allAllowedFields),
|
||||
...allowedRelations,
|
||||
])
|
||||
const notAllowedRelations = !allowedRelations.length
|
||||
? new Set()
|
||||
: getSetDifference(allRelations, allAllowedRelations)
|
||||
if (allowedRelations.length && expand) {
|
||||
const allAllowedRelations = new Set([...allowedRelations])
|
||||
|
||||
if (allRelations.size && notAllowedRelations.size) {
|
||||
throw new MedusaError(
|
||||
MedusaError.Types.INVALID_DATA,
|
||||
`Requested fields [${Array.from(notAllowedRelations).join(
|
||||
", "
|
||||
)}] are not valid`
|
||||
const notAllowedRelations = getSetDifference(
|
||||
allRelations,
|
||||
allAllowedRelations
|
||||
)
|
||||
|
||||
if (allRelations.size && notAllowedRelations.size) {
|
||||
throw new MedusaError(
|
||||
MedusaError.Types.INVALID_DATA,
|
||||
`Requested fields [${Array.from(notAllowedRelations).join(
|
||||
", "
|
||||
)}] are not valid`
|
||||
)
|
||||
}
|
||||
}
|
||||
// End of expand compatibility
|
||||
|
||||
|
||||
Reference in New Issue
Block a user