@webiny/api-headless-cms 5.18.3 → 5.19.0-beta.3

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.
Files changed (30) hide show
  1. package/content/plugins/crud/contentEntry/afterDelete.d.ts +7 -0
  2. package/content/plugins/crud/contentEntry/afterDelete.js +41 -0
  3. package/content/plugins/crud/contentEntry/markLockedFields.d.ts +7 -3
  4. package/content/plugins/crud/contentEntry/markLockedFields.js +41 -7
  5. package/content/plugins/crud/contentEntry/referenceFieldsMapping.d.ts +12 -0
  6. package/content/plugins/crud/contentEntry/referenceFieldsMapping.js +251 -0
  7. package/content/plugins/crud/contentEntry.crud.d.ts +0 -4
  8. package/content/plugins/crud/contentEntry.crud.js +127 -51
  9. package/content/plugins/crud/contentModel/beforeCreate.js +1 -1
  10. package/content/plugins/crud/index.js +6 -4
  11. package/content/plugins/graphqlFields/ref.js +70 -34
  12. package/content/plugins/modelManager/DefaultCmsModelManager.js +7 -1
  13. package/content/plugins/schema/contentEntries.js +39 -28
  14. package/content/plugins/schema/createManageResolvers.js +6 -2
  15. package/content/plugins/schema/createManageSDL.js +2 -0
  16. package/content/plugins/schema/resolvers/manage/resolveDelete.js +7 -1
  17. package/content/plugins/schema/resolvers/manage/resolveRepublish.d.ts +2 -0
  18. package/content/plugins/schema/resolvers/manage/resolveRepublish.js +21 -0
  19. package/content/plugins/utils/renderSortEnum.js +12 -12
  20. package/content/plugins/validators/patternPlugins/index.js +5 -1
  21. package/content/plugins/validators/patternPlugins/lowerCaseSpace.d.ts +3 -0
  22. package/content/plugins/validators/patternPlugins/lowerCaseSpace.js +17 -0
  23. package/content/plugins/validators/patternPlugins/upperCaseSpace.d.ts +3 -0
  24. package/content/plugins/validators/patternPlugins/upperCaseSpace.js +17 -0
  25. package/index.d.ts +1 -1
  26. package/package.json +24 -23
  27. package/plugins/crud/index.js +20 -2
  28. package/plugins/crud/system.crud.js +25 -7
  29. package/types.d.ts +25 -36
  30. package/types.js +0 -6
@@ -29,6 +29,10 @@ var _utils2 = require("@webiny/utils");
29
29
 
30
30
  var _entryStorage = require("../utils/entryStorage");
31
31
 
32
+ var _afterDelete = require("./contentEntry/afterDelete");
33
+
34
+ var _referenceFieldsMapping = require("./contentEntry/referenceFieldsMapping");
35
+
32
36
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
33
37
 
34
38
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -79,20 +83,23 @@ const createEntryId = version => {
79
83
  };
80
84
 
81
85
  const increaseEntryIdVersion = id => {
82
- if (id.includes("#") === false) {
86
+ const {
87
+ id: entryId,
88
+ version
89
+ } = (0, _utils2.parseIdentifier)(id);
90
+
91
+ if (!version) {
83
92
  throw new _error.default("Cannot increase version on the ID without the version part.", "WRONG_ID", {
84
93
  id
85
94
  });
86
95
  }
87
96
 
88
- const [entryId, version] = id.split("#");
89
- const ver = parseInt(version) + 1;
90
97
  return {
91
98
  entryId,
92
- version: ver,
99
+ version: version + 1,
93
100
  id: (0, _utils2.createIdentifier)({
94
101
  id: entryId,
95
- version: ver
102
+ version: version + 1
96
103
  })
97
104
  };
98
105
  };
@@ -101,8 +108,6 @@ const createContentEntryCrud = params => {
101
108
  const {
102
109
  storageOperations,
103
110
  context,
104
- getTenant,
105
- getLocale,
106
111
  getIdentity
107
112
  } = params;
108
113
  const onBeforeCreate = (0, _pubsub.createTopic)();
@@ -137,6 +142,10 @@ const createContentEntryCrud = params => {
137
142
  context,
138
143
  onBeforeUpdate
139
144
  });
145
+ (0, _afterDelete.assignAfterEntryDelete)({
146
+ context,
147
+ onAfterDelete
148
+ });
140
149
 
141
150
  const checkEntryPermissions = check => {
142
151
  return utils.checkPermissions(context, "cms.contentEntry", check);
@@ -183,8 +192,6 @@ const createContentEntryCrud = params => {
183
192
  });
184
193
  await utils.checkModelAccess(context, model);
185
194
  const entries = await storageOperations.entries.getByIds(model, {
186
- tenant: getTenant().id,
187
- locale: getLocale().code,
188
195
  ids
189
196
  });
190
197
  return entries.filter(entry => utils.validateOwnership(context, permission, entry));
@@ -246,8 +253,6 @@ const createContentEntryCrud = params => {
246
253
  });
