chore(medusa,orchestration,link-modules,modules-sdk): internal services as modules (#4925)
This commit is contained in:
committed by
GitHub
parent
85fa90d9c6
commit
a4906d0ac0
@@ -36,20 +36,30 @@ export type SharedResources = {
|
||||
}
|
||||
}
|
||||
|
||||
export async function MedusaApp({
|
||||
sharedResourcesConfig,
|
||||
modulesConfigPath,
|
||||
modulesConfig,
|
||||
linkModules,
|
||||
remoteFetchData,
|
||||
}: {
|
||||
sharedResourcesConfig?: SharedResources
|
||||
loadedModules?: LoadedModule[]
|
||||
modulesConfigPath?: string
|
||||
modulesConfig?: MedusaModuleConfig
|
||||
linkModules?: ModuleJoinerConfig | ModuleJoinerConfig[]
|
||||
remoteFetchData?: RemoteFetchDataCallback
|
||||
} = {}): Promise<{
|
||||
export async function MedusaApp(
|
||||
{
|
||||
sharedResourcesConfig,
|
||||
servicesConfig,
|
||||
modulesConfigPath,
|
||||
modulesConfigFileName,
|
||||
modulesConfig,
|
||||
linkModules,
|
||||
remoteFetchData,
|
||||
injectedDependencies,
|
||||
}: {
|
||||
sharedResourcesConfig?: SharedResources
|
||||
loadedModules?: LoadedModule[]
|
||||
servicesConfig?: ModuleJoinerConfig[]
|
||||
modulesConfigPath?: string
|
||||
modulesConfigFileName?: string
|
||||
modulesConfig?: MedusaModuleConfig
|
||||
linkModules?: ModuleJoinerConfig | ModuleJoinerConfig[]
|
||||
remoteFetchData?: RemoteFetchDataCallback
|
||||
injectedDependencies?: any
|
||||
} = {
|
||||
injectedDependencies: {},
|
||||
}
|
||||
): Promise<{
|
||||
modules: Record<string, LoadedModule | LoadedModule[]>
|
||||
link: RemoteLink | undefined
|
||||
query: (
|
||||
@@ -59,10 +69,12 @@ export async function MedusaApp({
|
||||
}> {
|
||||
const modules: MedusaModuleConfig =
|
||||
modulesConfig ??
|
||||
(await import(process.cwd() + (modulesConfigPath ?? "/modules-config")))
|
||||
.default
|
||||
|
||||
const injectedDependencies: any = {}
|
||||
(
|
||||
await import(
|
||||
modulesConfigPath ??
|
||||
process.cwd() + (modulesConfigFileName ?? "/modules-config")
|
||||
)
|
||||
).default
|
||||
|
||||
const dbData = ModulesSdkUtils.loadDatabaseConfig(
|
||||
"medusa",
|
||||
@@ -167,7 +179,10 @@ export async function MedusaApp({
|
||||
console.warn("Error initializing link modules.", err)
|
||||
}
|
||||
|
||||
const remoteQuery = new RemoteQuery(undefined, remoteFetchData)
|
||||
const remoteQuery = new RemoteQuery({
|
||||
servicesConfig,
|
||||
customRemoteFetchData: remoteFetchData,
|
||||
})
|
||||
query = async (
|
||||
query: string | RemoteJoinerQuery,
|
||||
variables?: Record<string, unknown>
|
||||
|
||||
@@ -17,8 +17,17 @@ export class RemoteQuery {
|
||||
private customRemoteFetchData?: RemoteFetchDataCallback
|
||||
|
||||
constructor(
|
||||
modulesLoaded?: LoadedModule[],
|
||||
customRemoteFetchData?: RemoteFetchDataCallback
|
||||
{
|
||||
modulesLoaded,
|
||||
customRemoteFetchData,
|
||||
servicesConfig,
|
||||
}: {
|
||||
modulesLoaded?: LoadedModule[]
|
||||
customRemoteFetchData?: RemoteFetchDataCallback
|
||||
servicesConfig?: ModuleJoinerConfig[]
|
||||
} = {
|
||||
servicesConfig: [],
|
||||
}
|
||||
) {
|
||||
if (!modulesLoaded?.length) {
|
||||
modulesLoaded = MedusaModule.getLoadedModules().map(
|
||||
@@ -26,7 +35,6 @@ export class RemoteQuery {
|
||||
)
|
||||
}
|
||||
|
||||
const servicesConfig: ModuleJoinerConfig[] = []
|
||||
for (const mod of modulesLoaded) {
|
||||
if (!mod.__definition.isQueryable) {
|
||||
continue
|
||||
@@ -41,7 +49,7 @@ export class RemoteQuery {
|
||||
}
|
||||
|
||||
this.modulesMap.set(serviceName, mod)
|
||||
servicesConfig.push(mod.__joinerConfig)
|
||||
servicesConfig!.push(mod.__joinerConfig)
|
||||
}
|
||||
|
||||
this.customRemoteFetchData = customRemoteFetchData
|
||||
@@ -65,7 +73,7 @@ export class RemoteQuery {
|
||||
this.remoteJoiner.setFetchDataCallback(remoteFetchData)
|
||||
}
|
||||
|
||||
private static getAllFieldsAndRelations(
|
||||
public static getAllFieldsAndRelations(
|
||||
data: any,
|
||||
prefix = "",
|
||||
args: Record<string, unknown[]> = {}
|
||||
|
||||
Reference in New Issue
Block a user