feat(*): Modules export entities and fields (#5242)

This commit is contained in:
Carlos R. L. Rodrigues authored and GitHub committed 2023-10-03 14:20:43 -07:00
1 parent eeceec791c
commit 130cbc1f43
27 files changed
+801 -226

No files matched your search

+23 -41
View File
@@ -11,54 +11,36 @@ import {
ProductVariant,
} from "@models"
import ProductImage from "./models/product-image"
import moduleSchema from "./schema"
export enum LinkableKeys {
PRODUCT_ID = "product_id", // Main service ID must the first
PRODUCT_HANDLE = "product_handle",
VARIANT_ID = "variant_id",
VARIANT_SKU = "variant_sku",
PRODUCT_OPTION_ID = "product_option_id",
PRODUCT_TYPE_ID = "product_type_id",
PRODUCT_CATEGORY_ID = "product_category_id",
PRODUCT_COLLECTION_ID = "product_collection_id",
PRODUCT_TAG_ID = "product_tag_id",
PRODUCT_IMAGE_ID = "product_image_id",
export const LinkableKeys = {
product_id: Product.name,
product_handle: Product.name,
variant_id: ProductVariant.name,
variant_sku: ProductVariant.name,
product_option_id: ProductOption.name,
product_type_id: ProductType.name,
product_category_id: ProductCategory.name,
product_collection_id: ProductCollection.name,
product_tag_id: ProductTag.name,
product_image_id: ProductImage.name,
}
export const entityNameToLinkableKeysMap: MapToConfig = {
[Product.name]: [
{ mapTo: LinkableKeys.PRODUCT_ID, valueFrom: "id" },
{
mapTo: LinkableKeys.PRODUCT_HANDLE,
valueFrom: "handle",
},
],
[ProductVariant.name]: [
{ mapTo: LinkableKeys.VARIANT_ID, valueFrom: "id" },
{ mapTo: LinkableKeys.VARIANT_SKU, valueFrom: "sku" },
],
[ProductOption.name]: [
{ mapTo: LinkableKeys.PRODUCT_OPTION_ID, valueFrom: "id" },
],
[ProductType.name]: [
{ mapTo: LinkableKeys.PRODUCT_TYPE_ID, valueFrom: "id" },
],
[ProductCategory.name]: [
{ mapTo: LinkableKeys.PRODUCT_CATEGORY_ID, valueFrom: "id" },
],
[ProductCollection.name]: [
{ mapTo: LinkableKeys.PRODUCT_COLLECTION_ID, valueFrom: "id" },
],
[ProductTag.name]: [{ mapTo: LinkableKeys.PRODUCT_TAG_ID, valueFrom: "id" }],
[ProductImage.name]: [
{ mapTo: LinkableKeys.PRODUCT_IMAGE_ID, valueFrom: "id" },
],
}
const entityLinkableKeysMap: MapToConfig = {}
Object.entries(LinkableKeys).forEach(([key, value]) => {
entityLinkableKeysMap[value] ??= []
entityLinkableKeysMap[value].push({
mapTo: key,
valueFrom: key.split("_").pop()!,
})
})
export const entityNameToLinkableKeysMap: MapToConfig = entityLinkableKeysMap
export const joinerConfig: ModuleJoinerConfig = {
serviceName: Modules.PRODUCT,
primaryKeys: ["id", "handle"],
linkableKeys: Object.values(LinkableKeys),
linkableKeys: LinkableKeys,
schema: moduleSchema,
alias: [
{
name: "product",
+154
View File
@@ -0,0 +1,154 @@
export default `
scalar Date
scalar JSON
enum ProductStatus {
DRAFT
PUBLISHED
ARCHIVED
}
type Product {
id: ID!
title: String!
handle: String
subtitle: String
description: String
isGiftcard: Boolean!
status: ProductStatus!
thumbnail: String
options: [ProductOption]
variants: [ProductVariant]
weight: Float
length: Float
height: Float
width: Float
originCountry: String
hsCode: String
midCode: String
material: String
collectionId: String
collection: ProductCollection
typeId: String
type: ProductType!
tags: [ProductTag]
images: [ProductImage]
categories: [ProductCategory]
discountable: Boolean!
externalId: String
createdAt: Date!
updatedAt: Date!
deletedAt: Date
metadata: JSON
}
type ProductVariant {
id: ID!
title: String!
sku: String
barcode: String
ean: String
upc: String
inventoryQuantity: Float!
allowBackorder: Boolean!
manageInventory: Boolean!
hsCode: String
originCountry: String
midCode: String
material: String
weight: Float
length: Float
height: Float
width: Float
metadata: JSON
variantRank: Float
productId: String!
createdAt: Date!
updatedAt: Date!
deletedAt: Date
product: Product!
options: [ProductOptionValue]
}
type ProductType {
id: ID!
value: String!
metadata: JSON
createdAt: Date!
updatedAt: Date!
deletedAt: Date
}
type ProductTag {
id: ID!
value: String!
metadata: JSON
createdAt: Date!
updatedAt: Date!
deletedAt: Date
products: [Product]
}
type ProductOption {
id: ID!
title: String!
productId: String!
product: Product!
values: [ProductOptionValue]
metadata: JSON
createdAt: Date!
updatedAt: Date!
deletedAt: Date
}
type ProductOptionValue {
id: ID!
value: String!
optionId: String!
option: ProductOption!
variantId: String!
variant: ProductVariant!
metadata: JSON
createdAt: Date!
updatedAt: Date!
deletedAt: Date
}
type ProductImage {
id: ID!
url: String!
metadata: JSON
createdAt: Date!
updatedAt: Date!
deletedAt: Date
products: [Product]
}
type ProductCollection {
id: ID!
title: String!
handle: String!
products: [Product]
metadata: JSON
createdAt: Date!
updatedAt: Date!
deletedAt: Date
}
type ProductCategory {
id: ID!
name: String!
description: String!
handle: String!
mpath: String!
isActive: Boolean!
isInternal: Boolean!
rank: Float!
parentCategoryId: String
parentCategory: ProductCategory
categoryChildren: [ProductCategory]
createdAt: Date!
updatedAt: Date!
products: [Product]
}
`