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