chore: default isQueryable module (#8192)
* chore: default isQueryable module * fix defaults * fix
This commit is contained in:
committed by
GitHub
parent
4ef268d829
commit
ecc97076b5
@@ -42,6 +42,7 @@ export const ModulesDefinition: {
|
||||
defaultPackage: MODULE_PACKAGE_NAMES[Modules.EVENT_BUS],
|
||||
label: upperCaseFirst(ModuleRegistrationName.EVENT_BUS),
|
||||
isRequired: true,
|
||||
isQueryable: false,
|
||||
dependencies: ["logger"],
|
||||
defaultModuleDeclaration: {
|
||||
scope: MODULE_SCOPE.INTERNAL,
|
||||
@@ -80,6 +81,7 @@ export const ModulesDefinition: {
|
||||
defaultPackage: MODULE_PACKAGE_NAMES[Modules.CACHE],
|
||||
label: upperCaseFirst(ModuleRegistrationName.CACHE),
|
||||
isRequired: true,
|
||||
isQueryable: false,
|
||||
defaultModuleDeclaration: {
|
||||
scope: MODULE_SCOPE.INTERNAL,
|
||||
resources: MODULE_RESOURCE_TYPE.SHARED,
|
||||
|
||||
@@ -387,9 +387,19 @@ class MedusaModule {
|
||||
services[keyName].__definition = resolution.definition
|
||||
|
||||
if (resolution.definition.isQueryable) {
|
||||
const joinerConfig: ModuleJoinerConfig = await services[
|
||||
keyName
|
||||
].__joinerConfig()
|
||||
let joinerConfig!: ModuleJoinerConfig
|
||||
|
||||
try {
|
||||
joinerConfig = await services[keyName].__joinerConfig?.()
|
||||
} catch {
|
||||
// noop
|
||||
}
|
||||
|
||||
if (!joinerConfig) {
|
||||
throw new Error(
|
||||
`Your module is missing a joiner config: ${keyName}. If this module is not queryable, please set { definition: { isQueryable: false } } in your module configuration.`
|
||||
)
|
||||
}
|
||||
|
||||
if (!joinerConfig.primaryKeys) {
|
||||
logger_.warn(
|
||||
@@ -513,9 +523,19 @@ class MedusaModule {
|
||||
services[keyName].__definition = resolution.definition
|
||||
|
||||
if (resolution.definition.isQueryable) {
|
||||
const joinerConfig: ModuleJoinerConfig = await services[
|
||||
keyName
|
||||
].__joinerConfig()
|
||||
let joinerConfig!: ModuleJoinerConfig
|
||||
|
||||
try {
|
||||
joinerConfig = await services[keyName].__joinerConfig?.()
|
||||
} catch {
|
||||
// noop
|
||||
}
|
||||
|
||||
if (!joinerConfig) {
|
||||
throw new Error(
|
||||
`Your module is missing a joiner config: ${keyName}. If this module is not queryable, please set { definition: { isQueryable: false } } in your module configuration.`
|
||||
)
|
||||
}
|
||||
|
||||
services[keyName].__joinerConfig = joinerConfig
|
||||
MedusaModule.setJoinerConfig(keyName, joinerConfig)
|
||||
|
||||
@@ -17,7 +17,9 @@ import {
|
||||
} from "@medusajs/types"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
isBoolean,
|
||||
isObject,
|
||||
isPresent,
|
||||
upperCaseFirst,
|
||||
} from "@medusajs/utils"
|
||||
|
||||
@@ -43,11 +45,15 @@ export function mergeDefaultModules(
|
||||
)) {
|
||||
const def = {} as ModuleDefinition
|
||||
def.key ??= key
|
||||
def.registrationName ??= key
|
||||
def.label ??= upperCaseFirst(key)
|
||||
def.registrationName ??= ModulesDefinition[key]?.registrationName ?? key
|
||||
def.label ??= ModulesDefinition[key]?.label ?? upperCaseFirst(key)
|
||||
def.isQueryable = ModulesDefinition[key]?.isQueryable ?? true
|
||||
|
||||
const orignalDef = value?.definition
|
||||
if (isObject(orignalDef)) {
|
||||
const orignalDef = value?.definition ?? ModulesDefinition[key]
|
||||
if (
|
||||
!isBoolean(value) &&
|
||||
(isObject(orignalDef) || !isPresent(value.definition))
|
||||
) {
|
||||
value.definition = {
|
||||
...def,
|
||||
...orignalDef,
|
||||
|
||||
Reference in New Issue
Block a user