@medusajs/index 3.0.0-snapshot-20250410105645 → 3.0.0-snapshot-20251104004624
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/loaders/index.d.ts.map +1 -1
- package/dist/loaders/index.js +1 -1
- package/dist/loaders/index.js.map +1 -1
- package/dist/migrations/Migration20231019174230.d.ts +1 -1
- package/dist/migrations/Migration20231019174230.d.ts.map +1 -1
- package/dist/migrations/Migration20231019174230.js +3 -3
- package/dist/migrations/Migration20231019174230.js.map +1 -1
- package/dist/migrations/Migration20241209173313.d.ts +1 -1
- package/dist/migrations/Migration20241209173313.d.ts.map +1 -1
- package/dist/migrations/Migration20241209173313.js +1 -1
- package/dist/migrations/Migration20241209173313.js.map +1 -1
- package/dist/migrations/Migration20250122154720.d.ts +1 -1
- package/dist/migrations/Migration20250122154720.d.ts.map +1 -1
- package/dist/migrations/Migration20250122154720.js +1 -1
- package/dist/migrations/Migration20250122154720.js.map +1 -1
- package/dist/migrations/Migration20250127105159.d.ts +1 -1
- package/dist/migrations/Migration20250127105159.d.ts.map +1 -1
- package/dist/migrations/Migration20250127105159.js +1 -1
- package/dist/migrations/Migration20250127105159.js.map +1 -1
- package/dist/migrations/Migration20250127144442.d.ts +1 -1
- package/dist/migrations/Migration20250127144442.d.ts.map +1 -1
- package/dist/migrations/Migration20250127144442.js +1 -1
- package/dist/migrations/Migration20250127144442.js.map +1 -1
- package/dist/migrations/Migration20250128132404.d.ts +1 -1
- package/dist/migrations/Migration20250128132404.d.ts.map +1 -1
- package/dist/migrations/Migration20250128132404.js +1 -1
- package/dist/migrations/Migration20250128132404.js.map +1 -1
- package/dist/migrations/Migration20250218132404.d.ts +1 -1
- package/dist/migrations/Migration20250218132404.d.ts.map +1 -1
- package/dist/migrations/Migration20250218132404.js +1 -1
- package/dist/migrations/Migration20250218132404.js.map +1 -1
- package/dist/migrations/Migration20250515161913.d.ts +6 -0
- package/dist/migrations/Migration20250515161913.d.ts.map +1 -0
- package/dist/migrations/Migration20250515161913.js +62 -0
- package/dist/migrations/Migration20250515161913.js.map +1 -0
- package/dist/services/data-synchronizer.d.ts.map +1 -1
- package/dist/services/data-synchronizer.js +8 -7
- package/dist/services/data-synchronizer.js.map +1 -1
- package/dist/services/index-data.d.ts +4 -1
- package/dist/services/index-data.d.ts.map +1 -1
- package/dist/services/index-metadata.d.ts +4 -1
- package/dist/services/index-metadata.d.ts.map +1 -1
- package/dist/services/index-module-service.d.ts +37 -2
- package/dist/services/index-module-service.d.ts.map +1 -1
- package/dist/services/index-module-service.js +261 -29
- package/dist/services/index-module-service.js.map +1 -1
- package/dist/services/index-relation.d.ts +4 -1
- package/dist/services/index-relation.d.ts.map +1 -1
- package/dist/services/index-sync.d.ts +4 -1
- package/dist/services/index-sync.d.ts.map +1 -1
- package/dist/services/postgres-provider.d.ts +1 -1
- package/dist/services/postgres-provider.d.ts.map +1 -1
- package/dist/services/postgres-provider.js +14 -61
- package/dist/services/postgres-provider.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/index.d.ts +0 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/base-graphql-schema.d.ts +2 -0
- package/dist/utils/base-graphql-schema.d.ts.map +1 -0
- package/dist/utils/base-graphql-schema.js +10 -0
- package/dist/utils/base-graphql-schema.js.map +1 -0
- package/dist/utils/build-config.d.ts +5 -1
- package/dist/utils/build-config.d.ts.map +1 -1
- package/dist/utils/build-config.js +488 -142
- package/dist/utils/build-config.js.map +1 -1
- package/dist/utils/create-partitions.d.ts +1 -1
- package/dist/utils/create-partitions.d.ts.map +1 -1
- package/dist/utils/create-partitions.js +33 -12
- package/dist/utils/create-partitions.js.map +1 -1
- package/dist/utils/default-schema.js +6 -6
- package/dist/utils/gql-to-types.d.ts +2 -1
- package/dist/utils/gql-to-types.d.ts.map +1 -1
- package/dist/utils/gql-to-types.js +19 -12
- package/dist/utils/gql-to-types.js.map +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/normalze-table-name.d.ts +3 -0
- package/dist/utils/normalze-table-name.d.ts.map +1 -0
- package/dist/utils/normalze-table-name.js +13 -0
- package/dist/utils/normalze-table-name.js.map +1 -0
- package/dist/utils/query-builder.d.ts +11 -12
- package/dist/utils/query-builder.d.ts.map +1 -1
- package/dist/utils/query-builder.js +335 -230
- package/dist/utils/query-builder.js.map +1 -1
- package/dist/utils/sync/configuration.js +17 -15
- package/dist/utils/sync/configuration.js.map +1 -1
- package/dist/utils/sync/orchestrator.d.ts +3 -2
- package/dist/utils/sync/orchestrator.d.ts.map +1 -1
- package/dist/utils/sync/orchestrator.js +19 -7
- package/dist/utils/sync/orchestrator.js.map +1 -1
- package/package.json +14 -30
|
@@ -6,6 +6,7 @@ exports.buildSchemaObjectRepresentation = buildSchemaObjectRepresentation;
|
|
|
6
6
|
const modules_sdk_1 = require("@medusajs/framework/modules-sdk");
|
|
7
7
|
const utils_1 = require("@medusajs/framework/utils");
|
|
8
8
|
const _types_1 = require("../types");
|
|
9
|
+
const base_graphql_schema_1 = require("./base-graphql-schema");
|
|
9
10
|
exports.CustomDirectives = {
|
|
10
11
|
Listeners: {
|
|
11
12
|
configurationPropertyName: "listeners",
|
|
@@ -24,6 +25,52 @@ function makeSchemaExecutable(inputSchema) {
|
|
|
24
25
|
typeDefs: cleanedSchema,
|
|
25
26
|
});
|
|
26
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Retrieve the property name of the source entity that corresponds to the target entity
|
|
30
|
+
* @param sourceEntityName - The name of the source entity
|
|
31
|
+
* @param targetEntityName - The name of the target entity
|
|
32
|
+
* @param entitiesMap - The map of entities configured in the module
|
|
33
|
+
* @param servicesEntityMap - The map of entities configured in the services
|
|
34
|
+
* @param node - The node of the source entity
|
|
35
|
+
* @returns The property name and if it is an array of the source entity property that corresponds to the target entity
|
|
36
|
+
*/
|
|
37
|
+
function retrieveEntityPropByType({ sourceEntityName, targetEntityName, entitiesMap, servicesEntityMap, node, }) {
|
|
38
|
+
if (!node && !entitiesMap && !servicesEntityMap) {
|
|
39
|
+
throw new Error("Index Module error, unable to retrieve the entity property by type. Please provide either the entitiesMap and servicesEntityMap or the node.");
|
|
40
|
+
}
|
|
41
|
+
const retrieveFieldNode = (node) => {
|
|
42
|
+
const astNode = node?.astNode;
|
|
43
|
+
const fields = astNode?.fields ?? [];
|
|
44
|
+
for (const field of fields) {
|
|
45
|
+
let type = field.type;
|
|
46
|
+
let isArray = false;
|
|
47
|
+
while (type.type) {
|
|
48
|
+
if (type.kind === utils_1.GraphQLUtils.Kind.LIST_TYPE) {
|
|
49
|
+
isArray = true;
|
|
50
|
+
}
|
|
51
|
+
type = type.type;
|
|
52
|
+
}
|
|
53
|
+
if (type.name?.value === targetEntityName) {
|
|
54
|
+
return { name: field.name?.value, isArray };
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return;
|
|
58
|
+
};
|
|
59
|
+
let prop;
|
|
60
|
+
if (node) {
|
|
61
|
+
prop = retrieveFieldNode(node);
|
|
62
|
+
}
|
|
63
|
+
if (entitiesMap && !prop) {
|
|
64
|
+
prop = retrieveFieldNode(entitiesMap[sourceEntityName]);
|
|
65
|
+
}
|
|
66
|
+
if (servicesEntityMap && !prop) {
|
|
67
|
+
prop = retrieveFieldNode(servicesEntityMap[sourceEntityName]);
|
|
68
|
+
}
|
|
69
|
+
return (prop && {
|
|
70
|
+
name: prop?.name,
|
|
71
|
+
isArray: prop?.isArray,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
27
74
|
function extractNameFromAlias(alias) {
|
|
28
75
|
const alias_ = Array.isArray(alias) ? alias[0] : alias;
|
|
29
76
|
const names = Array.isArray(alias_?.name) ? alias_?.name : [alias_?.name];
|
|
@@ -79,92 +126,148 @@ function retrieveModuleAndAlias(entityName, moduleJoinerConfigs) {
|
|
|
79
126
|
return { relatedModule, alias };
|
|
80
127
|
}
|
|
81
128
|
// TODO: rename util
|
|
82
|
-
function retrieveLinkModuleAndAlias({ primaryEntity, primaryModuleConfig, foreignEntity, foreignModuleConfig, moduleJoinerConfigs, }) {
|
|
129
|
+
function retrieveLinkModuleAndAlias({ primaryEntity, primaryModuleConfig, foreignEntity, foreignModuleConfig, moduleJoinerConfigs, servicesEntityMap, entitiesMap, }) {
|
|
83
130
|
const linkModulesMetadata = [];
|
|
84
131
|
for (const linkModuleJoinerConfig of moduleJoinerConfigs.filter((config) => config.isLink && !config.isReadOnlyLink)) {
|
|
85
132
|
const linkPrimary = linkModuleJoinerConfig.relationships[0];
|
|
86
133
|
const linkForeign = linkModuleJoinerConfig.relationships[1];
|
|
87
|
-
|
|
88
|
-
linkForeign.serviceName === foreignModuleConfig.serviceName
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
134
|
+
const isDirectMatch = linkPrimary.serviceName === primaryModuleConfig.serviceName &&
|
|
135
|
+
linkForeign.serviceName === foreignModuleConfig.serviceName &&
|
|
136
|
+
linkPrimary.entity === primaryEntity;
|
|
137
|
+
const isInverseMatch = linkPrimary.serviceName === foreignModuleConfig.serviceName &&
|
|
138
|
+
linkForeign.serviceName === primaryModuleConfig.serviceName &&
|
|
139
|
+
linkPrimary.entity === foreignEntity;
|
|
140
|
+
if (!(isDirectMatch || isInverseMatch)) {
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
const primaryEntityLinkableKey = isDirectMatch
|
|
144
|
+
? linkPrimary.foreignKey
|
|
145
|
+
: linkForeign.foreignKey;
|
|
146
|
+
const isTheForeignKeyEntityEqualPrimaryEntity = primaryModuleConfig.linkableKeys?.[primaryEntityLinkableKey] ===
|
|
147
|
+
primaryEntity;
|
|
148
|
+
const foreignEntityLinkableKey = isDirectMatch
|
|
149
|
+
? linkForeign.foreignKey
|
|
150
|
+
: linkPrimary.foreignKey;
|
|
151
|
+
const isTheForeignKeyEntityEqualForeignEntity = foreignModuleConfig.linkableKeys?.[foreignEntityLinkableKey] ===
|
|
152
|
+
foreignEntity;
|
|
153
|
+
const relationshipsTypes = linkModuleJoinerConfig.relationships
|
|
154
|
+
?.map((relationship) => relationship.entity)
|
|
155
|
+
.filter(Boolean) ?? [];
|
|
156
|
+
const filteredEntitiesMap = {
|
|
157
|
+
[linkModuleJoinerConfig.alias?.[0].entity]: entitiesMap[linkModuleJoinerConfig.alias?.[0].entity],
|
|
158
|
+
};
|
|
159
|
+
const filteredServicesEntityMap = {
|
|
160
|
+
[linkModuleJoinerConfig.alias?.[0].entity]: servicesEntityMap[linkModuleJoinerConfig.alias?.[0].entity],
|
|
161
|
+
};
|
|
162
|
+
for (const relationshipType of relationshipsTypes) {
|
|
163
|
+
filteredEntitiesMap[relationshipType] = entitiesMap[relationshipType];
|
|
164
|
+
filteredServicesEntityMap[relationshipType] =
|
|
165
|
+
servicesEntityMap[relationshipType];
|
|
166
|
+
}
|
|
167
|
+
const linkName = linkModuleJoinerConfig.extends?.find((extend) => {
|
|
168
|
+
return ((extend.serviceName === primaryModuleConfig.serviceName ||
|
|
169
|
+
extend.relationship.serviceName ===
|
|
170
|
+
foreignModuleConfig.serviceName) &&
|
|
171
|
+
(extend.relationship.primaryKey === primaryEntityLinkableKey ||
|
|
172
|
+
extend.relationship.primaryKey === foreignEntityLinkableKey));
|
|
173
|
+
})?.relationship.serviceName;
|
|
174
|
+
if (!linkName) {
|
|
175
|
+
throw new Error(`Index Module error, unable to retrieve the link module name for the services ${primaryModuleConfig.serviceName} - ${foreignModuleConfig.serviceName}. Please be sure that the extend relationship service name is set correctly`);
|
|
176
|
+
}
|
|
177
|
+
if (!linkModuleJoinerConfig.alias?.[0]?.entity) {
|
|
178
|
+
throw new Error(`Index Module error, unable to retrieve the link module entity name for the services ${primaryModuleConfig.serviceName} - ${foreignModuleConfig.serviceName}. Please be sure that the link module alias has an entity property in the args.`);
|
|
179
|
+
}
|
|
180
|
+
if (isTheForeignKeyEntityEqualPrimaryEntity &&
|
|
181
|
+
isTheForeignKeyEntityEqualForeignEntity) {
|
|
182
|
+
/**
|
|
183
|
+
* The link will become the parent of the foreign entity, that is why the alias must be the one that correspond to the extended foreign module
|
|
184
|
+
*/
|
|
185
|
+
const inverseSideProp = retrieveEntityPropByType({
|
|
186
|
+
targetEntityName: primaryEntity,
|
|
187
|
+
sourceEntityName: linkModuleJoinerConfig.alias[0].entity,
|
|
188
|
+
servicesEntityMap: filteredServicesEntityMap,
|
|
189
|
+
entitiesMap: filteredEntitiesMap,
|
|
190
|
+
});
|
|
191
|
+
linkModulesMetadata.push({
|
|
192
|
+
entityName: linkModuleJoinerConfig.alias[0].entity,
|
|
193
|
+
alias: extractNameFromAlias(linkModuleJoinerConfig.alias),
|
|
194
|
+
linkModuleConfig: linkModuleJoinerConfig,
|
|
195
|
+
intermediateEntityNames: [],
|
|
196
|
+
isInverse: isInverseMatch,
|
|
197
|
+
isList: inverseSideProp?.isArray,
|
|
198
|
+
inverseSideProp: inverseSideProp?.name,
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
const intermediateEntityName = foreignModuleConfig.linkableKeys[foreignEntityLinkableKey];
|
|
203
|
+
const moduleSchema = isDirectMatch
|
|
204
|
+
? foreignModuleConfig.schema
|
|
205
|
+
: primaryModuleConfig.schema;
|
|
206
|
+
if (!moduleSchema) {
|
|
207
|
+
throw new Error(`Index Module error, unable to retrieve the intermediate entity name for the services ${primaryModuleConfig.serviceName} - ${foreignModuleConfig.serviceName}. Please be sure that the foreign module ${foreignModuleConfig.serviceName} has a schema.`);
|
|
116
208
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
continue;
|
|
209
|
+
const entitiesMap = servicesEntityMap;
|
|
210
|
+
let intermediateEntities = [];
|
|
211
|
+
let foundCount = 0;
|
|
212
|
+
let foundName = null;
|
|
213
|
+
const isForeignEntityChildOfIntermediateEntity = (entityName, visited = new Set()) => {
|
|
214
|
+
if (visited.has(entityName)) {
|
|
215
|
+
return false;
|
|
125
216
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
217
|
+
visited.add(entityName);
|
|
218
|
+
for (const entityType of Object.values(entitiesMap)) {
|
|
219
|
+
const inverseSideProp = retrieveEntityPropByType({
|
|
220
|
+
node: entityType,
|
|
221
|
+
targetEntityName: entityName,
|
|
222
|
+
});
|
|
223
|
+
if (entityType.astNode?.kind === "ObjectTypeDefinition" &&
|
|
224
|
+
inverseSideProp) {
|
|
225
|
+
if (entityType.name === intermediateEntityName) {
|
|
226
|
+
foundName = entityType.name;
|
|
227
|
+
++foundCount;
|
|
228
|
+
return true;
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
const inverseSideProp = isForeignEntityChildOfIntermediateEntity(entityType.name, visited);
|
|
232
|
+
if (inverseSideProp) {
|
|
233
|
+
intermediateEntities.push(entityType.name);
|
|
137
234
|
return true;
|
|
138
235
|
}
|
|
139
|
-
else {
|
|
140
|
-
const test = isForeignEntityChildOfIntermediateEntity(entityType.name);
|
|
141
|
-
if (test) {
|
|
142
|
-
intermediateEntities.push(entityType.name);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
236
|
}
|
|
146
237
|
}
|
|
147
|
-
return false;
|
|
148
|
-
};
|
|
149
|
-
isForeignEntityChildOfIntermediateEntity(foreignEntity);
|
|
150
|
-
if (foundCount !== 1) {
|
|
151
|
-
throw new Error(`Index Module error, unable to retrieve the intermediate entities for the services ${primaryModuleConfig.serviceName} - ${foreignModuleConfig.serviceName} between ${foreignEntity} and ${intermediateEntityName}. Multiple paths or no path found. Please check your schema in ${foreignModuleConfig.serviceName}`);
|
|
152
238
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
entityName: linkModuleJoinerConfig.alias[0].entity,
|
|
159
|
-
alias: extractNameFromAlias(linkModuleJoinerConfig.alias),
|
|
160
|
-
linkModuleConfig: linkModuleJoinerConfig,
|
|
161
|
-
intermediateEntityNames: intermediateEntities,
|
|
162
|
-
});
|
|
239
|
+
return false;
|
|
240
|
+
};
|
|
241
|
+
isForeignEntityChildOfIntermediateEntity(isDirectMatch ? foreignEntity : primaryEntity);
|
|
242
|
+
if (foundCount !== 1) {
|
|
243
|
+
throw new Error(`Index Module error, unable to retrieve the intermediate entities for the services ${primaryModuleConfig.serviceName} - ${foreignModuleConfig.serviceName} between ${isDirectMatch ? foreignEntity : primaryEntity} and ${intermediateEntityName}. Multiple paths or no path found. Please check your schema in ${foreignModuleConfig.serviceName}`);
|
|
163
244
|
}
|
|
245
|
+
intermediateEntities.push(foundName);
|
|
246
|
+
/**
|
|
247
|
+
* The link will become the parent of the foreign entity, that is why the alias must be the one that correspond to the extended foreign module
|
|
248
|
+
*/
|
|
249
|
+
const directInverseSideProp = retrieveEntityPropByType({
|
|
250
|
+
targetEntityName: isDirectMatch
|
|
251
|
+
? primaryEntity
|
|
252
|
+
: linkModuleJoinerConfig.alias[0].entity,
|
|
253
|
+
sourceEntityName: isDirectMatch
|
|
254
|
+
? linkModuleJoinerConfig.alias[0].entity
|
|
255
|
+
: primaryEntity,
|
|
256
|
+
servicesEntityMap: filteredServicesEntityMap,
|
|
257
|
+
entitiesMap: filteredEntitiesMap,
|
|
258
|
+
});
|
|
259
|
+
linkModulesMetadata.push({
|
|
260
|
+
entityName: linkModuleJoinerConfig.alias[0].entity,
|
|
261
|
+
alias: extractNameFromAlias(linkModuleJoinerConfig.alias),
|
|
262
|
+
linkModuleConfig: linkModuleJoinerConfig,
|
|
263
|
+
intermediateEntityNames: intermediateEntities,
|
|
264
|
+
inverseSideProp: directInverseSideProp?.name,
|
|
265
|
+
isList: directInverseSideProp?.isArray,
|
|
266
|
+
isInverse: isInverseMatch,
|
|
267
|
+
});
|
|
164
268
|
}
|
|
165
269
|
}
|
|
166
270
|
if (!linkModulesMetadata.length) {
|
|
167
|
-
// TODO: change to use the logger
|
|
168
271
|
console.warn(`Index Module warning, unable to retrieve the link module that correspond to the entities ${primaryEntity} - ${foreignEntity}.`);
|
|
169
272
|
}
|
|
170
273
|
return linkModulesMetadata;
|
|
@@ -189,7 +292,7 @@ function setCustomDirectives(currentObjectRepresentationRef, directives) {
|
|
|
189
292
|
currentObjectRepresentationRef[customDirectiveConfiguration.configurationPropertyName] = (directive.arguments[0].value?.values ?? []).map((v) => v.value);
|
|
190
293
|
}
|
|
191
294
|
}
|
|
192
|
-
function processEntity(entityName, { entitiesMap, moduleJoinerConfigs, objectRepresentationRef, }) {
|
|
295
|
+
function processEntity(entityName, { entitiesMap, servicesEntityMap, moduleJoinerConfigs, objectRepresentationRef, }) {
|
|
193
296
|
/**
|
|
194
297
|
* Get the reference to the object representation for the current entity.
|
|
195
298
|
*/
|
|
@@ -200,8 +303,11 @@ function processEntity(entityName, { entitiesMap, moduleJoinerConfigs, objectRep
|
|
|
200
303
|
* Retrieve and set the custom directives for the current entity.
|
|
201
304
|
*/
|
|
202
305
|
setCustomDirectives(currentObjectRepresentationRef, entitiesMap[entityName].astNode?.directives ?? []);
|
|
306
|
+
// Merge and deduplicate the fields
|
|
307
|
+
currentObjectRepresentationRef.fields ??= [];
|
|
203
308
|
currentObjectRepresentationRef.fields =
|
|
204
|
-
utils_1.GraphQLUtils.gqlGetFieldsAndRelations(entitiesMap, entityName) ?? [];
|
|
309
|
+
currentObjectRepresentationRef.fields.concat(...(utils_1.GraphQLUtils.gqlGetFieldsAndRelations(entitiesMap, entityName) ?? []));
|
|
310
|
+
currentObjectRepresentationRef.fields = Array.from(new Set(currentObjectRepresentationRef.fields));
|
|
205
311
|
/**
|
|
206
312
|
* Retrieve the module and alias for the current entity.
|
|
207
313
|
*/
|
|
@@ -249,44 +355,84 @@ function processEntity(entityName, { entitiesMap, moduleJoinerConfigs, objectRep
|
|
|
249
355
|
/**
|
|
250
356
|
* Retrieve the parent entity field in the schema
|
|
251
357
|
*/
|
|
252
|
-
const entityFieldInParent =
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
return currentType.name?.value === entityName;
|
|
358
|
+
const entityFieldInParent = retrieveEntityPropByType({
|
|
359
|
+
sourceEntityName: parent,
|
|
360
|
+
targetEntityName: entityName,
|
|
361
|
+
entitiesMap,
|
|
362
|
+
servicesEntityMap,
|
|
258
363
|
});
|
|
259
|
-
const
|
|
260
|
-
const
|
|
364
|
+
const entityTargetPropertyNameInParent = entityFieldInParent.name;
|
|
365
|
+
const entityTargetPropertyIsListInParent = entityFieldInParent.isArray;
|
|
261
366
|
/**
|
|
262
367
|
* Retrieve the parent entity object representation reference.
|
|
263
368
|
*/
|
|
369
|
+
if (!objectRepresentationRef[parent]) {
|
|
370
|
+
processEntity(parent, {
|
|
371
|
+
entitiesMap,
|
|
372
|
+
servicesEntityMap,
|
|
373
|
+
moduleJoinerConfigs,
|
|
374
|
+
objectRepresentationRef,
|
|
375
|
+
});
|
|
376
|
+
}
|
|
264
377
|
const parentObjectRepresentationRef = getObjectRepresentationRef(parent, {
|
|
265
378
|
objectRepresentationRef,
|
|
266
379
|
});
|
|
267
380
|
const parentModuleConfig = parentObjectRepresentationRef.moduleConfig;
|
|
268
381
|
// If the entity is not part of any module, just set the parent and continue
|
|
269
382
|
if (!currentObjectRepresentationRef.moduleConfig) {
|
|
270
|
-
currentObjectRepresentationRef.parents.
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
383
|
+
const parentAlreadyExists = currentObjectRepresentationRef.parents.some((existingParent) => existingParent.ref?.entity === parentObjectRepresentationRef.entity &&
|
|
384
|
+
existingParent.targetProp === entityTargetPropertyNameInParent);
|
|
385
|
+
const parentPropertyNameWithinCurrentEntity = retrieveEntityPropByType({
|
|
386
|
+
sourceEntityName: entityName,
|
|
387
|
+
targetEntityName: parent,
|
|
388
|
+
entitiesMap,
|
|
389
|
+
servicesEntityMap,
|
|
274
390
|
});
|
|
391
|
+
if (!parentAlreadyExists) {
|
|
392
|
+
currentObjectRepresentationRef.parents.push({
|
|
393
|
+
ref: parentObjectRepresentationRef,
|
|
394
|
+
targetProp: entityTargetPropertyNameInParent,
|
|
395
|
+
inverseSideProp: parentPropertyNameWithinCurrentEntity?.name,
|
|
396
|
+
isList: entityTargetPropertyIsListInParent,
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
else {
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
275
402
|
continue;
|
|
276
403
|
}
|
|
277
404
|
/**
|
|
278
|
-
* If the parent entity and the current entity are part of the same
|
|
405
|
+
* If the parent entity and the current entity are part of the same service then configure the parent and
|
|
279
406
|
* add the parent id as a field to the current entity.
|
|
280
407
|
*/
|
|
281
408
|
if (currentObjectRepresentationRef.moduleConfig.serviceName ===
|
|
282
409
|
parentModuleConfig.serviceName ||
|
|
283
|
-
parentModuleConfig.isLink
|
|
284
|
-
currentObjectRepresentationRef.
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
410
|
+
parentModuleConfig.isLink ||
|
|
411
|
+
currentObjectRepresentationRef.moduleConfig.isLink) {
|
|
412
|
+
const parentPropertyNameWithinCurrentEntity = retrieveEntityPropByType({
|
|
413
|
+
sourceEntityName: entityName,
|
|
414
|
+
targetEntityName: parent,
|
|
415
|
+
entitiesMap,
|
|
416
|
+
servicesEntityMap,
|
|
288
417
|
});
|
|
289
|
-
currentObjectRepresentationRef.
|
|
418
|
+
const parentAlreadyExists = currentObjectRepresentationRef.parents.some((existingParent) => existingParent.ref?.entity === parentObjectRepresentationRef.entity &&
|
|
419
|
+
existingParent.targetProp === entityTargetPropertyNameInParent);
|
|
420
|
+
if (!parentAlreadyExists) {
|
|
421
|
+
currentObjectRepresentationRef.parents.push({
|
|
422
|
+
ref: parentObjectRepresentationRef,
|
|
423
|
+
targetProp: entityTargetPropertyNameInParent,
|
|
424
|
+
inverseSideProp: parentPropertyNameWithinCurrentEntity?.name,
|
|
425
|
+
isList: entityTargetPropertyIsListInParent,
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
const propertyToAdd = parentPropertyNameWithinCurrentEntity?.name + ".id";
|
|
429
|
+
if (parentPropertyNameWithinCurrentEntity &&
|
|
430
|
+
!currentObjectRepresentationRef.fields.includes(propertyToAdd)) {
|
|
431
|
+
currentObjectRepresentationRef.fields.push(propertyToAdd);
|
|
432
|
+
}
|
|
433
|
+
if (parentAlreadyExists) {
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
290
436
|
}
|
|
291
437
|
else {
|
|
292
438
|
/**
|
|
@@ -299,20 +445,26 @@ function processEntity(entityName, { entitiesMap, moduleJoinerConfigs, objectRep
|
|
|
299
445
|
foreignEntity: currentObjectRepresentationRef.entity,
|
|
300
446
|
foreignModuleConfig: currentEntityModule,
|
|
301
447
|
moduleJoinerConfigs,
|
|
448
|
+
servicesEntityMap,
|
|
449
|
+
entitiesMap,
|
|
302
450
|
});
|
|
303
451
|
for (const linkModuleMetadata of linkModuleMetadatas) {
|
|
304
452
|
const linkObjectRepresentationRef = getObjectRepresentationRef(linkModuleMetadata.entityName, { objectRepresentationRef });
|
|
305
453
|
objectRepresentationRef._serviceNameModuleConfigMap[linkModuleMetadata.linkModuleConfig.serviceName ||
|
|
306
|
-
linkModuleMetadata.entityName] =
|
|
454
|
+
linkModuleMetadata.entityName] = linkModuleMetadata.linkModuleConfig;
|
|
307
455
|
/**
|
|
308
456
|
* Add the schema parent entity as a parent to the link module and configure it.
|
|
309
457
|
*/
|
|
310
|
-
linkObjectRepresentationRef.parents
|
|
311
|
-
|
|
458
|
+
linkObjectRepresentationRef.parents ??= [];
|
|
459
|
+
if (!linkObjectRepresentationRef.parents.some((parent) => parent.ref.entity === parentObjectRepresentationRef.entity)) {
|
|
460
|
+
linkObjectRepresentationRef.parents.push({
|
|
312
461
|
ref: parentObjectRepresentationRef,
|
|
313
462
|
targetProp: linkModuleMetadata.alias,
|
|
314
|
-
|
|
315
|
-
|
|
463
|
+
inverseSideProp: linkModuleMetadata.inverseSideProp ?? "",
|
|
464
|
+
isList: linkModuleMetadata.isList,
|
|
465
|
+
isInverse: linkModuleMetadata.isInverse,
|
|
466
|
+
});
|
|
467
|
+
}
|
|
316
468
|
linkObjectRepresentationRef.alias = linkModuleMetadata.alias;
|
|
317
469
|
linkObjectRepresentationRef.listeners = [
|
|
318
470
|
`${linkModuleMetadata.entityName}.${utils_1.CommonEvents.ATTACHED}`,
|
|
@@ -345,38 +497,64 @@ function processEntity(entityName, { entitiesMap, moduleJoinerConfigs, objectRep
|
|
|
345
497
|
objectRepresentationRef,
|
|
346
498
|
});
|
|
347
499
|
objectRepresentationRef._serviceNameModuleConfigMap[intermediateEntityModule.serviceName] = intermediateEntityModule;
|
|
348
|
-
|
|
500
|
+
const parentPropertyNameWithinIntermediateEntity = retrieveEntityPropByType({
|
|
501
|
+
sourceEntityName: intermediateEntityName,
|
|
502
|
+
targetEntityName: parentIntermediateEntityRef.entity,
|
|
503
|
+
entitiesMap: entitiesMap,
|
|
504
|
+
servicesEntityMap: servicesEntityMap,
|
|
505
|
+
});
|
|
506
|
+
const intermediateEntityTargetPropertyIsListInParent = retrieveEntityPropByType({
|
|
507
|
+
sourceEntityName: parentIntermediateEntityRef.entity,
|
|
508
|
+
targetEntityName: intermediateEntityName,
|
|
509
|
+
entitiesMap: entitiesMap,
|
|
510
|
+
servicesEntityMap: servicesEntityMap,
|
|
511
|
+
})?.isArray;
|
|
512
|
+
const parentRef = {
|
|
349
513
|
ref: parentIntermediateEntityRef,
|
|
350
514
|
targetProp: intermediateEntityAlias,
|
|
351
|
-
|
|
352
|
-
|
|
515
|
+
inverseSideProp: parentPropertyNameWithinIntermediateEntity?.name,
|
|
516
|
+
isList: intermediateEntityTargetPropertyIsListInParent,
|
|
517
|
+
};
|
|
518
|
+
const parentAlreadyExists = intermediateEntityObjectRepresentationRef.parents.some((existingParent) => existingParent.ref?.entity ===
|
|
519
|
+
parentIntermediateEntityRef.entity &&
|
|
520
|
+
existingParent.targetProp === intermediateEntityAlias);
|
|
521
|
+
if (!parentAlreadyExists) {
|
|
522
|
+
intermediateEntityObjectRepresentationRef.parents.push(parentRef);
|
|
523
|
+
}
|
|
353
524
|
intermediateEntityObjectRepresentationRef.alias =
|
|
354
525
|
intermediateEntityAlias;
|
|
526
|
+
const kebabCasedServiceName = (0, utils_1.lowerCaseFirst)((0, utils_1.kebabCase)(intermediateEntityModule.serviceName));
|
|
355
527
|
intermediateEntityObjectRepresentationRef.listeners = [
|
|
356
528
|
(0, utils_1.buildModuleResourceEventName)({
|
|
357
529
|
action: utils_1.CommonEvents.CREATED,
|
|
358
530
|
objectName: intermediateEntityName,
|
|
359
|
-
prefix:
|
|
531
|
+
prefix: kebabCasedServiceName,
|
|
360
532
|
}),
|
|
361
533
|
(0, utils_1.buildModuleResourceEventName)({
|
|
362
534
|
action: utils_1.CommonEvents.UPDATED,
|
|
363
535
|
objectName: intermediateEntityName,
|
|
364
|
-
prefix:
|
|
536
|
+
prefix: kebabCasedServiceName,
|
|
365
537
|
}),
|
|
366
538
|
(0, utils_1.buildModuleResourceEventName)({
|
|
367
539
|
action: utils_1.CommonEvents.DELETED,
|
|
368
540
|
objectName: intermediateEntityName,
|
|
369
|
-
prefix:
|
|
541
|
+
prefix: kebabCasedServiceName,
|
|
370
542
|
}),
|
|
371
543
|
];
|
|
372
544
|
intermediateEntityObjectRepresentationRef.moduleConfig =
|
|
373
545
|
intermediateEntityModule;
|
|
374
|
-
intermediateEntityObjectRepresentationRef.fields
|
|
546
|
+
if (!intermediateEntityObjectRepresentationRef.fields.includes("id")) {
|
|
547
|
+
intermediateEntityObjectRepresentationRef.fields.push("id");
|
|
548
|
+
}
|
|
375
549
|
/**
|
|
376
550
|
* We push the parent id only between intermediate entities but not between intermediate and link
|
|
377
551
|
*/
|
|
378
552
|
if (!isLastIntermediateEntity) {
|
|
379
|
-
|
|
553
|
+
const propertyToAdd = parentPropertyNameWithinIntermediateEntity?.name + ".id";
|
|
554
|
+
if (parentPropertyNameWithinIntermediateEntity &&
|
|
555
|
+
!intermediateEntityObjectRepresentationRef.fields.includes(propertyToAdd)) {
|
|
556
|
+
intermediateEntityObjectRepresentationRef.fields.push(propertyToAdd);
|
|
557
|
+
}
|
|
380
558
|
}
|
|
381
559
|
}
|
|
382
560
|
/**
|
|
@@ -387,18 +565,53 @@ function processEntity(entityName, { entitiesMap, moduleJoinerConfigs, objectRep
|
|
|
387
565
|
if (linkModuleMetadata.intermediateEntityNames.length) {
|
|
388
566
|
currentParentIntermediateRef =
|
|
389
567
|
objectRepresentationRef[linkModuleMetadata.intermediateEntityNames[0]];
|
|
390
|
-
|
|
568
|
+
const parentPropertyNameWithinCurrentEntity = retrieveEntityPropByType({
|
|
569
|
+
sourceEntityName: currentObjectRepresentationRef.entity,
|
|
570
|
+
targetEntityName: currentParentIntermediateRef.entity,
|
|
571
|
+
entitiesMap: servicesEntityMap,
|
|
572
|
+
});
|
|
573
|
+
const propertyToAdd = parentPropertyNameWithinCurrentEntity?.name + ".id";
|
|
574
|
+
if (parentPropertyNameWithinCurrentEntity &&
|
|
575
|
+
!currentObjectRepresentationRef.fields.includes(propertyToAdd)) {
|
|
576
|
+
currentObjectRepresentationRef.fields.push(propertyToAdd);
|
|
577
|
+
}
|
|
391
578
|
}
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
isList: isEntityListInParent,
|
|
579
|
+
const parentPropertyNameWithinCurrentEntity = retrieveEntityPropByType({
|
|
580
|
+
sourceEntityName: currentObjectRepresentationRef.entity,
|
|
581
|
+
targetEntityName: currentParentIntermediateRef.entity,
|
|
582
|
+
entitiesMap: servicesEntityMap,
|
|
397
583
|
});
|
|
584
|
+
const entityTargetPropertyIsListInParent = retrieveEntityPropByType({
|
|
585
|
+
sourceEntityName: currentParentIntermediateRef.entity,
|
|
586
|
+
targetEntityName: currentObjectRepresentationRef.entity,
|
|
587
|
+
entitiesMap: entitiesMap,
|
|
588
|
+
servicesEntityMap: servicesEntityMap,
|
|
589
|
+
})?.isArray;
|
|
590
|
+
const parentAlreadyExists = currentObjectRepresentationRef.parents.some((existingParent) => existingParent.ref?.entity ===
|
|
591
|
+
currentParentIntermediateRef.entity &&
|
|
592
|
+
existingParent.targetProp === entityTargetPropertyNameInParent);
|
|
593
|
+
if (!parentAlreadyExists) {
|
|
594
|
+
currentObjectRepresentationRef.parents.push({
|
|
595
|
+
ref: currentParentIntermediateRef,
|
|
596
|
+
inSchemaRef: parentObjectRepresentationRef,
|
|
597
|
+
targetProp: entityTargetPropertyNameInParent,
|
|
598
|
+
inverseSideProp: parentPropertyNameWithinCurrentEntity?.name,
|
|
599
|
+
isList: entityTargetPropertyIsListInParent,
|
|
600
|
+
});
|
|
601
|
+
}
|
|
398
602
|
}
|
|
399
603
|
}
|
|
400
604
|
}
|
|
401
605
|
}
|
|
606
|
+
function getServicesEntityMap(moduleJoinerConfigs, addtionalSchema = "") {
|
|
607
|
+
return makeSchemaExecutable(base_graphql_schema_1.baseGraphqlSchema +
|
|
608
|
+
"\n" +
|
|
609
|
+
moduleJoinerConfigs
|
|
610
|
+
.map((joinerConfig) => joinerConfig?.schema ?? "")
|
|
611
|
+
.join("\n") +
|
|
612
|
+
"\n" +
|
|
613
|
+
addtionalSchema).getTypeMap();
|
|
614
|
+
}
|
|
402
615
|
/**
|
|
403
616
|
* Build a special object which will be used to retrieve the correct
|
|
404
617
|
* object representation using path tree
|
|
@@ -413,51 +626,172 @@ function processEntity(entityName, { entitiesMap, moduleJoinerConfigs, objectRep
|
|
|
413
626
|
*/
|
|
414
627
|
function buildAliasMap(objectRepresentation) {
|
|
415
628
|
const aliasMap = {};
|
|
416
|
-
function recursivelyBuildAliasPath(current,
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
629
|
+
function recursivelyBuildAliasPath(current, parentPath = "", aliases = [], visited = new Set(), pathStack = []) {
|
|
630
|
+
const pathIdentifier = `${current.entity}:${parentPath}`;
|
|
631
|
+
if (pathStack.includes(pathIdentifier)) {
|
|
632
|
+
return [];
|
|
633
|
+
}
|
|
634
|
+
pathStack.push(pathIdentifier);
|
|
635
|
+
if (visited.has(current.entity)) {
|
|
636
|
+
pathStack.pop();
|
|
637
|
+
return [];
|
|
638
|
+
}
|
|
639
|
+
visited.add(current.entity);
|
|
640
|
+
for (const parentEntity of current.parents) {
|
|
641
|
+
const newParentPath = parentPath
|
|
642
|
+
? `${parentEntity.targetProp}.${parentPath}`
|
|
643
|
+
: parentEntity.targetProp;
|
|
644
|
+
const newVisited = new Set(visited);
|
|
645
|
+
const newPathStack = [...pathStack];
|
|
646
|
+
const parentAliases = recursivelyBuildAliasPath(parentEntity.ref, newParentPath, [], newVisited, newPathStack).map((aliasObj) => ({
|
|
647
|
+
alias: aliasObj.alias,
|
|
648
|
+
isInverse: parentEntity.isInverse,
|
|
649
|
+
isList: parentEntity.isList,
|
|
650
|
+
}));
|
|
651
|
+
aliases.push(...parentAliases);
|
|
652
|
+
// Handle shortcut paths via inSchemaRef
|
|
653
|
+
if (parentEntity.inSchemaRef) {
|
|
654
|
+
const shortCutOf = parentAliases[0];
|
|
655
|
+
if (!shortCutOf) {
|
|
656
|
+
continue;
|
|
657
|
+
}
|
|
658
|
+
const shortcutAliases_ = recursivelyBuildAliasPath(parentEntity.inSchemaRef, newParentPath, [], new Set(visited), [...pathStack]);
|
|
659
|
+
// Assign all shortcut aliases to the parent aliases
|
|
660
|
+
const shortcutAliases = [];
|
|
661
|
+
shortcutAliases_.forEach((shortcutAlias) => {
|
|
662
|
+
parentAliases.forEach((aliasObj) => {
|
|
663
|
+
let isSamePath = aliasObj.alias.split(".")[0] === shortcutAlias.alias.split(".")[0];
|
|
664
|
+
if (!isSamePath) {
|
|
665
|
+
return;
|
|
666
|
+
}
|
|
667
|
+
shortcutAliases.push({
|
|
668
|
+
alias: shortcutAlias.alias,
|
|
669
|
+
shortCutOf: aliasObj.alias,
|
|
670
|
+
isList: parentEntity.isList ?? true,
|
|
671
|
+
isInverse: shortcutAlias.isInverse,
|
|
672
|
+
});
|
|
439
673
|
});
|
|
440
|
-
|
|
674
|
+
});
|
|
675
|
+
// Only add shortcut aliases if they don’t duplicate existing paths
|
|
676
|
+
for (const shortcut of shortcutAliases) {
|
|
677
|
+
if (!aliases.some((a) => a.alias === shortcut?.alias)) {
|
|
678
|
+
aliases.push(shortcut);
|
|
679
|
+
}
|
|
441
680
|
}
|
|
442
681
|
}
|
|
443
682
|
}
|
|
444
|
-
|
|
683
|
+
// Add the current entity's alias, avoiding duplication
|
|
684
|
+
const pathSegments = parentPath ? parentPath.split(".") : [];
|
|
685
|
+
const baseAlias = pathSegments.length && pathSegments[0] === current.alias
|
|
686
|
+
? parentPath // If parentPath already starts with this alias, use it as-is
|
|
687
|
+
: `${current.alias}${parentPath ? `.${parentPath}` : ""}`;
|
|
688
|
+
if (!aliases.some((a) => a.alias === baseAlias)) {
|
|
689
|
+
aliases.push({
|
|
690
|
+
alias: baseAlias,
|
|
691
|
+
isInverse: false,
|
|
692
|
+
});
|
|
693
|
+
}
|
|
694
|
+
pathStack.pop();
|
|
695
|
+
visited.delete(current.entity);
|
|
445
696
|
return aliases;
|
|
446
697
|
}
|
|
447
698
|
for (const objectRepresentationKey of Object.keys(objectRepresentation).filter((key) => !_types_1.schemaObjectRepresentationPropertiesToOmit.includes(key))) {
|
|
448
699
|
const entityRepresentationRef = objectRepresentation[objectRepresentationKey];
|
|
449
700
|
const aliases = recursivelyBuildAliasPath(entityRepresentationRef);
|
|
450
701
|
for (const alias of aliases) {
|
|
702
|
+
if (aliasMap[alias.alias] && !alias.shortCutOf) {
|
|
703
|
+
continue;
|
|
704
|
+
}
|
|
451
705
|
aliasMap[alias.alias] = {
|
|
452
706
|
ref: entityRepresentationRef,
|
|
707
|
+
shortCutOf: alias.shortCutOf,
|
|
708
|
+
isList: alias.isList,
|
|
709
|
+
isInverse: alias.isInverse,
|
|
453
710
|
};
|
|
454
|
-
if (alias.shortCutOf) {
|
|
455
|
-
aliasMap[alias.alias]["shortCutOf"] = alias.shortCutOf;
|
|
456
|
-
}
|
|
457
711
|
}
|
|
458
712
|
}
|
|
459
713
|
return aliasMap;
|
|
460
714
|
}
|
|
715
|
+
function buildSchemaFromFilterableLinks(moduleJoinerConfigs, servicesEntityMap) {
|
|
716
|
+
const allFilterable = moduleJoinerConfigs.flatMap((config) => {
|
|
717
|
+
const entities = [];
|
|
718
|
+
const schema = config.schema;
|
|
719
|
+
if (config.isLink) {
|
|
720
|
+
if (!config.relationships?.some((r) => r.filterable?.length)) {
|
|
721
|
+
return [];
|
|
722
|
+
}
|
|
723
|
+
for (const relationship of config.relationships) {
|
|
724
|
+
relationship.filterable ??= [];
|
|
725
|
+
if (!relationship.filterable?.length ||
|
|
726
|
+
!relationship.filterable?.includes("id")) {
|
|
727
|
+
relationship.filterable.push("id");
|
|
728
|
+
}
|
|
729
|
+
const fieldAliasMap = {};
|
|
730
|
+
for (const extend of config.extends ?? []) {
|
|
731
|
+
fieldAliasMap[extend.serviceName] = Object.keys(extend.fieldAlias ?? {});
|
|
732
|
+
fieldAliasMap[extend.serviceName].push(extend.relationship.alias);
|
|
733
|
+
}
|
|
734
|
+
const serviceName = relationship.serviceName;
|
|
735
|
+
entities.push({
|
|
736
|
+
serviceName,
|
|
737
|
+
entity: relationship.entity,
|
|
738
|
+
fields: Array.from(new Set(relationship.filterable.concat(fieldAliasMap[serviceName] ?? []))),
|
|
739
|
+
schema,
|
|
740
|
+
});
|
|
741
|
+
}
|
|
742
|
+
return entities;
|
|
743
|
+
}
|
|
744
|
+
let aliases = config.alias ?? [];
|
|
745
|
+
aliases = (Array.isArray(aliases) ? aliases : [aliases]).filter((a) => a.filterable?.length && a.entity);
|
|
746
|
+
for (const alias of aliases) {
|
|
747
|
+
entities.push({
|
|
748
|
+
serviceName: config.serviceName,
|
|
749
|
+
entity: alias.entity,
|
|
750
|
+
fields: Array.from(new Set(alias.filterable)),
|
|
751
|
+
schema,
|
|
752
|
+
});
|
|
753
|
+
}
|
|
754
|
+
return entities;
|
|
755
|
+
});
|
|
756
|
+
const getGqlType = (entity, field) => {
|
|
757
|
+
const fieldRef = servicesEntityMap[entity]?._fields?.[field];
|
|
758
|
+
if (!fieldRef) {
|
|
759
|
+
return;
|
|
760
|
+
}
|
|
761
|
+
const fieldType = fieldRef.type.toString();
|
|
762
|
+
const isArray = fieldType.startsWith("[");
|
|
763
|
+
let currentType = fieldType.replace(/\[|\]|\!/g, "");
|
|
764
|
+
const isEnum = currentType.endsWith("Enum");
|
|
765
|
+
if (isEnum) {
|
|
766
|
+
currentType = "String";
|
|
767
|
+
}
|
|
768
|
+
return isArray ? `[${currentType}]` : currentType;
|
|
769
|
+
};
|
|
770
|
+
const schema = allFilterable
|
|
771
|
+
.map(({ serviceName, entity, fields, schema }) => {
|
|
772
|
+
if (!schema) {
|
|
773
|
+
return;
|
|
774
|
+
}
|
|
775
|
+
const normalizedEntity = (0, utils_1.lowerCaseFirst)((0, utils_1.kebabCase)(entity));
|
|
776
|
+
const events = `@Listeners(values: ["${serviceName}.${normalizedEntity}.created", "${serviceName}.${normalizedEntity}.updated", "${serviceName}.${normalizedEntity}.deleted"])`;
|
|
777
|
+
const fieldDefinitions = fields
|
|
778
|
+
.map((field) => {
|
|
779
|
+
const type = getGqlType(entity, field) ?? "String";
|
|
780
|
+
return ` ${field}: ${type}`;
|
|
781
|
+
})
|
|
782
|
+
.join("\n");
|
|
783
|
+
return `
|
|
784
|
+
type ${entity} ${events} {
|
|
785
|
+
id: ID!
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
extend type ${entity} {
|
|
789
|
+
${fieldDefinitions}
|
|
790
|
+
}`;
|
|
791
|
+
})
|
|
792
|
+
.join("\n\n");
|
|
793
|
+
return schema;
|
|
794
|
+
}
|
|
461
795
|
/**
|
|
462
796
|
* This util build an internal representation object from the provided schema.
|
|
463
797
|
* It will resolve all modules, fields, link module representation to build
|
|
@@ -470,24 +804,36 @@ function buildAliasMap(objectRepresentation) {
|
|
|
470
804
|
*/
|
|
471
805
|
function buildSchemaObjectRepresentation(schema) {
|
|
472
806
|
const moduleJoinerConfigs = modules_sdk_1.MedusaModule.getAllJoinerConfigs();
|
|
473
|
-
const
|
|
807
|
+
const servicesEntityMap = getServicesEntityMap(moduleJoinerConfigs);
|
|
808
|
+
const filterableEntities = buildSchemaFromFilterableLinks(moduleJoinerConfigs, servicesEntityMap);
|
|
809
|
+
const augmentedSchema = exports.CustomDirectives.Listeners.definition +
|
|
810
|
+
"\n" +
|
|
811
|
+
schema +
|
|
812
|
+
"\n" +
|
|
813
|
+
filterableEntities;
|
|
474
814
|
const executableSchema = makeSchemaExecutable(augmentedSchema);
|
|
475
815
|
const entitiesMap = executableSchema.getTypeMap();
|
|
476
816
|
const objectRepresentation = {
|
|
477
817
|
_serviceNameModuleConfigMap: {},
|
|
478
818
|
};
|
|
479
819
|
Object.entries(entitiesMap).forEach(([entityName, entityMapValue]) => {
|
|
480
|
-
if (!entityMapValue.astNode
|
|
820
|
+
if (!entityMapValue.astNode ||
|
|
821
|
+
entityMapValue.astNode.kind === utils_1.GraphQLUtils.Kind.SCALAR_TYPE_DEFINITION) {
|
|
481
822
|
return;
|
|
482
823
|
}
|
|
483
824
|
processEntity(entityName, {
|
|
484
825
|
entitiesMap,
|
|
826
|
+
servicesEntityMap,
|
|
485
827
|
moduleJoinerConfigs,
|
|
486
828
|
objectRepresentationRef: objectRepresentation,
|
|
487
829
|
});
|
|
488
830
|
});
|
|
489
831
|
objectRepresentation._schemaPropertiesMap =
|
|
490
832
|
buildAliasMap(objectRepresentation);
|
|
491
|
-
return
|
|
833
|
+
return {
|
|
834
|
+
objectRepresentation,
|
|
835
|
+
entitiesMap,
|
|
836
|
+
executableSchema,
|
|
837
|
+
};
|
|
492
838
|
}
|
|
493
839
|
//# sourceMappingURL=build-config.js.map
|