@webiny/api-headless-cms 0.0.0-mt-1

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 (231) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +73 -0
  3. package/content/contextSetup.d.ts +4 -0
  4. package/content/contextSetup.js +65 -0
  5. package/content/graphQLHandlerFactory.d.ts +5 -0
  6. package/content/graphQLHandlerFactory.js +173 -0
  7. package/content/plugins/CmsGroupPlugin.d.ts +11 -0
  8. package/content/plugins/CmsGroupPlugin.js +24 -0
  9. package/content/plugins/CmsModelPlugin.d.ts +11 -0
  10. package/content/plugins/CmsModelPlugin.js +24 -0
  11. package/content/plugins/buildSchemaPlugins.d.ts +7 -0
  12. package/content/plugins/buildSchemaPlugins.js +29 -0
  13. package/content/plugins/crud/contentEntry/afterDelete.d.ts +7 -0
  14. package/content/plugins/crud/contentEntry/afterDelete.js +41 -0
  15. package/content/plugins/crud/contentEntry/beforeCreate.d.ts +7 -0
  16. package/content/plugins/crud/contentEntry/beforeCreate.js +28 -0
  17. package/content/plugins/crud/contentEntry/beforeUpdate.d.ts +7 -0
  18. package/content/plugins/crud/contentEntry/beforeUpdate.js +28 -0
  19. package/content/plugins/crud/contentEntry/entryDataValidation.d.ts +4 -0
  20. package/content/plugins/crud/contentEntry/entryDataValidation.js +188 -0
  21. package/content/plugins/crud/contentEntry/markLockedFields.d.ts +12 -0
  22. package/content/plugins/crud/contentEntry/markLockedFields.js +117 -0
  23. package/content/plugins/crud/contentEntry.crud.d.ts +17 -0
  24. package/content/plugins/crud/contentEntry.crud.js +931 -0
  25. package/content/plugins/crud/contentModel/afterCreate.d.ts +7 -0
  26. package/content/plugins/crud/contentModel/afterCreate.js +18 -0
  27. package/content/plugins/crud/contentModel/afterDelete.d.ts +7 -0
  28. package/content/plugins/crud/contentModel/afterDelete.js +18 -0
  29. package/content/plugins/crud/contentModel/afterUpdate.d.ts +7 -0
  30. package/content/plugins/crud/contentModel/afterUpdate.js +18 -0
  31. package/content/plugins/crud/contentModel/beforeCreate.d.ts +9 -0
  32. package/content/plugins/crud/contentModel/beforeCreate.js +146 -0
  33. package/content/plugins/crud/contentModel/beforeDelete.d.ts +9 -0
  34. package/content/plugins/crud/contentModel/beforeDelete.js +56 -0
  35. package/content/plugins/crud/contentModel/beforeUpdate.d.ts +9 -0
  36. package/content/plugins/crud/contentModel/beforeUpdate.js +128 -0
  37. package/content/plugins/crud/contentModel/contentModelManagerFactory.d.ts +2 -0
  38. package/content/plugins/crud/contentModel/contentModelManagerFactory.js +29 -0
  39. package/content/plugins/crud/contentModel/createFieldModels.d.ts +2 -0
  40. package/content/plugins/crud/contentModel/createFieldModels.js +22 -0
  41. package/content/plugins/crud/contentModel/idValidation.d.ts +2 -0
  42. package/content/plugins/crud/contentModel/idValidation.js +22 -0
  43. package/content/plugins/crud/contentModel/models.d.ts +3 -0
  44. package/content/plugins/crud/contentModel/models.js +141 -0
  45. package/content/plugins/crud/contentModel/validateLayout.d.ts +2 -0
  46. package/content/plugins/crud/contentModel/validateLayout.js +38 -0
  47. package/content/plugins/crud/contentModel.crud.d.ts +12 -0
  48. package/content/plugins/crud/contentModel.crud.js +425 -0
  49. package/content/plugins/crud/contentModelGroup/beforeCreate.d.ts +9 -0
  50. package/content/plugins/crud/contentModelGroup/beforeCreate.js +66 -0
  51. package/content/plugins/crud/contentModelGroup/beforeDelete.d.ts +9 -0
  52. package/content/plugins/crud/contentModelGroup/beforeDelete.js +48 -0
  53. package/content/plugins/crud/contentModelGroup/beforeUpdate.d.ts +8 -0
  54. package/content/plugins/crud/contentModelGroup/beforeUpdate.js +28 -0
  55. package/content/plugins/crud/contentModelGroup.crud.d.ts +12 -0
  56. package/content/plugins/crud/contentModelGroup.crud.js +351 -0
  57. package/content/plugins/crud/index.d.ts +6 -0
  58. package/content/plugins/crud/index.js +100 -0
  59. package/content/plugins/graphqlFields/boolean.d.ts +3 -0
  60. package/content/plugins/graphqlFields/boolean.js +69 -0
  61. package/content/plugins/graphqlFields/datetime.d.ts +3 -0
  62. package/content/plugins/graphqlFields/datetime.js +83 -0
  63. package/content/plugins/graphqlFields/file.d.ts +3 -0
  64. package/content/plugins/graphqlFields/file.js +49 -0
  65. package/content/plugins/graphqlFields/index.d.ts +2 -0
  66. package/content/plugins/graphqlFields/index.js +30 -0
  67. package/content/plugins/graphqlFields/longText.d.ts +3 -0
  68. package/content/plugins/graphqlFields/longText.js +62 -0
  69. package/content/plugins/graphqlFields/number.d.ts +3 -0
  70. package/content/plugins/graphqlFields/number.js +75 -0
  71. package/content/plugins/graphqlFields/object.d.ts +3 -0
  72. package/content/plugins/graphqlFields/object.js +180 -0
  73. package/content/plugins/graphqlFields/ref.d.ts +3 -0
  74. package/content/plugins/graphqlFields/ref.js +205 -0
  75. package/content/plugins/graphqlFields/richText.d.ts +3 -0
  76. package/content/plugins/graphqlFields/richText.js +55 -0
  77. package/content/plugins/graphqlFields/text.d.ts +3 -0
  78. package/content/plugins/graphqlFields/text.js +72 -0
  79. package/content/plugins/internalSecurity/InternalAuthenticationPlugin.d.ts +8 -0
  80. package/content/plugins/internalSecurity/InternalAuthenticationPlugin.js +54 -0
  81. package/content/plugins/internalSecurity/InternalAuthorizationPlugin.d.ts +7 -0
  82. package/content/plugins/internalSecurity/InternalAuthorizationPlugin.js +35 -0
  83. package/content/plugins/modelManager/DefaultCmsModelManager.d.ts +15 -0
  84. package/content/plugins/modelManager/DefaultCmsModelManager.js +62 -0
  85. package/content/plugins/modelManager/index.d.ts +3 -0
  86. package/content/plugins/modelManager/index.js +20 -0
  87. package/content/plugins/schema/baseSchema.d.ts +4 -0
  88. package/content/plugins/schema/baseSchema.js +98 -0
  89. package/content/plugins/schema/contentEntries.d.ts +4 -0
  90. package/content/plugins/schema/contentEntries.js +166 -0
  91. package/content/plugins/schema/contentModelGroups.d.ts +4 -0
  92. package/content/plugins/schema/contentModelGroups.js +153 -0
  93. package/content/plugins/schema/contentModels.d.ts +4 -0
  94. package/content/plugins/schema/contentModels.js +225 -0
  95. package/content/plugins/schema/createFieldResolvers.d.ts +19 -0
  96. package/content/plugins/schema/createFieldResolvers.js +92 -0
  97. package/content/plugins/schema/createManageResolvers.d.ts +11 -0
  98. package/content/plugins/schema/createManageResolvers.js +135 -0
  99. package/content/plugins/schema/createManageSDL.d.ts +9 -0
  100. package/content/plugins/schema/createManageSDL.js +153 -0
  101. package/content/plugins/schema/createPreviewResolvers.d.ts +10 -0
  102. package/content/plugins/schema/createPreviewResolvers.js +55 -0
  103. package/content/plugins/schema/createReadResolvers.d.ts +10 -0
  104. package/content/plugins/schema/createReadResolvers.js +55 -0
  105. package/content/plugins/schema/createReadSDL.d.ts +9 -0
  106. package/content/plugins/schema/createReadSDL.js +96 -0
  107. package/content/plugins/schema/resolvers/commonFieldResolvers.d.ts +6 -0
  108. package/content/plugins/schema/resolvers/commonFieldResolvers.js +14 -0
  109. package/content/plugins/schema/resolvers/manage/resolveCreate.d.ts +6 -0
  110. package/content/plugins/schema/resolvers/manage/resolveCreate.js +23 -0
  111. package/content/plugins/schema/resolvers/manage/resolveCreateFrom.d.ts +7 -0
  112. package/content/plugins/schema/resolvers/manage/resolveCreateFrom.js +23 -0
  113. package/content/plugins/schema/resolvers/manage/resolveDelete.d.ts +2 -0
  114. package/content/plugins/schema/resolvers/manage/resolveDelete.js +30 -0
  115. package/content/plugins/schema/resolvers/manage/resolveGet.d.ts +2 -0
  116. package/content/plugins/schema/resolvers/manage/resolveGet.js +21 -0
  117. package/content/plugins/schema/resolvers/manage/resolveGetByIds.d.ts +2 -0
  118. package/content/plugins/schema/resolvers/manage/resolveGetByIds.js +23 -0
  119. package/content/plugins/schema/resolvers/manage/resolveGetRevisions.d.ts +2 -0
  120. package/content/plugins/schema/resolvers/manage/resolveGetRevisions.js +23 -0
  121. package/content/plugins/schema/resolvers/manage/resolveList.d.ts +2 -0
  122. package/content/plugins/schema/resolvers/manage/resolveList.js +23 -0
  123. package/content/plugins/schema/resolvers/manage/resolvePublish.d.ts +2 -0
  124. package/content/plugins/schema/resolvers/manage/resolvePublish.js +21 -0
  125. package/content/plugins/schema/resolvers/manage/resolveRequestChanges.d.ts +6 -0
  126. package/content/plugins/schema/resolvers/manage/resolveRequestChanges.js +23 -0
  127. package/content/plugins/schema/resolvers/manage/resolveRequestReview.d.ts +6 -0
  128. package/content/plugins/schema/resolvers/manage/resolveRequestReview.js +23 -0
  129. package/content/plugins/schema/resolvers/manage/resolveUnpublish.d.ts +2 -0
  130. package/content/plugins/schema/resolvers/manage/resolveUnpublish.js +21 -0
  131. package/content/plugins/schema/resolvers/manage/resolveUpdate.d.ts +7 -0
  132. package/content/plugins/schema/resolvers/manage/resolveUpdate.js +23 -0
  133. package/content/plugins/schema/resolvers/preview/resolveGet.d.ts +2 -0
  134. package/content/plugins/schema/resolvers/preview/resolveGet.js +38 -0
  135. package/content/plugins/schema/resolvers/preview/resolveList.d.ts +2 -0
  136. package/content/plugins/schema/resolvers/preview/resolveList.js +23 -0
  137. package/content/plugins/schema/resolvers/read/resolveGet.d.ts +2 -0
  138. package/content/plugins/schema/resolvers/read/resolveGet.js +38 -0
  139. package/content/plugins/schema/resolvers/read/resolveList.d.ts +2 -0
  140. package/content/plugins/schema/resolvers/read/resolveList.js +23 -0
  141. package/content/plugins/schema/schemaPlugins.d.ts +3 -0
  142. package/content/plugins/schema/schemaPlugins.js +92 -0
  143. package/content/plugins/storage/StorageTransformPlugin.d.ts +30 -0
  144. package/content/plugins/storage/StorageTransformPlugin.js +36 -0
  145. package/content/plugins/storage/default.d.ts +3 -0
  146. package/content/plugins/storage/default.js +28 -0
  147. package/content/plugins/storage/object.d.ts +3 -0
  148. package/content/plugins/storage/object.js +119 -0
  149. package/content/plugins/utils/createTypeName.d.ts +3 -0
  150. package/content/plugins/utils/createTypeName.js +28 -0
  151. package/content/plugins/utils/entryStorage.d.ts +17 -0
  152. package/content/plugins/utils/entryStorage.js +125 -0
  153. package/content/plugins/utils/getEntryTitle.d.ts +2 -0
  154. package/content/plugins/utils/getEntryTitle.js +42 -0
  155. package/content/plugins/utils/getSchemaFromFieldPlugins.d.ts +11 -0
  156. package/content/plugins/utils/getSchemaFromFieldPlugins.js +30 -0
  157. package/content/plugins/utils/pluralizedTypeName.d.ts +1 -0
  158. package/content/plugins/utils/pluralizedTypeName.js +26 -0
  159. package/content/plugins/utils/renderFields.d.ts +16 -0
  160. package/content/plugins/utils/renderFields.js +51 -0
  161. package/content/plugins/utils/renderGetFilterFields.d.ts +9 -0
  162. package/content/plugins/utils/renderGetFilterFields.js +41 -0
  163. package/content/plugins/utils/renderInputFields.d.ts +14 -0
  164. package/content/plugins/utils/renderInputFields.js +53 -0
  165. package/content/plugins/utils/renderListFilterFields.d.ts +10 -0
  166. package/content/plugins/utils/renderListFilterFields.js +39 -0
  167. package/content/plugins/utils/renderSortEnum.d.ts +9 -0
  168. package/content/plugins/utils/renderSortEnum.js +32 -0
  169. package/content/plugins/validators/dateGte.d.ts +3 -0
  170. package/content/plugins/validators/dateGte.js +37 -0
  171. package/content/plugins/validators/dateLte.d.ts +3 -0
  172. package/content/plugins/validators/dateLte.js +37 -0
  173. package/content/plugins/validators/gte.d.ts +3 -0
  174. package/content/plugins/validators/gte.js +32 -0
  175. package/content/plugins/validators/in.d.ts +3 -0
  176. package/content/plugins/validators/in.js +32 -0
  177. package/content/plugins/validators/index.d.ts +2 -0
  178. package/content/plugins/validators/index.js +36 -0
  179. package/content/plugins/validators/lte.d.ts +3 -0
  180. package/content/plugins/validators/lte.js +32 -0
  181. package/content/plugins/validators/maxLength.d.ts +3 -0
  182. package/content/plugins/validators/maxLength.js +32 -0
  183. package/content/plugins/validators/minLength.d.ts +3 -0
  184. package/content/plugins/validators/minLength.js +32 -0
  185. package/content/plugins/validators/pattern.d.ts +3 -0
  186. package/content/plugins/validators/pattern.js +47 -0
  187. package/content/plugins/validators/patternPlugins/email.d.ts +3 -0
  188. package/content/plugins/validators/patternPlugins/email.js +17 -0
  189. package/content/plugins/validators/patternPlugins/index.d.ts +2 -0
  190. package/content/plugins/validators/patternPlugins/index.js +19 -0
  191. package/content/plugins/validators/patternPlugins/lowerCase.d.ts +3 -0
  192. package/content/plugins/validators/patternPlugins/lowerCase.js +17 -0
  193. package/content/plugins/validators/patternPlugins/upperCase.d.ts +3 -0
  194. package/content/plugins/validators/patternPlugins/upperCase.js +17 -0
  195. package/content/plugins/validators/patternPlugins/url.d.ts +3 -0
  196. package/content/plugins/validators/patternPlugins/url.js +17 -0
  197. package/content/plugins/validators/required.d.ts +3 -0
  198. package/content/plugins/validators/required.js +25 -0
  199. package/content/plugins/validators/timeGte.d.ts +3 -0
  200. package/content/plugins/validators/timeGte.js +32 -0
  201. package/content/plugins/validators/timeLte.d.ts +3 -0
  202. package/content/plugins/validators/timeLte.js +32 -0
  203. package/index.d.ts +12 -0
  204. package/index.js +66 -0
  205. package/migrateCMSPermissions.d.ts +17 -0
  206. package/migrateCMSPermissions.js +193 -0
  207. package/package.json +80 -0
  208. package/plugins/context.d.ts +4 -0
  209. package/plugins/context.js +34 -0
  210. package/plugins/crud/index.d.ts +6 -0
  211. package/plugins/crud/index.js +100 -0
  212. package/plugins/crud/settings.crud.d.ts +10 -0
  213. package/plugins/crud/settings.crud.js +93 -0
  214. package/plugins/crud/system.crud.d.ts +10 -0
  215. package/plugins/crud/system.crud.js +182 -0
  216. package/plugins/graphql/system.d.ts +17 -0
  217. package/plugins/graphql/system.js +72 -0
  218. package/plugins/graphql.d.ts +2 -0
  219. package/plugins/graphql.js +79 -0
  220. package/plugins/upgrades/index.d.ts +2 -0
  221. package/plugins/upgrades/index.js +14 -0
  222. package/plugins/upgrades/v5.5.0/helpers.d.ts +6 -0
  223. package/plugins/upgrades/v5.5.0/helpers.js +10 -0
  224. package/plugins/upgrades/v5.5.0/index.d.ts +4 -0
  225. package/plugins/upgrades/v5.5.0/index.js +129 -0
  226. package/transformers.d.ts +2 -0
  227. package/transformers.js +25 -0
  228. package/types.d.ts +2149 -0
  229. package/types.js +366 -0
  230. package/utils.d.ts +25 -0
  231. package/utils.js +251 -0
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+
10
+ var _text = _interopRequireDefault(require("./text"));
11
+
12
+ var _longText = _interopRequireDefault(require("./longText"));
13
+
14
+ var _ref = _interopRequireDefault(require("./ref"));
15
+
16
+ var _number = _interopRequireDefault(require("./number"));
17
+
18
+ var _boolean = _interopRequireDefault(require("./boolean"));
19
+
20
+ var _datetime = _interopRequireDefault(require("./datetime"));
21
+
22
+ var _richText = _interopRequireDefault(require("./richText"));
23
+
24
+ var _file = _interopRequireDefault(require("./file"));
25
+
26
+ var _object = _interopRequireDefault(require("./object"));
27
+
28
+ var _default = () => [_text.default, _ref.default, _number.default, _datetime.default, _boolean.default, _longText.default, _richText.default, _file.default, _object.default];
29
+
30
+ exports.default = _default;
@@ -0,0 +1,3 @@
1
+ import { CmsModelFieldToGraphQLPlugin } from "../../../types";
2
+ declare const plugin: CmsModelFieldToGraphQLPlugin;
3
+ export default plugin;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ const createListFilters = ({
9
+ field
10
+ }) => {
11
+ return `
12
+ ${field.fieldId}_contains: String
13
+ ${field.fieldId}_not_contains: String
14
+ `;
15
+ };
16
+
17
+ const plugin = {
18
+ name: "cms-model-field-to-graphql-long-text",
19
+ type: "cms-model-field-to-graphql",
20
+ fieldType: "long-text",
21
+ isSortable: false,
22
+ isSearchable: true,
23
+ read: {
24
+ createTypeField({
25
+ field
26
+ }) {
27
+ if (field.multipleValues) {
28
+ return `${field.fieldId}: [String]`;
29
+ }
30
+
31
+ return `${field.fieldId}: String`;
32
+ },
33
+
34
+ createListFilters
35
+ },
36
+ manage: {
37
+ createListFilters,
38
+
39
+ createTypeField({
40
+ field
41
+ }) {
42
+ if (field.multipleValues) {
43
+ return field.fieldId + ": [String]";
44
+ }
45
+
46
+ return field.fieldId + ": String";
47
+ },
48
+
49
+ createInputField({
50
+ field
51
+ }) {
52
+ if (field.multipleValues) {
53
+ return field.fieldId + ": [String]";
54
+ }
55
+
56
+ return field.fieldId + ": String";
57
+ }
58
+
59
+ }
60
+ };
61
+ var _default = plugin;
62
+ exports.default = _default;
@@ -0,0 +1,3 @@
1
+ import { CmsModelFieldToGraphQLPlugin } from "../../../types";
2
+ declare const plugin: CmsModelFieldToGraphQLPlugin;
3
+ export default plugin;
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ const createListFilters = ({
9
+ field
10
+ }) => {
11
+ return `
12
+ ${field.fieldId}: Number
13
+ ${field.fieldId}_not: Number
14
+ ${field.fieldId}_in: [Number]
15
+ ${field.fieldId}_not_in: [Number]
16
+ ${field.fieldId}_lt: Number
17
+ ${field.fieldId}_lte: Number
18
+ ${field.fieldId}_gt: Number
19
+ ${field.fieldId}_gte: Number
20
+ `;
21
+ };
22
+
23
+ const plugin = {
24
+ name: "cms-model-field-to-graphql-number",
25
+ type: "cms-model-field-to-graphql",
26
+ fieldType: "number",
27
+ isSortable: true,
28
+ isSearchable: true,
29
+ read: {
30
+ createGetFilters({
31
+ field
32
+ }) {
33
+ return `${field.fieldId}: Number`;
34
+ },
35
+
36
+ createListFilters,
37
+
38
+ createTypeField({
39
+ field
40
+ }) {
41
+ if (field.multipleValues) {
42
+ return `${field.fieldId}: [Number]`;
43
+ }
44
+
45
+ return `${field.fieldId}: Number`;
46
+ }
47
+
48
+ },
49
+ manage: {
50
+ createListFilters,
51
+
52
+ createTypeField({
53
+ field
54
+ }) {
55
+ if (field.multipleValues) {
56
+ return field.fieldId + ": [Number]";
57
+ }
58
+
59
+ return field.fieldId + ": Number";
60
+ },
61
+
62
+ createInputField({
63
+ field
64
+ }) {
65
+ if (field.multipleValues) {
66
+ return field.fieldId + ": [Number]";
67
+ }
68
+
69
+ return field.fieldId + ": Number";
70
+ }
71
+
72
+ }
73
+ };
74
+ var _default = plugin;
75
+ exports.default = _default;
@@ -0,0 +1,3 @@
1
+ import { CmsModelFieldToGraphQLPlugin } from "../../../types";
2
+ declare const plugin: CmsModelFieldToGraphQLPlugin;
3
+ export default plugin;
@@ -0,0 +1,180 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+
10
+ var _upperFirst = _interopRequireDefault(require("lodash/upperFirst"));
11
+
12
+ var _renderFields = require("../utils/renderFields");
13
+
14
+ var _renderInputFields = require("../utils/renderInputFields");
15
+
16
+ var _createTypeName = require("../utils/createTypeName");
17
+
18
+ const typeFromField = ({
19
+ typeOfType,
20
+ model,
21
+ type,
22
+ field,
23
+ fieldTypePlugins
24
+ }) => {
25
+ const typeSuffix = typeOfType === "input" ? "Input" : "";
26
+ const typeName = (0, _createTypeName.createTypeName)(model.modelId);
27
+ const mTypeName = (0, _createTypeName.createManageTypeName)(typeName); // `field` is an "object" field
28
+
29
+ const fields = field.settings.fields;
30
+ const fieldTypeName = `${mTypeName}_${(0, _upperFirst.default)(field.fieldId)}`;
31
+ const typeFields = [];
32
+ const nestedTypes = []; // Once the loop below starts, we'll be executing a recursive "object" type generation.
33
+ // The main trick here is that nested objects don't know who the parent is, and will generate
34
+ // type names using the "model", as if they're at the top level:
35
+ // Every time the types are returned, we need to replace the model name in the generated type name
36
+ // with the actual prefix which includes parent field name type.
37
+
38
+ const replace = new RegExp(`${mTypeName}_`, "g");
39
+
40
+ for (const f of fields) {
41
+ const {
42
+ fields,
43
+ typeDefs
44
+ } = typeOfType === "type" ? (0, _renderFields.renderField)({
45
+ field: f,
46
+ type,
47
+ model,
48
+ fieldTypePlugins
49
+ }) : (0, _renderInputFields.renderInputField)({
50
+ field: f,
51
+ model,
52
+ fieldTypePlugins
53
+ });
54
+ typeFields.push(fields.replace(replace, `${fieldTypeName}_`));
55
+
56
+ if (typeDefs) {
57
+ nestedTypes.push(typeDefs.replace(replace, `${fieldTypeName}_`));
58
+ }
59
+ }
60
+
61
+ return {
62
+ fieldType: `${fieldTypeName}${typeSuffix}`,
63
+ typeDefs:
64
+ /* GraphQL */
65
+ `
66
+ ${nestedTypes.join("\n")}
67
+
68
+ ${typeOfType} ${fieldTypeName}${typeSuffix} {
69
+ ${typeFields.join("\n")}
70
+ }
71
+ `
72
+ };
73
+ };
74
+
75
+ const plugin = {
76
+ name: "cms-model-field-to-graphql-object",
77
+ type: "cms-model-field-to-graphql",
78
+ fieldType: "object",
79
+ isSortable: false,
80
+ isSearchable: false,
81
+ read: {
82
+ createTypeField({
83
+ field,
84
+ model,
85
+ fieldTypePlugins
86
+ }) {
87
+ const {
88
+ fieldType,
89
+ typeDefs
90
+ } = typeFromField({
91
+ typeOfType: "type",
92
+ model,
93
+ type: "read",
94
+ field,
95
+ fieldTypePlugins
96
+ });
97
+ return {
98
+ fields: `${field.fieldId}: ${field.multipleValues ? `[${fieldType}!]` : fieldType}`,
99
+ typeDefs
100
+ };
101
+ },
102
+
103
+ createResolver({
104
+ field,
105
+ createFieldResolvers,
106
+ graphQLType
107
+ }) {
108
+ const fieldType = `${graphQLType}_${(0, _upperFirst.default)(field.fieldId)}`;
109
+ return {
110
+ resolver: null,
111
+ typeResolvers: createFieldResolvers({
112
+ graphQLType: fieldType,
113
+ fields: field.settings.fields
114
+ })
115
+ };
116
+ }
117
+
118
+ },
119
+ manage: {
120
+ createTypeField({
121
+ model,
122
+ field,
123
+ fieldTypePlugins
124
+ }) {
125
+ const {
126
+ fieldType,
127
+ typeDefs
128
+ } = typeFromField({
129
+ typeOfType: "type",
130
+ model,
131
+ type: "manage",
132
+ field,
133
+ fieldTypePlugins
134
+ });
135
+ return {
136
+ fields: `${field.fieldId}: ${field.multipleValues ? `[${fieldType}!]` : fieldType}`,
137
+ typeDefs
138
+ };
139
+ },
140
+
141
+ createInputField({
142
+ model,
143
+ field,
144
+ fieldTypePlugins
145
+ }) {
146
+ const {
147
+ fieldType,
148
+ typeDefs
149
+ } = typeFromField({
150
+ typeOfType: "input",
151
+ model,
152
+ type: "manage",
153
+ field,
154
+ fieldTypePlugins
155
+ });
156
+ return {
157
+ fields: `${field.fieldId}: ${field.multipleValues ? `[${fieldType}!]` : fieldType}`,
158
+ typeDefs
159
+ };
160
+ },
161
+
162
+ createResolver({
163
+ graphQLType,
164
+ field,
165
+ createFieldResolvers
166
+ }) {
167
+ const fieldType = `${graphQLType}_${(0, _upperFirst.default)(field.fieldId)}`;
168
+ return {
169
+ resolver: null,
170
+ typeResolvers: createFieldResolvers({
171
+ graphQLType: fieldType,
172
+ fields: field.settings.fields
173
+ })
174
+ };
175
+ }
176
+
177
+ }
178
+ };
179
+ var _default = plugin;
180
+ exports.default = _default;
@@ -0,0 +1,3 @@
1
+ import { CmsModelFieldToGraphQLPlugin } from "../../../types";
2
+ declare const plugin: CmsModelFieldToGraphQLPlugin;
3
+ export default plugin;
@@ -0,0 +1,205 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+
12
+ var _createTypeName = require("../utils/createTypeName");
13
+
14
+ 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
+
16
+ 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; }
17
+
18
+ const createUnionTypeName = (model, field) => {
19
+ return `${(0, _createTypeName.createReadTypeName)(model.modelId)}${(0, _createTypeName.createReadTypeName)(field.fieldId)}`;
20
+ };
21
+
22
+ const createListFilters = ({
23
+ field
24
+ }) => {
25
+ return `
26
+ ${field.fieldId}: String
27
+ ${field.fieldId}_in: [String!]
28
+ ${field.fieldId}_not: String
29
+ ${field.fieldId}_not_in: [String!]
30
+ `;
31
+ };
32
+
33
+ const appendTypename = (entries, typename) => {
34
+ return entries.map(item => {
35
+ item["__typename"] = typename;
36
+ return item;
37
+ });
38
+ };
39
+
40
+ const modelIdToTypeName = new Map();
41
+ const plugin = {
42
+ name: "cms-model-field-to-graphql-ref",
43
+ type: "cms-model-field-to-graphql",
44
+ fieldType: "ref",
45
+ isSortable: false,
46
+ isSearchable: true,
47
+ read: {
48
+ createTypeField({
49
+ model,
50
+ field
51
+ }) {
52
+ const gqlType = field.settings.models.length > 1 ? createUnionTypeName(model, field) : (0, _createTypeName.createReadTypeName)(field.settings.models[0].modelId);
53
+ return field.fieldId + `: ${field.multipleValues ? `[${gqlType}]` : gqlType}`;
54
+ },
55
+
56
+ createResolver({
57
+ field
58
+ }) {
59
+ // Create a map of model types and corresponding modelIds so resolvers don't need to perform the lookup.
60
+ for (const item of field.settings.models) {
61
+ modelIdToTypeName.set(item.modelId, (0, _createTypeName.createReadTypeName)(item.modelId));
62
+ }
63
+
64
+ return async (parent, _, context) => {
65
+ const {
66
+ cms
67
+ } = context; // Get field value for this entry
68
+
69
+ const value = parent[field.fieldId];
70
+
71
+ if (!value) {
72
+ return null;
73
+ }
74
+
75
+ if (field.multipleValues) {
76
+ if (!value.length) {
77
+ return [];
78
+ }
79
+
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
92
+ const model = await cms.getModelManager(modelId);
93
+ let entries; // `read` API works with `published` data
94
+
95
+ if (cms.READ) {
96
+ entries = await model.getPublishedByIds([entryId]);
97
+ } // `preview` and `manage` with `latest` data
98
+ else {
99
+ entries = await model.getLatestByIds([entryId]);
100
+ }
101
+
102
+ return appendTypename(entries, modelIdToTypeName.get(modelId));
103
+ });
104
+ return await Promise.all(getters).then(results => results.reduce((result, item) => result.concat(item), []));
105
+ } // Get model manager, to get access to CRUD methods
106
+
107
+
108
+ const model = await cms.getModelManager(value.modelId);
109
+ let revisions; // `read` API works with `published` data
110
+
111
+ if (cms.READ) {
112
+ revisions = await model.getPublishedByIds([value.entryId]);
113
+ } // `preview` API works with `latest` data
114
+ else {
115
+ revisions = await model.getLatestByIds([value.entryId]);
116
+ }
117
+ /**
118
+ * If there are no revisions we must return null.
119
+ */
120
+
121
+
122
+ if (!revisions || revisions.length === 0) {
123
+ return null;
124
+ }
125
+
126
+ return _objectSpread(_objectSpread({}, revisions[0]), {}, {
127
+ __typename: modelIdToTypeName.get(value.modelId)
128
+ });
129
+ };
130
+ },
131
+
132
+ createSchema({
133
+ models
134
+ }) {
135
+ const unionFields = [];
136
+
137
+ for (const model of models) {
138
+ // Generate a dedicated union type for every `ref` field which has more than 1 content model assigned.
139
+ model.fields.filter(field => field.type === "ref" && field.settings.models.length > 1).forEach(field => unionFields.push({
140
+ model,
141
+ field,
142
+ typeName: createUnionTypeName(model, field)
143
+ }));
144
+ }
145
+
146
+ if (!unionFields.length) {
147
+ return null;
148
+ }
149
+
150
+ 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"),
157
+ resolvers: {}
158
+ };
159
+ },
160
+
161
+ createListFilters
162
+ },
163
+ manage: {
164
+ createSchema() {
165
+ return {
166
+ typeDefs: `
167
+ type RefField {
168
+ modelId: String!
169
+ entryId: ID!
170
+ }
171
+
172
+ input RefFieldInput {
173
+ modelId: String!
174
+ entryId: ID!
175
+ }
176
+ `,
177
+ resolvers: {}
178
+ };
179
+ },
180
+
181
+ createTypeField({
182
+ field
183
+ }) {
184
+ if (field.multipleValues) {
185
+ return `${field.fieldId}: [RefField]`;
186
+ }
187
+
188
+ return `${field.fieldId}: RefField`;
189
+ },
190
+
191
+ createInputField({
192
+ field
193
+ }) {
194
+ if (field.multipleValues) {
195
+ return field.fieldId + ": [RefFieldInput]";
196
+ }
197
+
198
+ return field.fieldId + ": RefFieldInput";
199
+ },
200
+
201
+ createListFilters
202
+ }
203
+ };
204
+ var _default = plugin;
205
+ exports.default = _default;
@@ -0,0 +1,3 @@
1
+ import { CmsModelFieldToGraphQLPlugin } from "../../../types";
2
+ declare const plugin: CmsModelFieldToGraphQLPlugin;
3
+ export default plugin;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ const plugin = {
8
+ name: "cms-model-field-to-graphql-rich-text",
9
+ type: "cms-model-field-to-graphql",
10
+ fieldType: "rich-text",
11
+ isSortable: false,
12
+ isSearchable: false,
13
+ read: {
14
+ createTypeField({
15
+ field
16
+ }) {
17
+ if (field.multipleValues) {
18
+ return `${field.fieldId}: [JSON]`;
19
+ }
20
+
21
+ return `${field.fieldId}: JSON`;
22
+ },
23
+
24
+ createGetFilters({
25
+ field
26
+ }) {
27
+ return `${field.fieldId}: JSON`;
28
+ }
29
+
30
+ },
31
+ manage: {
32
+ createTypeField({
33
+ field
34
+ }) {
35
+ if (field.multipleValues) {
36
+ return `${field.fieldId}: [JSON]`;
37
+ }
38
+
39
+ return `${field.fieldId}: JSON`;
40
+ },
41
+
42
+ createInputField({
43
+ field
44
+ }) {
45
+ if (field.multipleValues) {
46
+ return field.fieldId + ": [JSON]";
47
+ }
48
+
49
+ return field.fieldId + ": JSON";
50
+ }
51
+
52
+ }
53
+ };
54
+ var _default = plugin;
55
+ exports.default = _default;
@@ -0,0 +1,3 @@
1
+ import { CmsModelFieldToGraphQLPlugin } from "../../../types";
2
+ declare const plugin: CmsModelFieldToGraphQLPlugin;
3
+ export default plugin;
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ const createListFilters = ({
9
+ field
10
+ }) => {
11
+ return `
12
+ ${field.fieldId}: String
13
+ ${field.fieldId}_not: String
14
+ ${field.fieldId}_in: [String]
15
+ ${field.fieldId}_not_in: [String]
16
+ ${field.fieldId}_contains: String
17
+ ${field.fieldId}_not_contains: String
18
+ `;
19
+ };
20
+
21
+ const plugin = {
22
+ name: "cms-model-field-to-graphql-text",
23
+ type: "cms-model-field-to-graphql",
24
+ fieldType: "text",
25
+ isSortable: true,
26
+ isSearchable: true,
27
+ read: {
28
+ createTypeField({
29
+ field
30
+ }) {
31
+ if (field.multipleValues) {
32
+ return `${field.fieldId}: [String]`;
33
+ }
34
+
35
+ return `${field.fieldId}: String`;
36
+ },
37
+
38
+ createGetFilters({
39
+ field
40
+ }) {
41
+ return `${field.fieldId}: String`;
42
+ },
43
+
44
+ createListFilters
45
+ },
46
+ manage: {
47
+ createListFilters,
48
+
49
+ createTypeField({
50
+ field
51
+ }) {
52
+ if (field.multipleValues) {
53
+ return `${field.fieldId}: [String]`;
54
+ }
55
+
56
+ return `${field.fieldId}: String`;
57
+ },
58
+
59
+ createInputField({
60
+ field
61
+ }) {
62
+ if (field.multipleValues) {
63
+ return field.fieldId + ": [String]";
64
+ }
65
+
66
+ return field.fieldId + ": String";
67
+ }
68
+
69
+ }
70
+ };
71
+ var _default = plugin;
72
+ exports.default = _default;