@simtlix/simfinity-js 1.3.0 → 1.5.0
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/package.json +6 -6
- package/src/index.js +33 -30
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simtlix/simfinity-js",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"url": "https://github.com/simtlix/simfinity.git"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
|
-
"graphql": "^
|
|
24
|
-
"mongoose": "^8.
|
|
23
|
+
"graphql": "^16.11.0",
|
|
24
|
+
"mongoose": "^8.16.2"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@eslint/compat": "^1.2.0",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"eslint-plugin-import": "^2.32.0",
|
|
33
33
|
"ghooks": "^2.0.4",
|
|
34
34
|
"globals": "^16.3.0",
|
|
35
|
-
"jest": "^
|
|
35
|
+
"jest": "^30.0.4"
|
|
36
36
|
},
|
|
37
37
|
"config": {
|
|
38
38
|
"ghooks": {
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
"owner": "simtlix"
|
|
42
42
|
},
|
|
43
43
|
"optionalDependencies": {
|
|
44
|
-
"graphql": "^
|
|
45
|
-
"mongoose": "^8.
|
|
44
|
+
"graphql": "^16.11.0",
|
|
45
|
+
"mongoose": "^8.16.2"
|
|
46
46
|
},
|
|
47
47
|
"jest": {
|
|
48
48
|
"testEnvironment": "node",
|
package/src/index.js
CHANGED
|
@@ -1563,36 +1563,39 @@ const autoGenerateResolvers = (gqltype) => {
|
|
|
1563
1563
|
if (fieldEntry.extensions && fieldEntry.extensions.relation) {
|
|
1564
1564
|
const { relation } = fieldEntry.extensions;
|
|
1565
1565
|
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1566
|
+
// Only generate resolvers for non-embedded relationships
|
|
1567
|
+
if (!relation.embedded) {
|
|
1568
|
+
if (fieldEntry.type instanceof GraphQLList) {
|
|
1569
|
+
// Collection field - generate resolve for one-to-many relationship
|
|
1570
|
+
const relatedType = fieldEntry.type.ofType;
|
|
1571
|
+
const connectionField = relation.connectionField || fieldName;
|
|
1572
|
+
|
|
1573
|
+
fieldEntry.resolve = (parent) => {
|
|
1574
|
+
// Lazy lookup of the related model
|
|
1575
|
+
const relatedTypeInfo = typesDict.types[relatedType.name];
|
|
1576
|
+
if (!relatedTypeInfo || !relatedTypeInfo.model) {
|
|
1577
|
+
throw new Error(`Related type ${relatedType.name} not found or not connected. Make sure it's connected with simfinity.connect() or simfinity.addNoEndpointType().`);
|
|
1578
|
+
}
|
|
1579
|
+
const query = {};
|
|
1580
|
+
query[connectionField] = parent.id || parent._id;
|
|
1581
|
+
return relatedTypeInfo.model.find(query);
|
|
1582
|
+
};
|
|
1583
|
+
} else if (fieldEntry.type instanceof GraphQLObjectType
|
|
1584
|
+
|| (fieldEntry.type instanceof GraphQLNonNull && fieldEntry.type.ofType instanceof GraphQLObjectType)) {
|
|
1585
|
+
// Single object field - generate resolve for one-to-one relationship
|
|
1586
|
+
const relatedType = fieldEntry.type instanceof GraphQLNonNull ? fieldEntry.type.ofType : fieldEntry.type;
|
|
1587
|
+
const connectionField = relation.connectionField || fieldName;
|
|
1588
|
+
|
|
1589
|
+
fieldEntry.resolve = (parent) => {
|
|
1590
|
+
// Lazy lookup of the related model
|
|
1591
|
+
const relatedTypeInfo = typesDict.types[relatedType.name];
|
|
1592
|
+
if (!relatedTypeInfo || !relatedTypeInfo.model) {
|
|
1593
|
+
throw new Error(`Related type ${relatedType.name} not found or not connected. Make sure it's connected with simfinity.connect() or simfinity.addNoEndpointType().`);
|
|
1594
|
+
}
|
|
1595
|
+
const relatedId = parent[connectionField] || parent[fieldName];
|
|
1596
|
+
return relatedId ? relatedTypeInfo.model.findById(relatedId) : null;
|
|
1597
|
+
};
|
|
1598
|
+
}
|
|
1596
1599
|
}
|
|
1597
1600
|
}
|
|
1598
1601
|
}
|