Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(link-modules,modules-sdk,pricing): Medusa App Migrations + Core compatible migrations #5317

Merged
merged 18 commits into from
Oct 10, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 31 additions & 12 deletions packages/modules-sdk/src/medusa-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,20 @@ async function loadModules(modulesConfig, injectedDependencies) {
return allModules
}

async function initializeLinks(linkModules, injectedDependencies) {
async function initializeLinks(config, linkModules, injectedDependencies) {
try {
const { initialize: initializeLinks } = await import(LinkModulePackage)
await initializeLinks({}, linkModules, injectedDependencies)
return new RemoteLink()
const { initialize } = await import(LinkModulePackage)
const linkResolution = await initialize(
config,
linkModules,
injectedDependencies
)

return { remoteLink: new RemoteLink(), linkResolution }
} catch (err) {
console.warn("Error initializing link modules.", err)
return undefined

return { remoteLink: undefined, linkResolution: undefined }
riqwan marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down Expand Up @@ -200,6 +206,7 @@ export async function MedusaApp(
process.cwd() + (modulesConfigFileName ?? "/modules-config")
)
).default

const dbData = ModulesSdkUtils.loadDatabaseConfig(
"medusa",
sharedResourcesConfig as ModuleServiceInitializeOptions,
Expand All @@ -219,8 +226,21 @@ export async function MedusaApp(
})
}

// remove the link module from the modules
const linkModule = modules[LinkModulePackage]
delete modules[LinkModulePackage]
let linkModuleOptions = {}

if (isObject(linkModule)) {
linkModuleOptions = linkModule
}

const allModules = await loadModules(modules, injectedDependencies)
const link = await initializeLinks(linkModules, injectedDependencies)
const { remoteLink, linkResolution } = await initializeLinks(
linkModuleOptions,
linkModules,
injectedDependencies
)

const loadedSchema = getLoadedSchema()
const { schema, notFound } = cleanAndMergeSchema(loadedSchema)
Expand All @@ -229,6 +249,7 @@ export async function MedusaApp(
servicesConfig,
customRemoteFetchData: remoteFetchData,
})

const query = async (
query: string | RemoteJoinerQuery | object,
variables?: Record<string, unknown>
Expand All @@ -239,10 +260,8 @@ export async function MedusaApp(
const linkModuleMigration = await getMigrationsFromLinkModule(
LinkModulePackage
)
const runMigrations: RunMigrationFn = async (
options,
injectedDependencies
): Promise<void> => {

const runMigrations: RunMigrationFn = async (): Promise<void> => {
for (const moduleName of Object.keys(allModules)) {
const loadedModule = allModules[moduleName]

Expand All @@ -254,12 +273,12 @@ export async function MedusaApp(
}

linkModuleMigration &&
(await linkModuleMigration(options, injectedDependencies))
(await linkModuleMigration(linkResolution.options, injectedDependencies))
}

return {
modules: allModules,
link,
link: remoteLink,
query,
entitiesMap: schema.getTypeMap(),
notFound,
Expand Down
Loading