fix(workflows-sdk): use loaded modules when container is empty (#7422)

This commit is contained in:
Carlos R. L. Rodrigues
2024-05-23 08:26:16 -03:00
committed by GitHub
parent 05077bab32
commit f3d19f5394
13 changed files with 15 additions and 154 deletions
@@ -244,18 +244,6 @@ export class RemoteJoiner {
{ fieldAlias, relationships },
] of expandedRelationships) {
if (!this.serviceConfigCache.has(serviceName)) {
// If true, the relationship is an internal service from the medusa core
// If modules are being used ouside of the core, we should not be throwing
// errors when the core services are not found in cache.
// TODO: Remove when there are no more "internal" services
const isInternalServicePresent = relationships.some(
(rel) => rel.isInternalService === true
)
if (isInternalServicePresent) {
continue
}
throw new Error(`Service "${serviceName}" was not found`)
}
-5
View File
@@ -3,11 +3,6 @@ export type JoinerRelationship = {
foreignKey: string
primaryKey: string
serviceName: string
/**
* If true, the relationship is an internal service from the medusa core
* TODO: Remove when there are no more "internal" services
*/
isInternalService?: boolean
/**
* In an inverted relationship the foreign key is on the other service and the primary key is on the current service
*/
@@ -220,10 +220,6 @@ export type ModuleJoinerConfig = Omit<
}
export declare type ModuleJoinerRelationship = JoinerRelationship & {
/**
* If true, the relationship is an internal service from the medusa core TODO: Remove when there are no more "internal" services
*/
isInternalService?: boolean
/**
* If true, the link joiner will cascade deleting the relationship
*/
@@ -1,12 +1,11 @@
import { MedusaModule } from "@medusajs/modules-sdk"
import {
LocalWorkflow,
TransactionHandlerType,
TransactionState,
} from "@medusajs/orchestration"
import { LoadedModule, MedusaContainer } from "@medusajs/types"
import { MedusaModule } from "@medusajs/modules-sdk"
import { MedusaContextType } from "@medusajs/utils"
import { MedusaContextType, isPresent } from "@medusajs/utils"
import { EOL } from "os"
import { ulid } from "ulid"
import { MedusaWorkflow } from "../medusa-workflow"
@@ -62,13 +61,16 @@ function createContextualWorkflowRunner<
},
...args
) => {
if (!executionContainer && !flow.container) {
executionContainer = MedusaModule.getLoadedModules().map(
(mod) => Object.values(mod)[0]
)
if (!executionContainer) {
const container_ = flow.container as MedusaContainer
if (!container_ || !isPresent(container_?.registrations)) {
executionContainer = MedusaModule.getLoadedModules().map(
(mod) => Object.values(mod)[0]
)
}
}
if (!flow.container) {
if (executionContainer) {
flow.container = executionContainer
}