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:
1 parent
202049f8aa
commit
19c5d5ba36
3 files changed
+105
-225
No files matched your search
@@ -10,7 +10,7 @@ import { IsOptional, IsString } from "class-validator"
|
|||||||
import { PriceSelectionParams } from "../../../../types/price-selection"
|
import { PriceSelectionParams } from "../../../../types/price-selection"
|
||||||
import { cleanResponseData } from "../../../../utils"
|
import { cleanResponseData } from "../../../../utils"
|
||||||
import IsolateProductDomain from "../../../../loaders/feature-flags/isolate-product-domain"
|
import IsolateProductDomain from "../../../../loaders/feature-flags/isolate-product-domain"
|
||||||
import { defaultStoreProductsFields } from "./index"
|
import { defaultStoreRemoteQueryFields } from "./index"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [get] /store/products/{id}
|
* @oas [get] /store/products/{id}
|
||||||
@@ -166,116 +166,15 @@ async function getProductWithIsolatedProductModule(req, id: string) {
|
|||||||
const remoteQuery = req.scope.resolve("remoteQuery")
|
const remoteQuery = req.scope.resolve("remoteQuery")
|
||||||
|
|
||||||
const variables = { id }
|
const variables = { id }
|
||||||
const commonProperties = []
|
|
||||||
|
|
||||||
const query = `
|
const query = {
|
||||||
query ($id: String!) {
|
product: {
|
||||||
product (id: $id) {
|
__args: variables,
|
||||||
${defaultStoreProductsFields.join("\n")}
|
...defaultStoreRemoteQueryFields,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
images {
|
const [product] = await remoteQuery(query)
|
||||||
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 [product] = await remoteQuery(query, variables)
|
|
||||||
|
|
||||||
product.profile_id = product.profile?.id
|
product.profile_id = product.profile?.id
|
||||||
|
|
||||||
|
|||||||
@@ -111,6 +111,95 @@ export const allowedStoreProductsRelations = [
|
|||||||
"sales_channels",
|
"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 "./list-products"
|
||||||
export * from "./search"
|
export * from "./search"
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import { cleanResponseData } from "../../../../utils/clean-response-data"
|
|||||||
import { defaultStoreCategoryScope } from "../product-categories"
|
import { defaultStoreCategoryScope } from "../product-categories"
|
||||||
import { optionalBooleanMapper } from "../../../../utils/validators/is-boolean"
|
import { optionalBooleanMapper } from "../../../../utils/validators/is-boolean"
|
||||||
import IsolateProductDomain from "../../../../loaders/feature-flags/isolate-product-domain"
|
import IsolateProductDomain from "../../../../loaders/feature-flags/isolate-product-domain"
|
||||||
import { defaultStoreProductsFields } from "./index"
|
import { defaultStoreRemoteQueryFields } from "./index"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [get] /store/products
|
* @oas [get] /store/products
|
||||||
@@ -394,125 +394,17 @@ async function listAndCountProductWithIsolatedProductModule(
|
|||||||
take: listConfig.take,
|
take: listConfig.take,
|
||||||
}
|
}
|
||||||
|
|
||||||
// prettier-ignore
|
const query = {
|
||||||
const args = `
|
product: {
|
||||||
filters: $filters,
|
__args: variables,
|
||||||
order: $order,
|
...defaultStoreRemoteQueryFields,
|
||||||
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 {
|
const {
|
||||||
rows: products,
|
rows: products,
|
||||||
metadata: { count },
|
metadata: { count },
|
||||||
} = await remoteQuery(query, variables)
|
} = await remoteQuery(query)
|
||||||
|
|
||||||
products.forEach((product) => {
|
products.forEach((product) => {
|
||||||
product.profile_id = product.profile?.id
|
product.profile_id = product.profile?.id
|
||||||
|
|||||||
Reference in new issue
Block a user