@lenne.tech/ng-base 13.10.3 → 13.11.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.
@@ -435,6 +435,49 @@ class GraphQLMeta {
435
435
  throw Error('Missing schema');
436
436
  }
437
437
  }
438
+ /**
439
+ * We're going to get the query and mutation types from the schema, then we're going to loop through the fields of each
440
+ * type and check if the field name starts with `find`, `create`, `update`, or `delete`. If it does, we're going to add
441
+ * the model name to the `possibleTypes` array
442
+ *
443
+ * @returns An array of objects with the name of the model, and the CRUD operations that are available for that model.
444
+ */
445
+ getTypes() {
446
+ const possibleTypes = [];
447
+ const mutationType = this.schema.getMutationType();
448
+ const queryType = this.schema.getQueryType();
449
+ for (const [key, value] of Object.entries(queryType.getFields())) {
450
+ if (key.startsWith('find')) {
451
+ possibleTypes.push({
452
+ name: key.split('find').pop().slice(0, -1),
453
+ create: false,
454
+ update: false,
455
+ delete: false,
456
+ });
457
+ }
458
+ }
459
+ for (const [key, value] of Object.entries(mutationType.getFields())) {
460
+ if (key.startsWith('create')) {
461
+ const model = key.split('create').pop();
462
+ if (possibleTypes.find((e) => e.name === model)) {
463
+ possibleTypes.find((item) => item.name === model).create = true;
464
+ }
465
+ }
466
+ if (key.startsWith('update')) {
467
+ const model = key.split('update').pop();
468
+ if (possibleTypes.find((e) => e.name === model)) {
469
+ possibleTypes.find((item) => item.name === model).update = true;
470
+ }
471
+ }
472
+ if (key.startsWith('delete')) {
473
+ const model = key.split('delete').pop();
474
+ if (possibleTypes.find((e) => e.name === model)) {
475
+ possibleTypes.find((item) => item.name === model).delete = true;
476
+ }
477
+ }
478
+ }
479
+ return possibleTypes;
480
+ }
438
481
  /**
439
482
  * Get arguments of GraphQL function
440
483
  */