fix(link-modules): generate graphql type of read only links (#9955)

This commit is contained in:
Carlos R. L. Rodrigues
2024-11-08 07:54:50 -03:00
committed by GitHub
parent 6496789c65
commit 03f4b66b90
35 changed files with 101 additions and 28 deletions

View File

@@ -46,11 +46,7 @@ export function generateGraphQLSchema(
)
}
/* const extJoinerConfig = MedusaModule.getJoinerConfig(
extend.relationship.serviceName
)*/
const extendedEntityName =
let extendedEntityName =
extendedModule[extend.serviceName].__joinerConfig.linkableKeys[
extend.relationship.primaryKey
]
@@ -69,11 +65,28 @@ export function generateGraphQLSchema(
let type = extend.relationship.isList ? `[${entityName}]` : entityName
if (joinerConfig?.isReadOnlyLink) {
// TODO: In readonly, the relation ship of the extend should be applied on all entities in the module that have the relationshiop foregin key attribute
/*type = extend.relationship.isList
? `[${extendedEntityName}]`
: extendedEntityName*/
continue
// TODO: In readonly links, the relationship of the extend where entity is undefined has to be applied on all entities in the module that have the relationshiop foreing key attribute (unkown in this context)
if (!extend.entity) {
continue
}
const rel = extend.relationship
const extendedService = MedusaModule.getModuleInstance(rel.serviceName)
const hasGraphqlSchema =
!!extendedService[rel.serviceName].__joinerConfig.schema
const relEntity = rel.entity
? rel.entity
: extendedService[rel.serviceName].__joinerConfig.linkableKeys[
rel.primaryKey
]
if (!relEntity || !hasGraphqlSchema) {
continue
}
type = rel.isList ? `[${relEntity}]` : relEntity!
extendedEntityName = extend.entity
}
/**
@@ -86,22 +99,6 @@ export function generateGraphQLSchema(
? extend.relationship.isList
: config.isList ?? extend.relationship.isList
// const pathSegments = path.split(",").reverse()
/*const relationshipMarkerIndex = pathSegments.findIndex((segment) => {
return !!joinerConfig.relationships!.find(
(relation) => relation.alias === targetEntityAlias
)
})
if (relationshipMarkerIndex === -1) {
return
}*/
/*const relationshipPropertyPath = pathSegments
.slice(0, relationshipMarkerIndex + 1)
.reverse()*/
const targetEntityAlias = path.split(".").pop()
const targetEntityRelation = joinerConfig.relationships?.find(