247
254
  await utils.checkModelAccess(context, model);
248
255
  const entries = await storageOperations.entries.getPublishedByIds(model, {
249
- tenant: getTenant().id,
250
- locale: getLocale().code,
251
256
  ids
252
257
  });
253
258
  return entries.filter(entry => utils.validateOwnership(context, permission, entry));
@@ -262,16 +267,12 @@ const createContentEntryCrud = params => {
262
267
  });
263
268
  await utils.checkModelAccess(context, model);
264
269
  const entries = await storageOperations.entries.getLatestByIds(model, {
265
- tenant: getTenant().id,
266
- locale: getLocale().code,
267
270
  ids
268
271
  });
269
272
  return entries.filter(entry => utils.validateOwnership(context, permission, entry));
270
273
  },
271
274
  getEntryRevisions: async (model, entryId) => {
272
275
  return storageOperations.entries.getRevisions(model, {
273
- tenant: getTenant().id,
274
- locale: getLocale().code,
275
276
  id: entryId
276
277
  });
277
278
  },
@@ -313,8 +314,8 @@ const createContentEntryCrud = params => {
313
314
  const ownedBy = permission.own ? getIdentity().id : where.ownedBy;
314
315
 
315
316
  const listWhere = _objectSpread(_objectSpread({}, where), {}, {
316
- tenant: where.tenant || getTenant().id,
317
- locale: where.locale || getLocale().code
317
+ tenant: model.tenant,
318
+ locale: model.locale
318
319
  });
319
320
 
320
321
  if (ownedBy !== undefined) {
@@ -374,8 +375,13 @@ const createContentEntryCrud = params => {
374
375
  * Make sure we only work with fields that are defined in the model.
375
376
  */
376
377
 
377
- const input = cleanInputData(model, inputData);
378
- await (0, _entryDataValidation.validateModelEntryData)(context, model, input);
378
+ const initialInput = cleanInputData(model, inputData);
379
+ await (0, _entryDataValidation.validateModelEntryData)(context, model, initialInput);
380
+ const input = await (0, _referenceFieldsMapping.referenceFieldsMapping)({
381
+ context,
382
+ model,
383
+ input: initialInput
384
+ });
379
385
  const identity = context.security.getIdentity();
380
386
  const locale = context.cms.getLocale();
381
387
  const owner = {
@@ -448,15 +454,13 @@ const createContentEntryCrud = params => {
448
454
  * Entries are identified by a common parent ID + Revision number.
449
455
  */
450
456
 
451
- const [uniqueId] = sourceId.split("#");
457
+ const {
458
+ id: uniqueId
459
+ } = (0, _utils2.parseIdentifier)(sourceId);
452
460
  const originalStorageEntry = await storageOperations.entries.getRevisionById(model, {
453
- tenant: getTenant().id,
454
- locale: getLocale().code,
455
461
  id: sourceId
456
462
  });
457
463
  const latestStorageEntry = await storageOperations.entries.getLatestRevisionByEntryId(model, {
458
- tenant: getTenant().id,
459
- locale: getLocale().code,
460
464
  id: uniqueId
461
465
  });
462
466
 
@@ -470,9 +474,14 @@ const createContentEntryCrud = params => {
470
474
 
471
475
  const originalEntry = await (0, _entryStorage.entryFromStorageTransform)(context, model, originalStorageEntry);
472
476
 
473
- const values = _objectSpread(_objectSpread({}, originalEntry.values), input);
477
+ const initialValues = _objectSpread(_objectSpread({}, originalEntry.values), input);
474
478
 
475
- await (0, _entryDataValidation.validateModelEntryData)(context, model, values);
479
+ await (0, _entryDataValidation.validateModelEntryData)(context, model, initialValues);
480
+ const values = await (0, _referenceFieldsMapping.referenceFieldsMapping)({
481
+ context,
482
+ model,
483
+ input: initialValues
484
+ });
476
485
  utils.checkOwnership(context, permission, originalEntry);
477
486
  const latestEntry = await (0, _entryStorage.entryFromStorageTransform)(context, model, latestStorageEntry);
478
487
  const identity = context.security.getIdentity();
@@ -550,8 +559,6 @@ const createContentEntryCrud = params => {
550
559
  */
551
560
 
552
561
  const originalStorageEntry = await storageOperations.entries.getRevisionById(model, {
553
- tenant: getTenant().id,
554
- locale: getLocale().code,
555
562
  id
556
563
  });
557
564
 
@@ -565,13 +572,21 @@ const createContentEntryCrud = params => {
565
572
 
566
573
  const originalEntry = await (0, _entryStorage.entryFromStorageTransform)(context, model, originalStorageEntry);
567
574
  utils.checkOwnership(context, permission, originalEntry);
575
+
576
+ const initialValues = _objectSpread(_objectSpread({}, originalEntry.values), input);
577
+
578
+ const values = await (0, _referenceFieldsMapping.referenceFieldsMapping)({
579
+ context,
580
+ model,
581
+ input: initialValues
582
+ });
568
583
  /**
569
584
  * We always send the full entry to the hooks and storage operations update.
570
585
  */
571
586
 
572
587
  const entry = _objectSpread(_objectSpread({}, originalEntry), {}, {
573
588
  savedOn: new Date().toISOString(),
574
- values: _objectSpread(_objectSpread({}, originalEntry.values), input)
589
+ values
575
590
  });
576
591
 
577
592
  let storageEntry = undefined;
@@ -609,6 +624,83 @@ const createContentEntryCrud = params => {
609
624
  });
610
625
  }
611
626
  },
627
+ republishEntry: async (model, id) => {
628
+ await checkEntryPermissions({
629
+ rwd: "w"
630
+ });
631
+ await utils.checkModelAccess(context, model);
632
+ /**
633
+ * Fetch the entry from the storage.
634
+ */
635
+
636
+ const originalStorageEntry = await storageOperations.entries.getRevisionById(model, {
637
+ id
638
+ });
639
+
640
+ if (!originalStorageEntry) {
641
+ throw new _handlerGraphql.NotFoundError(`Entry "${id}" was not found!`);
642
+ }
643
+
644
+ const originalEntry = await (0, _entryStorage.entryFromStorageTransform)(context, model, originalStorageEntry);
645
+ /**
646
+ * We can only process published entries.
647
+ */
648
+
649
+ if (originalEntry.status !== "published") {
650
+ throw new _error.default("Entry with given ID is not published!", "NOT_PUBLISHED_ERROR", {
651
+ id,
652
+ original: originalEntry
653
+ });
654
+ }
655
+
656
+ const values = await (0, _referenceFieldsMapping.referenceFieldsMapping)({
657
+ context,
658
+ model,
659
+ input: originalEntry.values
660
+ });
661
+
662
+ const entry = _objectSpread(_objectSpread({}, originalEntry), {}, {
663
+ savedOn: new Date().toISOString(),
664
+ webinyVersion: context.WEBINY_VERSION,
665
+ values
666
+ });
667
+
668
+ const storageEntry = await (0, _entryStorage.entryToStorageTransform)(context, model, entry);
669
+ /**
670
+ * First we need to update existing entry.
671
+ */
672
+
673
+ try {
674
+ await storageOperations.entries.update(model, {
675
+ originalEntry,
676
+ originalStorageEntry,
677
+ entry,
678
+ storageEntry,
679
+ input: {}
680
+ });
681
+ } catch (ex) {
682
+ throw new _error.default("Could not update existing entry with new data while re-publishing.", "REPUBLISH_UPDATE_ERROR", {
683
+ entry
684
+ });
685
+ }
686
+ /**
687
+ * Then we move onto publishing it again.
688
+ */
689
+
690
+
691
+ try {
692
+ return await storageOperations.entries.publish(model, {
693
+ originalEntry,
694
+ originalStorageEntry,
695
+ entry,
696
+ storageEntry
697
+ });
698
+ } catch (ex) {
699
+ throw new _error.default("Could not publish existing entry while re-publishing.", "REPUBLISH_PUBLISH_ERROR", {
700
+ entry
701
+ });
702
+ }
703
+ },
612
704
  deleteEntryRevision: async (model, revisionId) => {
613
705
  const permission = await checkEntryPermissions({
614
706
  rwd: "d"
@@ -619,18 +711,12 @@ const createContentEntryCrud = params => {
619
711
  version
620
712
  } = (0, _utils2.parseIdentifier)(revisionId);
621
713
  const storageEntryToDelete = await storageOperations.entries.getRevisionById(model, {
622
- tenant: getTenant().id,
623
- locale: getLocale().code,
624
714
  id: revisionId
625
715
  });
626
716
  const latestStorageEntry = await storageOperations.entries.getLatestRevisionByEntryId(model, {
627
- tenant: getTenant().id,
628
- locale: getLocale().code,
629
717
  id: entryId
630
718
  });
631
719
  const previousStorageEntry = await storageOperations.entries.getPreviousRevision(model, {
632
- tenant: getTenant().id,
633
- locale: getLocale().code,
634
720
  entryId,
635
721
  version
636
722
  });
@@ -698,8 +784,6 @@ const createContentEntryCrud = params => {
698
784
  });
699
785
  await utils.checkModelAccess(context, model);
700
786
  const storageEntry = await storageOperations.entries.getLatestRevisionByEntryId(model, {
701
- tenant: getTenant().id,
702
- locale: getLocale().code,
703
787
  id: entryId
704
788
  });
705
789
 
@@ -720,11 +804,7 @@ const createContentEntryCrud = params => {
720
804
  pw: "p"
721
805
  });
722
806
  await utils.checkModelAccess(context, model);
723
- const tenant = getTenant().id;
724
- const locale = getLocale().code;
725
807
  const originalStorageEntry = await storageOperations.entries.getRevisionById(model, {
726
- tenant,
727
- locale,
728
808
  id
729
809
  });
730
810
 
@@ -778,8 +858,6 @@ const createContentEntryCrud = params => {
778
858
  pw: "c"
779
859
  });
780
860
  const originalStorageEntry = await storageOperations.entries.getRevisionById(model, {
781
- tenant: getTenant().id,
782
- locale: getLocale().code,
783
861
  id
784
862
  });
785
863
 
@@ -836,15 +914,13 @@ const createContentEntryCrud = params => {
836
914
  const permission = await checkEntryPermissions({
837
915
  pw: "r"
838
916
  });
839
- const [entryId] = id.split("#");
917
+ const {
918
+ id: entryId
919
+ } = (0, _utils2.parseIdentifier)(id);
840
920
  const originalStorageEntry = await storageOperations.entries.getRevisionById(model, {
841
- tenant: getTenant().id,
842
- locale: getLocale().code,
843
921
  id
844
922
  });
845
923
  const latestEntryRevision = await storageOperations.entries.getLatestRevisionByEntryId(model, {
846
- tenant: getTenant().id,
847
- locale: getLocale().code,
848
924
  id: entryId
849
925
  });
850
926
 
@@ -900,10 +976,10 @@ const createContentEntryCrud = params => {
900
976
  const permission = await checkEntryPermissions({
901
977
  pw: "u"
902
978
  });
903
- const [entryId] = id.split("#");
979
+ const {
980
+ id: entryId
981
+ } = (0, _utils2.parseIdentifier)(id);
904
982
  const originalStorageEntry = await storageOperations.entries.getPublishedRevisionByEntryId(model, {
905
- tenant: getTenant().id,
906
- locale: getLocale().code,
907
983
  id: entryId
908
984
  });
909
985
 
@@ -21,7 +21,7 @@ const disallowedModelIdList = ["contentModel", "contentModels", "contentModelGro
21
21
  * Add more if required.
22
22
  */
23
23
 
24
- const disallowedModelIdEndingList = ["Response", "List", "Meta", "Input", "Sorter"];
24
+ const disallowedModelIdEndingList = ["Response", "List", "Meta", "Input", "Sorter", "RefType"];
25
25
  /**
26
26
  * Checks for the uniqueness of provided modelId, against the provided list of models.
27
27
  * It also takes plural / singular forms of the provided modelId into account.
@@ -25,6 +25,8 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
25
25
 
26
26
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
27
27
 
28
+ const debug = process.env.DEBUG === "true";
29
+
28
30
  const createContentCruds = params => {
29
31
  const {
30
32
  storageOperations
@@ -35,7 +37,7 @@ const createContentCruds = params => {
35
37
  * It is to make sure that we load setup context before the CRUD init in our internal code.
36
38
  */
37
39
  if (!context.cms) {
38
- console.log(`Missing initial "cms" on the context. Make sure that you set it up before creating Content CRUDs.`);
40
+ debug && console.log(`Missing initial "cms" on the context. Make sure that you set it up before creating Content CRUDs.`);
39
41
  return;
40
42
  }
41
43
 
@@ -55,7 +57,9 @@ const createContentCruds = params => {
55
57
  context.plugins.register(storageOperations.plugins);
56
58
  }
57
59
 
58
- context.cms = _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, context.cms), (0, _system.createSystemCrud)({
60
+ context.cms = _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, context.cms), {}, {
61
+ storageOperations
62
+ }, (0, _system.createSystemCrud)({
59
63
  context,
60
64
  getTenant,
61
65
  getIdentity,
@@ -79,8 +83,6 @@ const createContentCruds = params => {
79
83
  storageOperations
80
84
  })), (0, _contentEntry.createContentEntryCrud)({
81
85
  context,
82
- getLocale,
83
- getTenant,
84
86
  getIdentity,
85
87
  storageOperations
86
88
  }));
@@ -11,6 +11,8 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
11
11
 
12
12
  var _createTypeName = require("../utils/createTypeName");
13
13
 
14
+ var _utils = require("@webiny/utils");
15
+
14
16
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
15
17
 
16
18
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
@@ -23,17 +25,30 @@ const createListFilters = ({
23
25
  field
24
26
  }) => {
25
27
  return `
26
- ${field.fieldId}: String
27
- ${field.fieldId}_in: [String!]
28
- ${field.fieldId}_not: String
29
- ${field.fieldId}_not_in: [String!]
28
+ ${field.fieldId}: RefFieldWhereInput
29
+ `;
30
+ };
31
+
32
+ const createFilteringTypeDef = () => {
33
+ return `
34
+ input RefFieldWhereInput {
35
+ id: String
36
+ id_not: String
37
+ id_in: [String!]
38
+ id_not_in: [String]
39
+ entryId: String
40
+ entryId_not: String
41
+ entryId_in: [String!]
42
+ entryId_not_in: [String!]
43
+ }
30
44
  `;
31
45
  };
32
46
 
33
47
  const appendTypename = (entries, typename) => {
34
48
  return entries.map(item => {
35
- item["__typename"] = typename;
36
- return item;
49
+ return _objectSpread(_objectSpread({}, item), {}, {
50
+ __typename: typename
51
+ });
37
52
  });
38
53
  };
39
54
 
@@ -77,26 +92,27 @@ const plugin = {
77
92
  return [];
78
93
  }
79
94
 
80
- const entriesByModel = value.map((ref, index) => {
81
- return {
82
- entryId: ref.entryId,
83
- modelId: ref.modelId,
84
- index
85
- };
86
- });
87
- const getters = entriesByModel.map(async ({
88
- modelId,
89
- entryId
90
- }) => {
91
- // Get model manager, to get access to CRUD methods
95
+ const entriesByModel = value.reduce((collection, ref) => {
96
+ if (!collection[ref.modelId]) {
97
+ collection[ref.modelId] = [];
98
+ } else if (collection[ref.modelId].includes(ref.entryId) === true) {
99
+ return collection;
100
+ }
101
+
102
+ collection[ref.modelId].push(ref.entryId);
103
+ return collection;
104
+ }, {});
105
+ const getters = Object.keys(entriesByModel).map(async modelId => {
106
+ const idList = entriesByModel[modelId]; // Get model manager, to get access to CRUD methods
107
+
92
108
  const model = await cms.getModelManager(modelId);
93
109
  let entries; // `read` API works with `published` data
94
110
 
95
111
  if (cms.READ) {
96
- entries = await model.getPublishedByIds([entryId]);
112
+ entries = await model.getPublishedByIds(idList);
97
113
  } // `preview` and `manage` with `latest` data
98
114
  else {
99
- entries = await model.getLatestByIds([entryId]);
115
+ entries = await model.getLatestByIds(idList);
100
116
  }
101
117
 
102
118
  return appendTypename(entries, modelIdToTypeName.get(modelId));
@@ -143,17 +159,19 @@ const plugin = {
143
159
  }));
144
160
  }
145
161
 
146
- if (!unionFields.length) {
147
- return null;
148
- }
149
-
162
+ const unionFieldsTypeDef = unionFields.map(({
163
+ field,
164
+ typeName
165
+ }) => `union ${typeName} = ${field.settings.models.map(({
166
+ modelId
167
+ }) => (0, _createTypeName.createReadTypeName)(modelId)).join(" | ")}`).join("\n");
168
+ const filteringTypeDef = `
169
+ ${createFilteringTypeDef()}
170
+
171
+ ${unionFieldsTypeDef}
172
+ `;
150
173
  return {
151
- typeDefs: unionFields.map(({
152
- field,
153
- typeName
154
- }) => `union ${typeName} = ${field.settings.models.map(({
155
- modelId
156
- }) => (0, _createTypeName.createReadTypeName)(modelId)).join(" | ")}`).join("\n"),
174
+ typeDefs: filteringTypeDef,
157
175
  resolvers: {}
158
176
  };
159
177
  },
@@ -162,19 +180,37 @@ const plugin = {
162
180
  },
163
181
  manage: {
164
182
  createSchema() {
183
+ /**
184
+ * entryId in RefFieldInput is deprecated but cannot mark it as GraphQL does not allow marking input fields as deprecated
185
+ */
165
186
  return {
166
187
  typeDefs: `
167
188
  type RefField {
168
189
  modelId: String!
169
190
  entryId: ID!
191
+ id: ID!
170
192
  }
171
193
 
172
194
  input RefFieldInput {
173
195
  modelId: String!
174
- entryId: ID!
196
+ id: ID!
175
197
  }
198
+
199
+ ${createFilteringTypeDef()}
176
200
  `,
177
- resolvers: {}
201
+ resolvers: {
202
+ RefField: {
203
+ entryId: parent => {
204
+ const {
205
+ id
206
+ } = (0, _utils.parseIdentifier)(parent.entryId || parent.id);
207
+ return id;
208
+ },
209
+ id: parent => {
210
+ return parent.id || parent.entryId;
211
+ }
212
+ }
213
+ }
178
214
  };
179
215
  },
180
216
 
@@ -182,7 +218,7 @@ const plugin = {
182
218
  field
183
219
  }) {
184
220
  if (field.multipleValues) {
185
- return `${field.fieldId}: [RefField]`;
221
+ return `${field.fieldId}: [RefField!]`;
186
222
  }
187
223
 
188
224
  return `${field.fieldId}: RefField`;
@@ -192,7 +228,7 @@ const plugin = {
192
228
  field
193
229
  }) {
194
230
  if (field.multipleValues) {
195
- return field.fieldId + ": [RefFieldInput]";
231
+ return field.fieldId + ": [RefFieldInput!]";
196
232
  }
197
233
 
198
234
  return field.fieldId + ": RefFieldInput";
@@ -9,6 +9,8 @@ exports.DefaultCmsModelManager = void 0;
9
9
 
10
10
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
11
 
12
+ var _utils = require("@webiny/utils");
13
+
12
14
  class DefaultCmsModelManager {
13
15
  constructor(context, model) {
14
16
  (0, _defineProperty2.default)(this, "_context", void 0);
@@ -22,7 +24,11 @@ class DefaultCmsModelManager {
22
24
  }
23
25
 
24
26
  async delete(id) {
25
- if (id.includes("#")) {
27
+ const {
28
+ version
29
+ } = (0, _utils.parseIdentifier)(id);
30
+
31
+ if (version) {
26
32
  return this._context.cms.deleteEntryRevision(this._model, id);
27
33
  }
28
34