diff --git a/.changeset/lucky-pets-glow.md b/.changeset/lucky-pets-glow.md new file mode 100644 index 0000000000000..d324d471b9232 --- /dev/null +++ b/.changeset/lucky-pets-glow.md @@ -0,0 +1,7 @@ +--- +"@medusajs/link-modules": patch +"@medusajs/types": patch +"@medusajs/utils": patch +--- + +Generate graph schema with readonly links diff --git a/integration-tests/modules/__tests__/link-modules/define-link.spec.ts b/integration-tests/modules/__tests__/link-modules/define-link.spec.ts index 1f6850adce9f4..82de7f5d6dd3a 100644 --- a/integration-tests/modules/__tests__/link-modules/define-link.spec.ts +++ b/integration-tests/modules/__tests__/link-modules/define-link.spec.ts @@ -67,6 +67,7 @@ medusaIntegrationTestRunner({ extends: [ { serviceName: "currency", + entity: "Currency", fieldAlias: { region: { path: "region_link.region", @@ -85,6 +86,7 @@ medusaIntegrationTestRunner({ }, { serviceName: "region", + entity: "Region", fieldAlias: { currency: { path: "currency_link.currency", @@ -164,6 +166,7 @@ medusaIntegrationTestRunner({ extends: [ { serviceName: "product", + entity: "ProductVariant", fieldAlias: { region: { path: "region_link.region", @@ -182,6 +185,7 @@ medusaIntegrationTestRunner({ }, { serviceName: "region", + entity: "Region", fieldAlias: { product_variant: { path: "product_variant_link.product_variant", @@ -266,6 +270,7 @@ medusaIntegrationTestRunner({ extends: [ { serviceName: "currency", + entity: "Currency", fieldAlias: { region: { path: "region_link.region", @@ -284,6 +289,7 @@ medusaIntegrationTestRunner({ }, { serviceName: "region", + entity: "Region", fieldAlias: { currency: { path: "currency_link.currency", @@ -362,6 +368,7 @@ medusaIntegrationTestRunner({ extends: [ { serviceName: "currency", + entity: "Currency", fieldAlias: { regions: { path: "region_link.region", @@ -380,6 +387,7 @@ medusaIntegrationTestRunner({ }, { serviceName: "region", + entity: "Region", fieldAlias: { currency: { path: "currency_link.currency", diff --git a/packages/core/types/src/joiner/index.ts b/packages/core/types/src/joiner/index.ts index e56da2a93536b..0760e650b3f81 100644 --- a/packages/core/types/src/joiner/index.ts +++ b/packages/core/types/src/joiner/index.ts @@ -48,6 +48,7 @@ export interface JoinerServiceConfig { relationships?: JoinerRelationship[] extends?: { serviceName: string + entity?: string relationship: JoinerRelationship }[] /** diff --git a/packages/core/types/src/modules-sdk/index.ts b/packages/core/types/src/modules-sdk/index.ts index 8f39fb3e33773..e1b3d7e7dc33c 100644 --- a/packages/core/types/src/modules-sdk/index.ts +++ b/packages/core/types/src/modules-sdk/index.ts @@ -198,6 +198,7 @@ export type ModuleJoinerConfig = Omit< relationships?: ModuleJoinerRelationship[] extends?: { serviceName: string + entity?: string fieldAlias?: Record< string, | string diff --git a/packages/core/utils/src/modules-sdk/define-link.ts b/packages/core/utils/src/modules-sdk/define-link.ts index af598e5e64a77..7d215b3234d7d 100644 --- a/packages/core/utils/src/modules-sdk/define-link.ts +++ b/packages/core/utils/src/modules-sdk/define-link.ts @@ -388,6 +388,7 @@ ${serviceBObj.module}: { extends: [ { serviceName: serviceAObj.module, + entity: serviceAObj.entity, fieldAlias: buildFieldAlias({ property: serviceBObj.isList ? pluralize(aliasB) : aliasB, path: aliasB + "_link." + aliasB, @@ -405,6 +406,7 @@ ${serviceBObj.module}: { }, { serviceName: serviceBObj.module, + entity: serviceBObj.entity, fieldAlias: buildFieldAlias({ property: serviceAObj.isList ? pluralize(aliasA) : aliasA, path: aliasA + "_link." + aliasA, @@ -482,6 +484,7 @@ ${serviceBObj.module}: { extends: [ { serviceName: serviceAObj.module, + entity: serviceAObj.entity, fieldAlias: buildFieldAlias(readOnlyLinkOptions?.shortcut), relationship: { serviceName: serviceBObj.module, diff --git a/packages/modules/link-modules/src/definitions/cart-payment-collection.ts b/packages/modules/link-modules/src/definitions/cart-payment-collection.ts index 82ec4ec63aa0d..1ed541f0663d3 100644 --- a/packages/modules/link-modules/src/definitions/cart-payment-collection.ts +++ b/packages/modules/link-modules/src/definitions/cart-payment-collection.ts @@ -40,6 +40,7 @@ export const CartPaymentCollection: ModuleJoinerConfig = { extends: [ { serviceName: Modules.CART, + entity: "Cart", fieldAlias: { payment_collection: "payment_collection_link.payment_collection", }, @@ -52,6 +53,7 @@ export const CartPaymentCollection: ModuleJoinerConfig = { }, { serviceName: Modules.PAYMENT, + entity: "PaymentCollection", fieldAlias: { cart: "cart_link.cart", }, diff --git a/packages/modules/link-modules/src/definitions/cart-promotion.ts b/packages/modules/link-modules/src/definitions/cart-promotion.ts index 9b5f2153ed8fb..0f60c52e7ffa6 100644 --- a/packages/modules/link-modules/src/definitions/cart-promotion.ts +++ b/packages/modules/link-modules/src/definitions/cart-promotion.ts @@ -40,6 +40,7 @@ export const CartPromotion: ModuleJoinerConfig = { extends: [ { serviceName: Modules.CART, + entity: "Cart", fieldAlias: { promotions: { path: "cart_link.promotions", diff --git a/packages/modules/link-modules/src/definitions/fulfillment-provider-location.ts b/packages/modules/link-modules/src/definitions/fulfillment-provider-location.ts index 44855c12a5e30..04f05cacb9024 100644 --- a/packages/modules/link-modules/src/definitions/fulfillment-provider-location.ts +++ b/packages/modules/link-modules/src/definitions/fulfillment-provider-location.ts @@ -52,6 +52,7 @@ export const LocationFulfillmentProvider: ModuleJoinerConfig = { }, { serviceName: Modules.FULFILLMENT, + entity: "FulfillmentProvider", relationship: { serviceName: LINKS.LocationFulfillmentProvider, primaryKey: "fulfillment_provider_id", diff --git a/packages/modules/link-modules/src/definitions/fulfillment-set-location.ts b/packages/modules/link-modules/src/definitions/fulfillment-set-location.ts index 6813ae0dc9ac7..aa954213a2792 100644 --- a/packages/modules/link-modules/src/definitions/fulfillment-set-location.ts +++ b/packages/modules/link-modules/src/definitions/fulfillment-set-location.ts @@ -57,6 +57,7 @@ export const LocationFulfillmentSet: ModuleJoinerConfig = { }, { serviceName: Modules.FULFILLMENT, + entity: "FulfillmentSet", fieldAlias: { location: "locations_link.location", }, diff --git a/packages/modules/link-modules/src/definitions/order-cart.ts b/packages/modules/link-modules/src/definitions/order-cart.ts index ae407510730e2..c2d540552fc14 100644 --- a/packages/modules/link-modules/src/definitions/order-cart.ts +++ b/packages/modules/link-modules/src/definitions/order-cart.ts @@ -40,6 +40,7 @@ export const OrderCart: ModuleJoinerConfig = { extends: [ { serviceName: Modules.ORDER, + entity: "Order", fieldAlias: { cart: "cart_link.cart", }, @@ -52,6 +53,7 @@ export const OrderCart: ModuleJoinerConfig = { }, { serviceName: Modules.CART, + entity: "Cart", fieldAlias: { order: "order_link.order", }, diff --git a/packages/modules/link-modules/src/definitions/order-claim-payment-collection.ts b/packages/modules/link-modules/src/definitions/order-claim-payment-collection.ts index 9ddf9be7cf622..8678b429ec81b 100644 --- a/packages/modules/link-modules/src/definitions/order-claim-payment-collection.ts +++ b/packages/modules/link-modules/src/definitions/order-claim-payment-collection.ts @@ -43,6 +43,7 @@ export const OrderClaimPaymentCollection: ModuleJoinerConfig = { extends: [ { serviceName: Modules.ORDER, + entity: "OrderClaim", fieldAlias: { claim_payment_collections: { path: "claim_payment_collections_link.payment_collection", @@ -58,6 +59,7 @@ export const OrderClaimPaymentCollection: ModuleJoinerConfig = { }, { serviceName: Modules.PAYMENT, + entity: "PaymentCollection", fieldAlias: { claim: "order_claim_link.order", }, diff --git a/packages/modules/link-modules/src/definitions/order-exchange-payment-collection.ts b/packages/modules/link-modules/src/definitions/order-exchange-payment-collection.ts index dcd656bd30eb7..03f944e7944dd 100644 --- a/packages/modules/link-modules/src/definitions/order-exchange-payment-collection.ts +++ b/packages/modules/link-modules/src/definitions/order-exchange-payment-collection.ts @@ -43,6 +43,7 @@ export const OrderExchangePaymentCollection: ModuleJoinerConfig = { extends: [ { serviceName: Modules.ORDER, + entity: "OrderExchange", fieldAlias: { exchange_payment_collections: { path: "exchange_payment_collections_link.payment_collection", @@ -58,6 +59,7 @@ export const OrderExchangePaymentCollection: ModuleJoinerConfig = { }, { serviceName: Modules.PAYMENT, + entity: "PaymentCollection", fieldAlias: { exchange: "order_exchange_link.order", }, diff --git a/packages/modules/link-modules/src/definitions/order-fulfillment.ts b/packages/modules/link-modules/src/definitions/order-fulfillment.ts index 6083022134236..97058bacac2e8 100644 --- a/packages/modules/link-modules/src/definitions/order-fulfillment.ts +++ b/packages/modules/link-modules/src/definitions/order-fulfillment.ts @@ -40,6 +40,7 @@ export const OrderFulfillment: ModuleJoinerConfig = { extends: [ { serviceName: Modules.ORDER, + entity: "Order", fieldAlias: { fulfillments: { path: "fulfillment_link.fulfillments", @@ -56,6 +57,7 @@ export const OrderFulfillment: ModuleJoinerConfig = { }, { serviceName: Modules.FULFILLMENT, + entity: "Fulfillment", fieldAlias: { order: "order_link.order", }, diff --git a/packages/modules/link-modules/src/definitions/order-payment-collection.ts b/packages/modules/link-modules/src/definitions/order-payment-collection.ts index e7683fdef0544..77682525c950e 100644 --- a/packages/modules/link-modules/src/definitions/order-payment-collection.ts +++ b/packages/modules/link-modules/src/definitions/order-payment-collection.ts @@ -41,6 +41,7 @@ export const OrderPaymentCollection: ModuleJoinerConfig = { extends: [ { serviceName: Modules.ORDER, + entity: "Order", fieldAlias: { payment_collections: { path: "payment_collections_link.payment_collection", @@ -56,6 +57,7 @@ export const OrderPaymentCollection: ModuleJoinerConfig = { }, { serviceName: Modules.PAYMENT, + entity: "PaymentCollection", fieldAlias: { order: "order_link.order", }, diff --git a/packages/modules/link-modules/src/definitions/order-promotion.ts b/packages/modules/link-modules/src/definitions/order-promotion.ts index da2e0bfff9c86..465286161c124 100644 --- a/packages/modules/link-modules/src/definitions/order-promotion.ts +++ b/packages/modules/link-modules/src/definitions/order-promotion.ts @@ -40,8 +40,12 @@ export const OrderPromotion: ModuleJoinerConfig = { extends: [ { serviceName: Modules.ORDER, + entity: "Order", fieldAlias: { - promotion: "promotion_link.promotion", + promotion: { + path: "promotion_link.promotion", + isList: true, + }, }, relationship: { serviceName: LINKS.OrderPromotion, @@ -52,6 +56,7 @@ export const OrderPromotion: ModuleJoinerConfig = { }, { serviceName: Modules.PROMOTION, + entity: "Promotion", relationship: { serviceName: LINKS.OrderPromotion, primaryKey: "promotion_id", diff --git a/packages/modules/link-modules/src/definitions/order-return-fulfillment.ts b/packages/modules/link-modules/src/definitions/order-return-fulfillment.ts index 015e32ddb0214..23fa3e3a58cf2 100644 --- a/packages/modules/link-modules/src/definitions/order-return-fulfillment.ts +++ b/packages/modules/link-modules/src/definitions/order-return-fulfillment.ts @@ -18,7 +18,7 @@ export const ReturnFulfillment: ModuleJoinerConfig = { relationships: [ { serviceName: Modules.ORDER, - entity: "Order", + entity: "Return", primaryKey: "id", foreignKey: "return_id", alias: "return", @@ -40,6 +40,7 @@ export const ReturnFulfillment: ModuleJoinerConfig = { extends: [ { serviceName: Modules.ORDER, + entity: "Return", fieldAlias: { return_fulfillments: { path: "return_fulfillment_link.fulfillments", @@ -56,6 +57,7 @@ export const ReturnFulfillment: ModuleJoinerConfig = { }, { serviceName: Modules.FULFILLMENT, + entity: "Fulfillment", relationship: { serviceName: LINKS.OrderFulfillment, primaryKey: "fulfillment_id", diff --git a/packages/modules/link-modules/src/definitions/product-sales-channel.ts b/packages/modules/link-modules/src/definitions/product-sales-channel.ts index 7466444e5aaa7..5d0665c9a99d8 100644 --- a/packages/modules/link-modules/src/definitions/product-sales-channel.ts +++ b/packages/modules/link-modules/src/definitions/product-sales-channel.ts @@ -42,6 +42,7 @@ export const ProductSalesChannel: ModuleJoinerConfig = { extends: [ { serviceName: Modules.PRODUCT, + entity: "Product", fieldAlias: { sales_channels: { path: "sales_channels_link.sales_channel", @@ -58,6 +59,7 @@ export const ProductSalesChannel: ModuleJoinerConfig = { }, { serviceName: Modules.SALES_CHANNEL, + entity: "SalesChannel", relationship: { serviceName: LINKS.ProductSalesChannel, primaryKey: "sales_channel_id", diff --git a/packages/modules/link-modules/src/definitions/product-variant-inventory-item.ts b/packages/modules/link-modules/src/definitions/product-variant-inventory-item.ts index b18beb00638e4..5f5d0bf69611e 100644 --- a/packages/modules/link-modules/src/definitions/product-variant-inventory-item.ts +++ b/packages/modules/link-modules/src/definitions/product-variant-inventory-item.ts @@ -49,6 +49,7 @@ export const ProductVariantInventoryItem: ModuleJoinerConfig = { extends: [ { serviceName: Modules.PRODUCT, + entity: "ProductVariant", fieldAlias: { inventory: "inventory_items.inventory", }, @@ -62,6 +63,7 @@ export const ProductVariantInventoryItem: ModuleJoinerConfig = { }, { serviceName: Modules.INVENTORY, + entity: "InventoryItem", fieldAlias: { variants: { path: "variant_link.variant", diff --git a/packages/modules/link-modules/src/definitions/product-variant-price-set.ts b/packages/modules/link-modules/src/definitions/product-variant-price-set.ts index c2c1d8f9c8f6c..d2c989bf9152c 100644 --- a/packages/modules/link-modules/src/definitions/product-variant-price-set.ts +++ b/packages/modules/link-modules/src/definitions/product-variant-price-set.ts @@ -41,6 +41,7 @@ export const ProductVariantPriceSet: ModuleJoinerConfig = { extends: [ { serviceName: Modules.PRODUCT, + entity: "ProductVariant", fieldAlias: { price_set: "price_set_link.price_set", prices: { @@ -62,6 +63,7 @@ export const ProductVariantPriceSet: ModuleJoinerConfig = { }, { serviceName: Modules.PRICING, + entity: "PriceSet", relationship: { serviceName: LINKS.ProductVariantPriceSet, primaryKey: "price_set_id", diff --git a/packages/modules/link-modules/src/definitions/publishable-api-key-sales-channel.ts b/packages/modules/link-modules/src/definitions/publishable-api-key-sales-channel.ts index bae571e9d1fb5..84ef51bb96857 100644 --- a/packages/modules/link-modules/src/definitions/publishable-api-key-sales-channel.ts +++ b/packages/modules/link-modules/src/definitions/publishable-api-key-sales-channel.ts @@ -42,6 +42,7 @@ export const PublishableApiKeySalesChannel: ModuleJoinerConfig = { extends: [ { serviceName: Modules.API_KEY, + entity: "ApiKey", fieldAlias: { sales_channels: { path: "sales_channels_link.sales_channel", @@ -58,6 +59,7 @@ export const PublishableApiKeySalesChannel: ModuleJoinerConfig = { }, { serviceName: Modules.SALES_CHANNEL, + entity: "SalesChannel", fieldAlias: { publishable_api_keys: { path: "api_keys_link.api_key", diff --git a/packages/modules/link-modules/src/definitions/readonly/cart-customer.ts b/packages/modules/link-modules/src/definitions/readonly/cart-customer.ts index 14f1bbabfe5dd..20122b1687338 100644 --- a/packages/modules/link-modules/src/definitions/readonly/cart-customer.ts +++ b/packages/modules/link-modules/src/definitions/readonly/cart-customer.ts @@ -7,6 +7,7 @@ export const CartCustomer: ModuleJoinerConfig = { extends: [ { serviceName: Modules.CART, + entity: "Cart", relationship: { serviceName: Modules.CUSTOMER, entity: "Customer", @@ -20,6 +21,7 @@ export const CartCustomer: ModuleJoinerConfig = { }, { serviceName: Modules.CUSTOMER, + entity: "Customer", relationship: { serviceName: Modules.CART, entity: "Cart", diff --git a/packages/modules/link-modules/src/definitions/readonly/cart-product.ts b/packages/modules/link-modules/src/definitions/readonly/cart-product.ts index 4ab920e95b1e3..f45f5e0e7515c 100644 --- a/packages/modules/link-modules/src/definitions/readonly/cart-product.ts +++ b/packages/modules/link-modules/src/definitions/readonly/cart-product.ts @@ -7,6 +7,7 @@ export const CartProduct: ModuleJoinerConfig = { extends: [ { serviceName: Modules.CART, + entity: "LineItem", relationship: { serviceName: Modules.PRODUCT, primaryKey: "id", @@ -19,6 +20,7 @@ export const CartProduct: ModuleJoinerConfig = { }, { serviceName: Modules.CART, + entity: "LineItem", relationship: { serviceName: Modules.PRODUCT, entity: "ProductVariant", diff --git a/packages/modules/link-modules/src/definitions/readonly/cart-region.ts b/packages/modules/link-modules/src/definitions/readonly/cart-region.ts index 94e920e28d21b..672a56920dfff 100644 --- a/packages/modules/link-modules/src/definitions/readonly/cart-region.ts +++ b/packages/modules/link-modules/src/definitions/readonly/cart-region.ts @@ -7,6 +7,7 @@ export const CartRegion: ModuleJoinerConfig = { extends: [ { serviceName: Modules.CART, + entity: "Cart", relationship: { serviceName: Modules.REGION, entity: "Region", @@ -20,6 +21,7 @@ export const CartRegion: ModuleJoinerConfig = { }, { serviceName: Modules.REGION, + entity: "Region", relationship: { serviceName: Modules.CART, entity: "Cart", diff --git a/packages/modules/link-modules/src/definitions/readonly/cart-sales-channel.ts b/packages/modules/link-modules/src/definitions/readonly/cart-sales-channel.ts index 3b11286573a02..b8c38a955a4b7 100644 --- a/packages/modules/link-modules/src/definitions/readonly/cart-sales-channel.ts +++ b/packages/modules/link-modules/src/definitions/readonly/cart-sales-channel.ts @@ -7,6 +7,7 @@ export const CartSalesChannel: ModuleJoinerConfig = { extends: [ { serviceName: Modules.CART, + entity: "Cart", relationship: { serviceName: Modules.SALES_CHANNEL, entity: "SalesChannel", @@ -20,6 +21,7 @@ export const CartSalesChannel: ModuleJoinerConfig = { }, { serviceName: Modules.SALES_CHANNEL, + entity: "SalesChannel", relationship: { serviceName: Modules.CART, entity: "Cart", diff --git a/packages/modules/link-modules/src/definitions/readonly/inventory-level-stock-location.ts b/packages/modules/link-modules/src/definitions/readonly/inventory-level-stock-location.ts index 9163edfc1fea3..34258ad917381 100644 --- a/packages/modules/link-modules/src/definitions/readonly/inventory-level-stock-location.ts +++ b/packages/modules/link-modules/src/definitions/readonly/inventory-level-stock-location.ts @@ -7,6 +7,7 @@ export const InventoryLevelStockLocation: ModuleJoinerConfig = { extends: [ { serviceName: Modules.INVENTORY, + entity: "InventoryLevel", relationship: { serviceName: Modules.STOCK_LOCATION, entity: "StockLocation", diff --git a/packages/modules/link-modules/src/definitions/readonly/line-item-adjustment-promotion.ts b/packages/modules/link-modules/src/definitions/readonly/line-item-adjustment-promotion.ts index 7617bfba27801..640c3d854b821 100644 --- a/packages/modules/link-modules/src/definitions/readonly/line-item-adjustment-promotion.ts +++ b/packages/modules/link-modules/src/definitions/readonly/line-item-adjustment-promotion.ts @@ -7,6 +7,7 @@ export const LineItemAdjustmentPromotion: ModuleJoinerConfig = { extends: [ { serviceName: Modules.CART, + entity: "LineItemAdjustment", relationship: { serviceName: Modules.PROMOTION, entity: "Promotion", diff --git a/packages/modules/link-modules/src/definitions/readonly/order-customer.ts b/packages/modules/link-modules/src/definitions/readonly/order-customer.ts index 86f8fd15667fa..964ab69d2049c 100644 --- a/packages/modules/link-modules/src/definitions/readonly/order-customer.ts +++ b/packages/modules/link-modules/src/definitions/readonly/order-customer.ts @@ -7,6 +7,7 @@ export const OrderCustomer: ModuleJoinerConfig = { extends: [ { serviceName: Modules.ORDER, + entity: "Order", relationship: { serviceName: Modules.CUSTOMER, entity: "Customer", @@ -20,6 +21,7 @@ export const OrderCustomer: ModuleJoinerConfig = { }, { serviceName: Modules.CUSTOMER, + entity: "Customer", relationship: { serviceName: Modules.ORDER, entity: "Order", diff --git a/packages/modules/link-modules/src/definitions/readonly/order-product.ts b/packages/modules/link-modules/src/definitions/readonly/order-product.ts index 17a4478f2a26a..c9b1a4a86da2e 100644 --- a/packages/modules/link-modules/src/definitions/readonly/order-product.ts +++ b/packages/modules/link-modules/src/definitions/readonly/order-product.ts @@ -7,6 +7,7 @@ export const OrderProduct: ModuleJoinerConfig = { extends: [ { serviceName: Modules.ORDER, + entity: "OrderLineItem", relationship: { serviceName: Modules.PRODUCT, entity: "Product", @@ -20,6 +21,7 @@ export const OrderProduct: ModuleJoinerConfig = { }, { serviceName: Modules.ORDER, + entity: "OrderLineItem", relationship: { serviceName: Modules.PRODUCT, entity: "ProductVariant", @@ -33,6 +35,7 @@ export const OrderProduct: ModuleJoinerConfig = { }, { serviceName: Modules.PRODUCT, + entity: "ProductVariant", relationship: { serviceName: Modules.ORDER, entity: "OrderLineItem", diff --git a/packages/modules/link-modules/src/definitions/readonly/order-region.ts b/packages/modules/link-modules/src/definitions/readonly/order-region.ts index 3935d3ca17759..aede7ad3aa5cb 100644 --- a/packages/modules/link-modules/src/definitions/readonly/order-region.ts +++ b/packages/modules/link-modules/src/definitions/readonly/order-region.ts @@ -7,6 +7,7 @@ export const OrderRegion: ModuleJoinerConfig = { extends: [ { serviceName: Modules.ORDER, + entity: "Order", relationship: { serviceName: Modules.REGION, entity: "Region", @@ -20,6 +21,7 @@ export const OrderRegion: ModuleJoinerConfig = { }, { serviceName: Modules.REGION, + entity: "Region", relationship: { serviceName: Modules.ORDER, entity: "Order", diff --git a/packages/modules/link-modules/src/definitions/readonly/order-sales-channel.ts b/packages/modules/link-modules/src/definitions/readonly/order-sales-channel.ts index 834f8cec42c34..07384267637ac 100644 --- a/packages/modules/link-modules/src/definitions/readonly/order-sales-channel.ts +++ b/packages/modules/link-modules/src/definitions/readonly/order-sales-channel.ts @@ -7,6 +7,7 @@ export const OrderSalesChannel: ModuleJoinerConfig = { extends: [ { serviceName: Modules.ORDER, + entity: "Order", relationship: { serviceName: Modules.SALES_CHANNEL, entity: "SalesChannel", @@ -20,6 +21,7 @@ export const OrderSalesChannel: ModuleJoinerConfig = { }, { serviceName: Modules.SALES_CHANNEL, + entity: "SalesChannel", relationship: { serviceName: Modules.ORDER, entity: "Order", diff --git a/packages/modules/link-modules/src/definitions/readonly/store-currency.ts b/packages/modules/link-modules/src/definitions/readonly/store-currency.ts index cde506eecfa15..26ca469e00c6c 100644 --- a/packages/modules/link-modules/src/definitions/readonly/store-currency.ts +++ b/packages/modules/link-modules/src/definitions/readonly/store-currency.ts @@ -7,6 +7,7 @@ export const StoreCurrencies: ModuleJoinerConfig = { extends: [ { serviceName: Modules.STORE, + entity: "Store", relationship: { serviceName: Modules.CURRENCY, entity: "Currency", diff --git a/packages/modules/link-modules/src/definitions/region-payment-provider.ts b/packages/modules/link-modules/src/definitions/region-payment-provider.ts index f021f37934042..e01103ca0adc5 100644 --- a/packages/modules/link-modules/src/definitions/region-payment-provider.ts +++ b/packages/modules/link-modules/src/definitions/region-payment-provider.ts @@ -38,6 +38,7 @@ export const RegionPaymentProvider: ModuleJoinerConfig = { extends: [ { serviceName: Modules.REGION, + entity: "Region", fieldAlias: { payment_providers: { path: "payment_provider_link.payment_provider", @@ -54,6 +55,7 @@ export const RegionPaymentProvider: ModuleJoinerConfig = { }, { serviceName: Modules.PAYMENT, + entity: "PaymentProvider", fieldAlias: { regions: { path: "region_link.region", diff --git a/packages/modules/link-modules/src/definitions/sales-channel-location.ts b/packages/modules/link-modules/src/definitions/sales-channel-location.ts index 8c143f49ad30a..45b887bfbfb0d 100644 --- a/packages/modules/link-modules/src/definitions/sales-channel-location.ts +++ b/packages/modules/link-modules/src/definitions/sales-channel-location.ts @@ -40,6 +40,7 @@ export const SalesChannelLocation: ModuleJoinerConfig = { extends: [ { serviceName: Modules.SALES_CHANNEL, + entity: "SalesChannel", fieldAlias: { stock_locations: { path: "locations_link.location", @@ -56,6 +57,7 @@ export const SalesChannelLocation: ModuleJoinerConfig = { }, { serviceName: Modules.STOCK_LOCATION, + entity: "StockLocation", fieldAlias: { sales_channels: { path: "sales_channels_link.sales_channel", diff --git a/packages/modules/link-modules/src/definitions/shipping-option-price-set.ts b/packages/modules/link-modules/src/definitions/shipping-option-price-set.ts index 64c36b349452d..5b3ea5b22b519 100644 --- a/packages/modules/link-modules/src/definitions/shipping-option-price-set.ts +++ b/packages/modules/link-modules/src/definitions/shipping-option-price-set.ts @@ -41,6 +41,7 @@ export const ShippingOptionPriceSet: ModuleJoinerConfig = { extends: [ { serviceName: Modules.FULFILLMENT, + entity: "ShippingOption", fieldAlias: { prices: { path: "price_set_link.price_set.prices", @@ -60,6 +61,7 @@ export const ShippingOptionPriceSet: ModuleJoinerConfig = { }, { serviceName: Modules.PRICING, + entity: "PriceSet", relationship: { serviceName: LINKS.ShippingOptionPriceSet, primaryKey: "price_set_id", diff --git a/packages/modules/link-modules/src/utils/generate-schema.ts b/packages/modules/link-modules/src/utils/generate-schema.ts index aefb9fa49dcb6..449e3a0c4f534 100644 --- a/packages/modules/link-modules/src/utils/generate-schema.ts +++ b/packages/modules/link-modules/src/utils/generate-schema.ts @@ -46,11 +46,7 @@ export function generateGraphQLSchema( ) } - /* const extJoinerConfig = MedusaModule.getJoinerConfig( - extend.relationship.serviceName - )*/ - - const extendedEntityName = + let extendedEntityName = extendedModule[extend.serviceName].__joinerConfig.linkableKeys[ extend.relationship.primaryKey ] @@ -69,11 +65,28 @@ export function generateGraphQLSchema( let type = extend.relationship.isList ? `[${entityName}]` : entityName if (joinerConfig?.isReadOnlyLink) { - // TODO: In readonly, the relation ship of the extend should be applied on all entities in the module that have the relationshiop foregin key attribute - /*type = extend.relationship.isList - ? `[${extendedEntityName}]` - : extendedEntityName*/ - continue + // TODO: In readonly links, the relationship of the extend where entity is undefined has to be applied on all entities in the module that have the relationshiop foreing key attribute (unkown in this context) + if (!extend.entity) { + continue + } + + const rel = extend.relationship + const extendedService = MedusaModule.getModuleInstance(rel.serviceName) + + const hasGraphqlSchema = + !!extendedService[rel.serviceName].__joinerConfig.schema + const relEntity = rel.entity + ? rel.entity + : extendedService[rel.serviceName].__joinerConfig.linkableKeys[ + rel.primaryKey + ] + + if (!relEntity || !hasGraphqlSchema) { + continue + } + + type = rel.isList ? `[${relEntity}]` : relEntity! + extendedEntityName = extend.entity } /** @@ -86,22 +99,6 @@ export function generateGraphQLSchema( ? extend.relationship.isList : config.isList ?? extend.relationship.isList - // const pathSegments = path.split(",").reverse() - - /*const relationshipMarkerIndex = pathSegments.findIndex((segment) => { - return !!joinerConfig.relationships!.find( - (relation) => relation.alias === targetEntityAlias - ) - }) - - if (relationshipMarkerIndex === -1) { - return - }*/ - - /*const relationshipPropertyPath = pathSegments - .slice(0, relationshipMarkerIndex + 1) - .reverse()*/ - const targetEntityAlias = path.split(".").pop() const targetEntityRelation = joinerConfig.relationships?.find(