feat(medusa): Migrate remote query usage in store product domain to use an object (#5131)
* feat(medusa): Migrate remote query usage in store product domain to use an object * fix profile level
This commit is contained in:
committed by
GitHub
parent
202049f8aa
commit
19c5d5ba36
@@ -10,7 +10,7 @@ import { IsOptional, IsString } from "class-validator"
|
||||
import { PriceSelectionParams } from "../../../../types/price-selection"
|
||||
import { cleanResponseData } from "../../../../utils"
|
||||
import IsolateProductDomain from "../../../../loaders/feature-flags/isolate-product-domain"
|
||||
import { defaultStoreProductsFields } from "./index"
|
||||
import { defaultStoreRemoteQueryFields } from "./index"
|
||||
|
||||
/**
|
||||
* @oas [get] /store/products/{id}
|
||||
@@ -166,116 +166,15 @@ async function getProductWithIsolatedProductModule(req, id: string) {
|
||||
const remoteQuery = req.scope.resolve("remoteQuery")
|
||||
|
||||
const variables = { id }
|
||||
const commonProperties = []
|
||||
|
||||
const query = `
|
||||
query ($id: String!) {
|
||||
product (id: $id) {
|
||||
${defaultStoreProductsFields.join("\n")}
|
||||
|
||||
images {
|
||||
id
|
||||
created_at
|
||||
updated_at
|
||||
deleted_at
|
||||
url
|
||||
metadata
|
||||
}
|
||||
|
||||
tags {
|
||||
id
|
||||
created_at
|
||||
updated_at
|
||||
deleted_at
|
||||
value
|
||||
}
|
||||
|
||||
type {
|
||||
id
|
||||
created_at
|
||||
updated_at
|
||||
deleted_at
|
||||
value
|
||||
}
|
||||
|
||||
collection {
|
||||
title
|
||||
handle
|
||||
id
|
||||
created_at
|
||||
updated_at
|
||||
deleted_at
|
||||
}
|
||||
|
||||
options {
|
||||
id
|
||||
created_at
|
||||
updated_at
|
||||
deleted_at
|
||||
title
|
||||
product_id
|
||||
metadata
|
||||
values {
|
||||
id
|
||||
created_at
|
||||
updated_at
|
||||
deleted_at
|
||||
value
|
||||
option_id
|
||||
variant_id
|
||||
metadata
|
||||
}
|
||||
}
|
||||
|
||||
variants {
|
||||
id
|
||||
created_at
|
||||
updated_at
|
||||
deleted_at
|
||||
title
|
||||
product_id
|
||||
sku
|
||||
barcode
|
||||
ean
|
||||
upc
|
||||
variant_rank
|
||||
inventory_quantity
|
||||
allow_backorder
|
||||
manage_inventory
|
||||
hs_code
|
||||
origin_country
|
||||
mid_code
|
||||
material
|
||||
weight
|
||||
length
|
||||
height
|
||||
width
|
||||
metadata
|
||||
options {
|
||||
id
|
||||
created_at
|
||||
updated_at
|
||||
deleted_at
|
||||
value
|
||||
option_id
|
||||
variant_id
|
||||
metadata
|
||||
}
|
||||
}
|
||||
|
||||
profile {
|
||||
id
|
||||
created_at
|
||||
updated_at
|
||||
deleted_at
|
||||
name
|
||||
type
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
const query = {
|
||||
product: {
|
||||
__args: variables,
|
||||
...defaultStoreRemoteQueryFields,
|
||||
},
|
||||
}
|
||||
|
||||
const [product] = await remoteQuery(query, variables)
|
||||
const [product] = await remoteQuery(query)
|
||||
|
||||
product.profile_id = product.profile?.id
|
||||
|
||||
|
||||
@@ -111,6 +111,95 @@ export const allowedStoreProductsRelations = [
|
||||
"sales_channels",
|
||||
]
|
||||
|
||||
/**
|
||||
* This is temporary.
|
||||
*/
|
||||
export const defaultStoreRemoteQueryFields = {
|
||||
fields: defaultStoreProductsFields,
|
||||
images: {
|
||||
fields: ["id", "created_at", "updated_at", "deleted_at", "url", "metadata"],
|
||||
},
|
||||
tags: {
|
||||
fields: ["id", "created_at", "updated_at", "deleted_at", "value"],
|
||||
},
|
||||
|
||||
type: {
|
||||
fields: ["id", "created_at", "updated_at", "deleted_at", "value"],
|
||||
},
|
||||
|
||||
collection: {
|
||||
fields: ["title", "handle", "id", "created_at", "updated_at", "deleted_at"],
|
||||
},
|
||||
|
||||
options: {
|
||||
fields: [
|
||||
"id",
|
||||
"created_at",
|
||||
"updated_at",
|
||||
"deleted_at",
|
||||
"title",
|
||||
"product_id",
|
||||
"metadata",
|
||||
],
|
||||
values: {
|
||||
fields: [
|
||||
"id",
|
||||
"created_at",
|
||||
"updated_at",
|
||||
"deleted_at",
|
||||
"value",
|
||||
"option_id",
|
||||
"variant_id",
|
||||
"metadata",
|
||||
],
|
||||
},
|
||||
},
|
||||
|
||||
variants: {
|
||||
fields: [
|
||||
"id",
|
||||
"created_at",
|
||||
"updated_at",
|
||||
"deleted_at",
|
||||
"title",
|
||||
"product_id",
|
||||
"sku",
|
||||
"barcode",
|
||||
"ean",
|
||||
"upc",
|
||||
"variant_rank",
|
||||
"inventory_quantity",
|
||||
"allow_backorder",
|
||||
"manage_inventory",
|
||||
"hs_code",
|
||||
"origin_country",
|
||||
"mid_code",
|
||||
"material",
|
||||
"weight",
|
||||
"length",
|
||||
"height",
|
||||
"width",
|
||||
"metadata",
|
||||
],
|
||||
|
||||
options: {
|
||||
fields: [
|
||||
"id",
|
||||
"created_at",
|
||||
"updated_at",
|
||||
"deleted_at",
|
||||
"value",
|
||||
"option_id",
|
||||
"variant_id",
|
||||
"metadata",
|
||||
],
|
||||
},
|
||||
},
|
||||
profile: {
|
||||
fields: ["id", "created_at", "updated_at", "deleted_at", "name", "type"],
|
||||
},
|
||||
}
|
||||
|
||||
export * from "./list-products"
|
||||
export * from "./search"
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ import { cleanResponseData } from "../../../../utils/clean-response-data"
|
||||
import { defaultStoreCategoryScope } from "../product-categories"
|
||||
import { optionalBooleanMapper } from "../../../../utils/validators/is-boolean"
|
||||
import IsolateProductDomain from "../../../../loaders/feature-flags/isolate-product-domain"
|
||||
import { defaultStoreProductsFields } from "./index"
|
||||
import { defaultStoreRemoteQueryFields } from "./index"
|
||||
|
||||
/**
|
||||
* @oas [get] /store/products
|
||||
@@ -394,125 +394,17 @@ async function listAndCountProductWithIsolatedProductModule(
|
||||
take: listConfig.take,
|
||||
}
|
||||
|
||||
// prettier-ignore
|
||||
const args = `
|
||||
filters: $filters,
|
||||
order: $order,
|
||||
skip: $skip,
|
||||
take: $take
|
||||
`
|
||||
|
||||
const query = `
|
||||
query ($filters: any, $order: any, $skip: Int, $take: Int) {
|
||||
product (${args}) {
|
||||
${defaultStoreProductsFields.join("\n")}
|
||||
|
||||
images {
|
||||
id
|
||||
created_at
|
||||
updated_at
|
||||
deleted_at
|
||||
url
|
||||
metadata
|
||||
}
|
||||
|
||||
tags {
|
||||
id
|
||||
created_at
|
||||
updated_at
|
||||
deleted_at
|
||||
value
|
||||
}
|
||||
|
||||
type {
|
||||
id
|
||||
created_at
|
||||
updated_at
|
||||
deleted_at
|
||||
value
|
||||
}
|
||||
|
||||
collection {
|
||||
title
|
||||
handle
|
||||
id
|
||||
created_at
|
||||
updated_at
|
||||
deleted_at
|
||||
}
|
||||
|
||||
options {
|
||||
id
|
||||
created_at
|
||||
updated_at
|
||||
deleted_at
|
||||
title
|
||||
product_id
|
||||
metadata
|
||||
values {
|
||||
id
|
||||
created_at
|
||||
updated_at
|
||||
deleted_at
|
||||
value
|
||||
option_id
|
||||
variant_id
|
||||
metadata
|
||||
}
|
||||
}
|
||||
|
||||
variants {
|
||||
id
|
||||
created_at
|
||||
updated_at
|
||||
deleted_at
|
||||
title
|
||||
product_id
|
||||
sku
|
||||
barcode
|
||||
ean
|
||||
upc
|
||||
variant_rank
|
||||
inventory_quantity
|
||||
allow_backorder
|
||||
manage_inventory
|
||||
hs_code
|
||||
origin_country
|
||||
mid_code
|
||||
material
|
||||
weight
|
||||
length
|
||||
height
|
||||
width
|
||||
metadata
|
||||
options {
|
||||
id
|
||||
created_at
|
||||
updated_at
|
||||
deleted_at
|
||||
value
|
||||
option_id
|
||||
variant_id
|
||||
metadata
|
||||
}
|
||||
}
|
||||
|
||||
profile {
|
||||
id
|
||||
created_at
|
||||
updated_at
|
||||
deleted_at
|
||||
name
|
||||
type
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
const query = {
|
||||
product: {
|
||||
__args: variables,
|
||||
...defaultStoreRemoteQueryFields,
|
||||
},
|
||||
}
|
||||
|
||||
const {
|
||||
rows: products,
|
||||
metadata: { count },
|
||||
} = await remoteQuery(query, variables)
|
||||
} = await remoteQuery(query)
|
||||
|
||||
products.forEach((product) => {
|
||||
product.profile_id = product.profile?.id
|
||||
|
||||
Reference in New Issue
Block a user