@simtlix/simfinity-js 1.7.0 → 1.8.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
CHANGED
package/src/index.js
CHANGED
|
@@ -1537,6 +1537,26 @@ we will allow users to use when they are making request. */
|
|
|
1537
1537
|
export const createSchema = (includedQueryTypes,
|
|
1538
1538
|
includedMutationTypes, includedCustomMutations) => {
|
|
1539
1539
|
|
|
1540
|
+
// Generate models for all registered types now that all types are available
|
|
1541
|
+
Object.values(typesDict.types).forEach(typeInfo => {
|
|
1542
|
+
if (typeInfo.gqltype && !typeInfo.model) {
|
|
1543
|
+
if (typeInfo.endpoint) {
|
|
1544
|
+
// Generate model with collection for endpoint types (types registered with connect)
|
|
1545
|
+
typeInfo.model = generateModel(typeInfo.gqltype, typeInfo.onModelCreated);
|
|
1546
|
+
} else if (typeInfo.needsModel) {
|
|
1547
|
+
// Generate model without collection for no-endpoint types that need models (addNoEndpointType)
|
|
1548
|
+
typeInfo.model = generateModelWithoutCollection(typeInfo.gqltype, null);
|
|
1549
|
+
}
|
|
1550
|
+
}
|
|
1551
|
+
});
|
|
1552
|
+
|
|
1553
|
+
// Also update the typesDictForUpdate with the generated models
|
|
1554
|
+
Object.keys(typesDict.types).forEach(typeName => {
|
|
1555
|
+
if (typesDictForUpdate.types[typeName]) {
|
|
1556
|
+
typesDictForUpdate.types[typeName].model = typesDict.types[typeName].model;
|
|
1557
|
+
}
|
|
1558
|
+
});
|
|
1559
|
+
|
|
1540
1560
|
// Auto-generate resolvers for all registered types now that all types are available
|
|
1541
1561
|
Object.values(typesDict.types).forEach(typeInfo => {
|
|
1542
1562
|
if (typeInfo.gqltype) {
|
|
@@ -1628,13 +1648,14 @@ export const connect = (model, gqltype, simpleEntityEndpointName,
|
|
|
1628
1648
|
gqltype,
|
|
1629
1649
|
};
|
|
1630
1650
|
typesDict.types[gqltype.name] = {
|
|
1631
|
-
model: model
|
|
1651
|
+
model: model, // Will be generated later in createSchema if not provided
|
|
1632
1652
|
gqltype,
|
|
1633
1653
|
simpleEntityEndpointName,
|
|
1634
1654
|
listEntitiesEndpointName,
|
|
1635
1655
|
endpoint: true,
|
|
1636
1656
|
controller,
|
|
1637
1657
|
stateMachine,
|
|
1658
|
+
onModelCreated, // Store the callback for later use
|
|
1638
1659
|
};
|
|
1639
1660
|
|
|
1640
1661
|
typesDictForUpdate.types[gqltype.name] = { ...typesDict.types[gqltype.name] };
|
|
@@ -1661,8 +1682,9 @@ export const addNoEndpointType = (gqltype) => {
|
|
|
1661
1682
|
typesDict.types[gqltype.name] = {
|
|
1662
1683
|
gqltype,
|
|
1663
1684
|
endpoint: false,
|
|
1664
|
-
//
|
|
1665
|
-
model:
|
|
1685
|
+
// Model will be generated later in createSchema if needed
|
|
1686
|
+
model: null,
|
|
1687
|
+
needsModel, // Store whether this type needs a model
|
|
1666
1688
|
};
|
|
1667
1689
|
|
|
1668
1690
|
typesDictForUpdate.types[gqltype.name] = { ...typesDict.types[gqltype.name] };
|
|
@@ -28,6 +28,7 @@ describe('preventCreatingCollection option', () => {
|
|
|
28
28
|
});
|
|
29
29
|
|
|
30
30
|
simfinity.connect(null, TestType, 'testTypeDefault', 'testTypesDefault');
|
|
31
|
+
simfinity.createSchema(); // Models are now generated during schema creation
|
|
31
32
|
expect(createCollectionSpy).toHaveBeenCalledTimes(1);
|
|
32
33
|
});
|
|
33
34
|
|
|
@@ -43,6 +44,7 @@ describe('preventCreatingCollection option', () => {
|
|
|
43
44
|
});
|
|
44
45
|
|
|
45
46
|
simfinity.connect(null, TestType, 'testTypePrevent', 'testTypesPrevent');
|
|
47
|
+
simfinity.createSchema(); // Models are now generated during schema creation
|
|
46
48
|
expect(createCollectionSpy).not.toHaveBeenCalled();
|
|
47
49
|
});
|
|
48
50
|
|
|
@@ -59,6 +61,7 @@ describe('preventCreatingCollection option', () => {
|
|
|
59
61
|
});
|
|
60
62
|
|
|
61
63
|
simfinity.connect(null, TestType, 'testTypeAllow', 'testTypesAllow');
|
|
64
|
+
simfinity.createSchema(); // Models are now generated during schema creation
|
|
62
65
|
expect(createCollectionSpy).toHaveBeenCalledTimes(1);
|
|
63
66
|
});
|
|
64
67
|
});
|
|
@@ -117,6 +117,7 @@ describe('Custom Validated Scalar Types', () => {
|
|
|
117
117
|
|
|
118
118
|
beforeAll(() => {
|
|
119
119
|
simfinity.connect(null, UserType, 'user', 'users');
|
|
120
|
+
simfinity.createSchema(); // Models are now generated during schema creation
|
|
120
121
|
UserModel = simfinity.getModel(UserType);
|
|
121
122
|
});
|
|
122
123
|
|
|
@@ -150,6 +151,7 @@ describe('Custom Validated Scalar Types', () => {
|
|
|
150
151
|
}),
|
|
151
152
|
});
|
|
152
153
|
simfinity.connect(null, UserWithUniqueType, 'userWithUnique', 'usersWithUnique');
|
|
154
|
+
simfinity.createSchema(); // Models are now generated during schema creation
|
|
153
155
|
const UserWithUniqueModel = simfinity.getModel(UserWithUniqueType);
|
|
154
156
|
const schema = UserWithUniqueModel.schema.obj;
|
|
155
157
|
|