Skip to content

Commit

Permalink
fix(link-modules): generate graphql type of read only links (#9955)
Browse files Browse the repository at this point in the history
  • Loading branch information
carlos-r-l-rodrigues authored Nov 8, 2024
1 parent 6496789 commit 03f4b66
Show file tree
Hide file tree
Showing 35 changed files with 101 additions and 28 deletions.
7 changes: 7 additions & 0 deletions .changeset/lucky-pets-glow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@medusajs/link-modules": patch
"@medusajs/types": patch
"@medusajs/utils": patch
---

Generate graph schema with readonly links
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ medusaIntegrationTestRunner({
extends: [
{
serviceName: "currency",
entity: "Currency",
fieldAlias: {
region: {
path: "region_link.region",
Expand All @@ -85,6 +86,7 @@ medusaIntegrationTestRunner({
},
{
serviceName: "region",
entity: "Region",
fieldAlias: {
currency: {
path: "currency_link.currency",
Expand Down Expand Up @@ -164,6 +166,7 @@ medusaIntegrationTestRunner({
extends: [
{
serviceName: "product",
entity: "ProductVariant",
fieldAlias: {
region: {
path: "region_link.region",
Expand All @@ -182,6 +185,7 @@ medusaIntegrationTestRunner({
},
{
serviceName: "region",
entity: "Region",
fieldAlias: {
product_variant: {
path: "product_variant_link.product_variant",
Expand Down Expand Up @@ -266,6 +270,7 @@ medusaIntegrationTestRunner({
extends: [
{
serviceName: "currency",
entity: "Currency",
fieldAlias: {
region: {
path: "region_link.region",
Expand All @@ -284,6 +289,7 @@ medusaIntegrationTestRunner({
},
{
serviceName: "region",
entity: "Region",
fieldAlias: {
currency: {
path: "currency_link.currency",
Expand Down Expand Up @@ -362,6 +368,7 @@ medusaIntegrationTestRunner({
extends: [
{
serviceName: "currency",
entity: "Currency",
fieldAlias: {
regions: {
path: "region_link.region",
Expand All @@ -380,6 +387,7 @@ medusaIntegrationTestRunner({
},
{
serviceName: "region",
entity: "Region",
fieldAlias: {
currency: {
path: "currency_link.currency",
Expand Down
1 change: 1 addition & 0 deletions packages/core/types/src/joiner/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export interface JoinerServiceConfig {
relationships?: JoinerRelationship[]
extends?: {
serviceName: string
entity?: string
relationship: JoinerRelationship
}[]
/**
Expand Down
1 change: 1 addition & 0 deletions packages/core/types/src/modules-sdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ export type ModuleJoinerConfig = Omit<
relationships?: ModuleJoinerRelationship[]
extends?: {
serviceName: string
entity?: string
fieldAlias?: Record<
string,
| string
Expand Down
3 changes: 3 additions & 0 deletions packages/core/utils/src/modules-sdk/define-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -405,6 +406,7 @@ ${serviceBObj.module}: {
},
{
serviceName: serviceBObj.module,
entity: serviceBObj.entity,
fieldAlias: buildFieldAlias({
property: serviceAObj.isList ? pluralize(aliasA) : aliasA,
path: aliasA + "_link." + aliasA,
Expand Down Expand Up @@ -482,6 +484,7 @@ ${serviceBObj.module}: {
extends: [
{
serviceName: serviceAObj.module,
entity: serviceAObj.entity,
fieldAlias: buildFieldAlias(readOnlyLinkOptions?.shortcut),
relationship: {
serviceName: serviceBObj.module,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const CartPaymentCollection: ModuleJoinerConfig = {
extends: [
{
serviceName: Modules.CART,
entity: "Cart",
fieldAlias: {
payment_collection: "payment_collection_link.payment_collection",
},
Expand All @@ -52,6 +53,7 @@ export const CartPaymentCollection: ModuleJoinerConfig = {
},
{
serviceName: Modules.PAYMENT,
entity: "PaymentCollection",
fieldAlias: {
cart: "cart_link.cart",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const CartPromotion: ModuleJoinerConfig = {
extends: [
{
serviceName: Modules.CART,
entity: "Cart",
fieldAlias: {
promotions: {
path: "cart_link.promotions",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export const LocationFulfillmentProvider: ModuleJoinerConfig = {
},
{
serviceName: Modules.FULFILLMENT,
entity: "FulfillmentProvider",
relationship: {
serviceName: LINKS.LocationFulfillmentProvider,
primaryKey: "fulfillment_provider_id",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export const LocationFulfillmentSet: ModuleJoinerConfig = {
},
{
serviceName: Modules.FULFILLMENT,
entity: "FulfillmentSet",
fieldAlias: {
location: "locations_link.location",
},
Expand Down
2 changes: 2 additions & 0 deletions packages/modules/link-modules/src/definitions/order-cart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const OrderCart: ModuleJoinerConfig = {
extends: [
{
serviceName: Modules.ORDER,
entity: "Order",
fieldAlias: {
cart: "cart_link.cart",
},
Expand All @@ -52,6 +53,7 @@ export const OrderCart: ModuleJoinerConfig = {
},
{
serviceName: Modules.CART,
entity: "Cart",
fieldAlias: {
order: "order_link.order",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -58,6 +59,7 @@ export const OrderClaimPaymentCollection: ModuleJoinerConfig = {
},
{
serviceName: Modules.PAYMENT,
entity: "PaymentCollection",
fieldAlias: {
claim: "order_claim_link.order",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -58,6 +59,7 @@ export const OrderExchangePaymentCollection: ModuleJoinerConfig = {
},
{
serviceName: Modules.PAYMENT,
entity: "PaymentCollection",
fieldAlias: {
exchange: "order_exchange_link.order",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const OrderFulfillment: ModuleJoinerConfig = {
extends: [
{
serviceName: Modules.ORDER,
entity: "Order",
fieldAlias: {
fulfillments: {
path: "fulfillment_link.fulfillments",
Expand All @@ -56,6 +57,7 @@ export const OrderFulfillment: ModuleJoinerConfig = {
},
{
serviceName: Modules.FULFILLMENT,
entity: "Fulfillment",
fieldAlias: {
order: "order_link.order",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const OrderPaymentCollection: ModuleJoinerConfig = {
extends: [
{
serviceName: Modules.ORDER,
entity: "Order",
fieldAlias: {
payment_collections: {
path: "payment_collections_link.payment_collection",
Expand All @@ -56,6 +57,7 @@ export const OrderPaymentCollection: ModuleJoinerConfig = {
},
{
serviceName: Modules.PAYMENT,
entity: "PaymentCollection",
fieldAlias: {
order: "order_link.order",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -52,6 +56,7 @@ export const OrderPromotion: ModuleJoinerConfig = {
},
{
serviceName: Modules.PROMOTION,
entity: "Promotion",
relationship: {
serviceName: LINKS.OrderPromotion,
primaryKey: "promotion_id",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const ReturnFulfillment: ModuleJoinerConfig = {
relationships: [
{
serviceName: Modules.ORDER,
entity: "Order",
entity: "Return",
primaryKey: "id",
foreignKey: "return_id",
alias: "return",
Expand All @@ -40,6 +40,7 @@ export const ReturnFulfillment: ModuleJoinerConfig = {
extends: [
{
serviceName: Modules.ORDER,
entity: "Return",
fieldAlias: {
return_fulfillments: {
path: "return_fulfillment_link.fulfillments",
Expand All @@ -56,6 +57,7 @@ export const ReturnFulfillment: ModuleJoinerConfig = {
},
{
serviceName: Modules.FULFILLMENT,
entity: "Fulfillment",
relationship: {
serviceName: LINKS.OrderFulfillment,
primaryKey: "fulfillment_id",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const ProductSalesChannel: ModuleJoinerConfig = {
extends: [
{
serviceName: Modules.PRODUCT,
entity: "Product",
fieldAlias: {
sales_channels: {
path: "sales_channels_link.sales_channel",
Expand All @@ -58,6 +59,7 @@ export const ProductSalesChannel: ModuleJoinerConfig = {
},
{
serviceName: Modules.SALES_CHANNEL,
entity: "SalesChannel",
relationship: {
serviceName: LINKS.ProductSalesChannel,
primaryKey: "sales_channel_id",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const ProductVariantInventoryItem: ModuleJoinerConfig = {
extends: [
{
serviceName: Modules.PRODUCT,
entity: "ProductVariant",
fieldAlias: {
inventory: "inventory_items.inventory",
},
Expand All @@ -62,6 +63,7 @@ export const ProductVariantInventoryItem: ModuleJoinerConfig = {
},
{
serviceName: Modules.INVENTORY,
entity: "InventoryItem",
fieldAlias: {
variants: {
path: "variant_link.variant",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const ProductVariantPriceSet: ModuleJoinerConfig = {
extends: [
{
serviceName: Modules.PRODUCT,
entity: "ProductVariant",
fieldAlias: {
price_set: "price_set_link.price_set",
prices: {
Expand All @@ -62,6 +63,7 @@ export const ProductVariantPriceSet: ModuleJoinerConfig = {
},
{
serviceName: Modules.PRICING,
entity: "PriceSet",
relationship: {
serviceName: LINKS.ProductVariantPriceSet,
primaryKey: "price_set_id",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const PublishableApiKeySalesChannel: ModuleJoinerConfig = {
extends: [
{
serviceName: Modules.API_KEY,
entity: "ApiKey",
fieldAlias: {
sales_channels: {
path: "sales_channels_link.sales_channel",
Expand All @@ -58,6 +59,7 @@ export const PublishableApiKeySalesChannel: ModuleJoinerConfig = {
},
{
serviceName: Modules.SALES_CHANNEL,
entity: "SalesChannel",
fieldAlias: {
publishable_api_keys: {
path: "api_keys_link.api_key",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const CartCustomer: ModuleJoinerConfig = {
extends: [
{
serviceName: Modules.CART,
entity: "Cart",
relationship: {
serviceName: Modules.CUSTOMER,
entity: "Customer",
Expand All @@ -20,6 +21,7 @@ export const CartCustomer: ModuleJoinerConfig = {
},
{
serviceName: Modules.CUSTOMER,
entity: "Customer",
relationship: {
serviceName: Modules.CART,
entity: "Cart",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const CartProduct: ModuleJoinerConfig = {
extends: [
{
serviceName: Modules.CART,
entity: "LineItem",
relationship: {
serviceName: Modules.PRODUCT,
primaryKey: "id",
Expand All @@ -19,6 +20,7 @@ export const CartProduct: ModuleJoinerConfig = {
},
{
serviceName: Modules.CART,
entity: "LineItem",
relationship: {
serviceName: Modules.PRODUCT,
entity: "ProductVariant",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const CartRegion: ModuleJoinerConfig = {
extends: [
{
serviceName: Modules.CART,
entity: "Cart",
relationship: {
serviceName: Modules.REGION,
entity: "Region",
Expand All @@ -20,6 +21,7 @@ export const CartRegion: ModuleJoinerConfig = {
},
{
serviceName: Modules.REGION,
entity: "Region",
relationship: {
serviceName: Modules.CART,
entity: "Cart",
Expand Down
Loading

0 comments on commit 03f4b66

Please sign in to comment.