@webiny/api-headless-cms 0.0.0-unstable.990c3ab1b6 → 0.0.0-unstable.aa00eecd97

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 (296) hide show
  1. package/context.d.ts +5 -2
  2. package/context.js +61 -8
  3. package/context.js.map +1 -1
  4. package/crud/contentEntry/markLockedFields.d.ts +1 -1
  5. package/crud/contentEntry/markLockedFields.js +17 -4
  6. package/crud/contentEntry/markLockedFields.js.map +1 -1
  7. package/crud/contentEntry/referenceFieldsMapping.js +40 -9
  8. package/crud/contentEntry/referenceFieldsMapping.js.map +1 -1
  9. package/crud/contentEntry/searchableFields.d.ts +9 -0
  10. package/crud/contentEntry/searchableFields.js +72 -0
  11. package/crud/contentEntry/searchableFields.js.map +1 -0
  12. package/crud/contentEntry.crud.d.ts +8 -5
  13. package/crud/contentEntry.crud.js +1081 -841
  14. package/crud/contentEntry.crud.js.map +1 -1
  15. package/crud/contentModel/beforeCreate.d.ts +2 -3
  16. package/crud/contentModel/beforeCreate.js +43 -81
  17. package/crud/contentModel/beforeCreate.js.map +1 -1
  18. package/crud/contentModel/beforeDelete.d.ts +1 -1
  19. package/crud/contentModel/beforeDelete.js +1 -5
  20. package/crud/contentModel/beforeDelete.js.map +1 -1
  21. package/crud/contentModel/beforeUpdate.d.ts +2 -4
  22. package/crud/contentModel/beforeUpdate.js +33 -5
  23. package/crud/contentModel/beforeUpdate.js.map +1 -1
  24. package/crud/contentModel/compatibility/modelApiName.d.ts +3 -0
  25. package/crud/contentModel/compatibility/modelApiName.js +24 -0
  26. package/crud/contentModel/compatibility/modelApiName.js.map +1 -0
  27. package/crud/contentModel/createFieldStorageId.js +4 -1
  28. package/crud/contentModel/createFieldStorageId.js.map +1 -1
  29. package/crud/contentModel/defaultFields.d.ts +5 -0
  30. package/crud/contentModel/defaultFields.js +58 -0
  31. package/crud/contentModel/defaultFields.js.map +1 -0
  32. package/crud/contentModel/fields/descriptionField.d.ts +2 -0
  33. package/crud/contentModel/fields/descriptionField.js +42 -0
  34. package/crud/contentModel/fields/descriptionField.js.map +1 -0
  35. package/crud/contentModel/fields/imageField.d.ts +2 -0
  36. package/crud/contentModel/fields/imageField.js +46 -0
  37. package/crud/contentModel/fields/imageField.js.map +1 -0
  38. package/crud/contentModel/fields/titleField.d.ts +2 -0
  39. package/crud/contentModel/fields/titleField.js +58 -0
  40. package/crud/contentModel/fields/titleField.js.map +1 -0
  41. package/crud/contentModel/validate/endingAllowed.d.ts +6 -0
  42. package/crud/contentModel/validate/endingAllowed.js +26 -0
  43. package/crud/contentModel/validate/endingAllowed.js.map +1 -0
  44. package/crud/contentModel/validate/isModelEndingAllowed.d.ts +6 -0
  45. package/crud/contentModel/validate/isModelEndingAllowed.js +24 -0
  46. package/crud/contentModel/validate/isModelEndingAllowed.js.map +1 -0
  47. package/crud/contentModel/validate/modelId.d.ts +11 -0
  48. package/crud/contentModel/validate/modelId.js +36 -0
  49. package/crud/contentModel/validate/modelId.js.map +1 -0
  50. package/crud/contentModel/validate/pluralApiName.d.ts +7 -0
  51. package/crud/contentModel/validate/pluralApiName.js +24 -0
  52. package/crud/contentModel/validate/pluralApiName.js.map +1 -0
  53. package/crud/contentModel/validate/singularApiName.d.ts +7 -0
  54. package/crud/contentModel/validate/singularApiName.js +24 -0
  55. package/crud/contentModel/validate/singularApiName.js.map +1 -0
  56. package/crud/contentModel/validateModel.d.ts +4 -4
  57. package/crud/contentModel/validateModel.js +6 -3
  58. package/crud/contentModel/validateModel.js.map +1 -1
  59. package/crud/contentModel/validateModelFields.d.ts +4 -4
  60. package/crud/contentModel/validateModelFields.js +123 -88
  61. package/crud/contentModel/validateModelFields.js.map +1 -1
  62. package/crud/contentModel/validation.d.ts +551 -0
  63. package/crud/contentModel/validation.js +145 -0
  64. package/crud/contentModel/validation.js.map +1 -0
  65. package/crud/contentModel.crud.js +369 -273
  66. package/crud/contentModel.crud.js.map +1 -1
  67. package/crud/contentModelGroup/validation.d.ts +30 -0
  68. package/crud/contentModelGroup/validation.js +34 -0
  69. package/crud/contentModelGroup/validation.js.map +1 -0
  70. package/crud/contentModelGroup.crud.js +189 -172
  71. package/crud/contentModelGroup.crud.js.map +1 -1
  72. package/crud/settings.crud.d.ts +1 -1
  73. package/crud/settings.crud.js +5 -10
  74. package/crud/settings.crud.js.map +1 -1
  75. package/crud/system.crud.js +0 -60
  76. package/crud/system.crud.js.map +1 -1
  77. package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.d.ts +11 -0
  78. package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js +203 -0
  79. package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js.map +1 -0
  80. package/fieldConverters/index.d.ts +2 -1
  81. package/fieldConverters/index.js +2 -1
  82. package/fieldConverters/index.js.map +1 -1
  83. package/graphql/buildSchemaPlugins.d.ts +8 -3
  84. package/graphql/buildSchemaPlugins.js +3 -7
  85. package/graphql/buildSchemaPlugins.js.map +1 -1
  86. package/graphql/checkEndpointAccess.d.ts +2 -0
  87. package/graphql/checkEndpointAccess.js +18 -0
  88. package/graphql/checkEndpointAccess.js.map +1 -0
  89. package/graphql/createExecutableSchema.d.ts +6 -0
  90. package/graphql/createExecutableSchema.js +29 -0
  91. package/graphql/createExecutableSchema.js.map +1 -0
  92. package/graphql/createRequestBody.d.ts +2 -0
  93. package/graphql/createRequestBody.js +14 -0
  94. package/graphql/createRequestBody.js.map +1 -0
  95. package/graphql/formatErrorPayload.d.ts +1 -0
  96. package/graphql/formatErrorPayload.js +25 -0
  97. package/graphql/formatErrorPayload.js.map +1 -0
  98. package/graphql/generateSchema.d.ts +8 -0
  99. package/graphql/generateSchema.js +31 -0
  100. package/graphql/generateSchema.js.map +1 -0
  101. package/graphql/getSchema.d.ts +17 -0
  102. package/graphql/getSchema.js +102 -0
  103. package/graphql/getSchema.js.map +1 -0
  104. package/graphql/graphQLHandlerFactory.js +6 -104
  105. package/graphql/graphQLHandlerFactory.js.map +1 -1
  106. package/graphql/handleRequest.d.ts +11 -0
  107. package/graphql/handleRequest.js +81 -0
  108. package/graphql/handleRequest.js.map +1 -0
  109. package/graphql/index.d.ts +1 -3
  110. package/graphql/index.js +2 -39
  111. package/graphql/index.js.map +1 -1
  112. package/graphql/schema/baseContentSchema.d.ts +6 -2
  113. package/graphql/schema/baseContentSchema.js +9 -11
  114. package/graphql/schema/baseContentSchema.js.map +1 -1
  115. package/graphql/schema/baseSchema.d.ts +3 -0
  116. package/graphql/schema/baseSchema.js +68 -0
  117. package/graphql/schema/baseSchema.js.map +1 -0
  118. package/graphql/schema/contentEntries.d.ts +6 -2
  119. package/graphql/schema/contentEntries.js +116 -65
  120. package/graphql/schema/contentEntries.js.map +1 -1
  121. package/graphql/schema/contentModelGroups.d.ts +6 -2
  122. package/graphql/schema/contentModelGroups.js +14 -10
  123. package/graphql/schema/contentModelGroups.js.map +1 -1
  124. package/graphql/schema/contentModels.d.ts +6 -2
  125. package/graphql/schema/contentModels.js +60 -8
  126. package/graphql/schema/contentModels.js.map +1 -1
  127. package/graphql/schema/createFieldResolvers.d.ts +2 -2
  128. package/graphql/schema/createFieldResolvers.js +18 -13
  129. package/graphql/schema/createFieldResolvers.js.map +1 -1
  130. package/graphql/schema/createFieldTypePluginRecords.d.ts +3 -0
  131. package/graphql/schema/createFieldTypePluginRecords.js +13 -0
  132. package/graphql/schema/createFieldTypePluginRecords.js.map +1 -0
  133. package/graphql/schema/createManageResolvers.d.ts +1 -1
  134. package/graphql/schema/createManageResolvers.js +37 -17
  135. package/graphql/schema/createManageResolvers.js.map +1 -1
  136. package/graphql/schema/createManageSDL.d.ts +3 -0
  137. package/graphql/schema/createManageSDL.js +81 -63
  138. package/graphql/schema/createManageSDL.js.map +1 -1
  139. package/graphql/schema/createPreviewResolvers.js +3 -7
  140. package/graphql/schema/createPreviewResolvers.js.map +1 -1
  141. package/graphql/schema/createReadResolvers.js +8 -7
  142. package/graphql/schema/createReadResolvers.js.map +1 -1
  143. package/graphql/schema/createReadSDL.d.ts +3 -0
  144. package/graphql/schema/createReadSDL.js +47 -36
  145. package/graphql/schema/createReadSDL.js.map +1 -1
  146. package/graphql/schema/resolvers/commonFieldResolvers.d.ts +3 -2
  147. package/graphql/schema/resolvers/commonFieldResolvers.js +2 -1
  148. package/graphql/schema/resolvers/commonFieldResolvers.js.map +1 -1
  149. package/graphql/schema/resolvers/manage/resolveDelete.d.ts +2 -1
  150. package/graphql/schema/resolvers/manage/resolveDelete.js +13 -3
  151. package/graphql/schema/resolvers/manage/resolveDelete.js.map +1 -1
  152. package/graphql/schema/resolvers/manage/resolveDeleteMultiple.d.ts +7 -0
  153. package/graphql/schema/resolvers/manage/resolveDeleteMultiple.js +20 -0
  154. package/graphql/schema/resolvers/manage/resolveDeleteMultiple.js.map +1 -0
  155. package/graphql/schema/resolvers/manage/resolveGetUniqueFieldValues.d.ts +4 -0
  156. package/graphql/schema/resolvers/manage/resolveGetUniqueFieldValues.js +18 -0
  157. package/graphql/schema/resolvers/manage/resolveGetUniqueFieldValues.js.map +1 -0
  158. package/graphql/schema/schemaPlugins.d.ts +8 -3
  159. package/graphql/schema/schemaPlugins.js +55 -52
  160. package/graphql/schema/schemaPlugins.js.map +1 -1
  161. package/graphql/system.js +55 -74
  162. package/graphql/system.js.map +1 -1
  163. package/graphqlFields/dynamicZone/dynamicZoneField.d.ts +2 -0
  164. package/graphqlFields/dynamicZone/dynamicZoneField.js +243 -0
  165. package/graphqlFields/dynamicZone/dynamicZoneField.js.map +1 -0
  166. package/graphqlFields/dynamicZone/dynamicZoneStorage.d.ts +3 -0
  167. package/graphqlFields/dynamicZone/dynamicZoneStorage.js +63 -0
  168. package/graphqlFields/dynamicZone/dynamicZoneStorage.js.map +1 -0
  169. package/graphqlFields/dynamicZone/index.d.ts +2 -0
  170. package/graphqlFields/dynamicZone/index.js +19 -0
  171. package/graphqlFields/dynamicZone/index.js.map +1 -0
  172. package/graphqlFields/index.d.ts +1 -1
  173. package/graphqlFields/index.js +2 -1
  174. package/graphqlFields/index.js.map +1 -1
  175. package/graphqlFields/number.js +4 -0
  176. package/graphqlFields/number.js.map +1 -1
  177. package/graphqlFields/object.js +131 -68
  178. package/graphqlFields/object.js.map +1 -1
  179. package/graphqlFields/ref.js +70 -56
  180. package/graphqlFields/ref.js.map +1 -1
  181. package/index.d.ts +5 -3
  182. package/index.js +27 -8
  183. package/index.js.map +1 -1
  184. package/package.json +40 -41
  185. package/plugins/CmsGraphQLSchemaPlugin.d.ts +5 -0
  186. package/plugins/CmsGraphQLSchemaPlugin.js +12 -0
  187. package/plugins/CmsGraphQLSchemaPlugin.js.map +1 -0
  188. package/plugins/CmsGraphQLSchemaSorterPlugin.d.ts +20 -0
  189. package/plugins/CmsGraphQLSchemaSorterPlugin.js +28 -0
  190. package/plugins/CmsGraphQLSchemaSorterPlugin.js.map +1 -0
  191. package/plugins/CmsModelFieldConverterPlugin.d.ts +2 -2
  192. package/plugins/CmsModelFieldConverterPlugin.js.map +1 -1
  193. package/plugins/CmsModelPlugin.d.ts +21 -3
  194. package/plugins/CmsModelPlugin.js +28 -2
  195. package/plugins/CmsModelPlugin.js.map +1 -1
  196. package/plugins/StorageOperationsCmsModelPlugin.d.ts +23 -0
  197. package/plugins/StorageOperationsCmsModelPlugin.js +42 -0
  198. package/plugins/StorageOperationsCmsModelPlugin.js.map +1 -0
  199. package/plugins/StorageTransformPlugin.d.ts +11 -11
  200. package/plugins/StorageTransformPlugin.js.map +1 -1
  201. package/plugins/index.d.ts +3 -0
  202. package/plugins/index.js +33 -0
  203. package/plugins/index.js.map +1 -1
  204. package/storage/object.js +4 -2
  205. package/storage/object.js.map +1 -1
  206. package/types.d.ts +436 -149
  207. package/types.js +74 -8
  208. package/types.js.map +1 -1
  209. package/utils/converters/ConverterCollection.js +5 -2
  210. package/utils/converters/ConverterCollection.js.map +1 -1
  211. package/utils/converters/valueKeyStorageConverter.d.ts +1 -5
  212. package/utils/converters/valueKeyStorageConverter.js +26 -20
  213. package/utils/converters/valueKeyStorageConverter.js.map +1 -1
  214. package/utils/createTypeFromFields.d.ts +16 -0
  215. package/utils/createTypeFromFields.js +66 -0
  216. package/utils/createTypeFromFields.js.map +1 -0
  217. package/utils/createTypeName.d.ts +0 -2
  218. package/utils/createTypeName.js +4 -11
  219. package/utils/createTypeName.js.map +1 -1
  220. package/utils/entryStorage.js +14 -11
  221. package/utils/entryStorage.js.map +1 -1
  222. package/utils/getBaseFieldType.d.ts +2 -0
  223. package/utils/getBaseFieldType.js +10 -0
  224. package/utils/getBaseFieldType.js.map +1 -0
  225. package/utils/getEntryDescription.d.ts +2 -0
  226. package/utils/getEntryDescription.js +17 -0
  227. package/utils/getEntryDescription.js.map +1 -0
  228. package/utils/getEntryImage.d.ts +2 -0
  229. package/utils/getEntryImage.js +17 -0
  230. package/utils/getEntryImage.js.map +1 -0
  231. package/utils/getEntryTitle.d.ts +1 -1
  232. package/utils/getEntryTitle.js.map +1 -1
  233. package/utils/getSchemaFromFieldPlugins.d.ts +4 -7
  234. package/utils/getSchemaFromFieldPlugins.js +22 -14
  235. package/utils/getSchemaFromFieldPlugins.js.map +1 -1
  236. package/utils/incrementEntryIdVersion.d.ts +5 -0
  237. package/utils/incrementEntryIdVersion.js +29 -0
  238. package/utils/incrementEntryIdVersion.js.map +1 -0
  239. package/utils/ownership.d.ts +3 -3
  240. package/utils/ownership.js.map +1 -1
  241. package/utils/renderFields.d.ts +4 -2
  242. package/utils/renderFields.js +12 -3
  243. package/utils/renderFields.js.map +1 -1
  244. package/utils/renderGetFilterFields.d.ts +2 -2
  245. package/utils/renderGetFilterFields.js +9 -19
  246. package/utils/renderGetFilterFields.js.map +1 -1
  247. package/utils/renderInputFields.d.ts +4 -2
  248. package/utils/renderInputFields.js +19 -6
  249. package/utils/renderInputFields.js.map +1 -1
  250. package/utils/renderListFilterFields.d.ts +2 -1
  251. package/utils/renderListFilterFields.js +12 -21
  252. package/utils/renderListFilterFields.js.map +1 -1
  253. package/utils/renderSortEnum.d.ts +9 -5
  254. package/utils/renderSortEnum.js +23 -5
  255. package/utils/renderSortEnum.js.map +1 -1
  256. package/validators/dynamicZone.d.ts +2 -0
  257. package/validators/dynamicZone.js +20 -0
  258. package/validators/dynamicZone.js.map +1 -0
  259. package/validators/index.js +2 -1
  260. package/validators/index.js.map +1 -1
  261. package/crud/contentModel/createFieldModels.d.ts +0 -2
  262. package/crud/contentModel/createFieldModels.js +0 -20
  263. package/crud/contentModel/createFieldModels.js.map +0 -1
  264. package/crud/contentModel/fieldIdValidation.d.ts +0 -1
  265. package/crud/contentModel/fieldIdValidation.js +0 -20
  266. package/crud/contentModel/fieldIdValidation.js.map +0 -1
  267. package/crud/contentModel/idValidation.d.ts +0 -1
  268. package/crud/contentModel/idValidation.js +0 -17
  269. package/crud/contentModel/idValidation.js.map +0 -1
  270. package/crud/contentModel/models.d.ts +0 -4
  271. package/crud/contentModel/models.js +0 -173
  272. package/crud/contentModel/models.js.map +0 -1
  273. package/crud/contentModel/systemFields.d.ts +0 -1
  274. package/crud/contentModel/systemFields.js +0 -8
  275. package/crud/contentModel/systemFields.js.map +0 -1
  276. package/crud/index.d.ts +0 -6
  277. package/crud/index.js +0 -69
  278. package/crud/index.js.map +0 -1
  279. package/graphql/schema/resolvers/manage/resolveRequestChanges.d.ts +0 -7
  280. package/graphql/schema/resolvers/manage/resolveRequestChanges.js +0 -21
  281. package/graphql/schema/resolvers/manage/resolveRequestChanges.js.map +0 -1
  282. package/graphql/schema/resolvers/manage/resolveRequestReview.d.ts +0 -7
  283. package/graphql/schema/resolvers/manage/resolveRequestReview.js +0 -21
  284. package/graphql/schema/resolvers/manage/resolveRequestReview.js.map +0 -1
  285. package/upgrades/5.33.0/index.d.ts +0 -3
  286. package/upgrades/5.33.0/index.js +0 -159
  287. package/upgrades/5.33.0/index.js.map +0 -1
  288. package/upgrades/index.d.ts +0 -1
  289. package/upgrades/index.js +0 -9
  290. package/upgrades/index.js.map +0 -1
  291. package/utils/filterModelFields.d.ts +0 -16
  292. package/utils/filterModelFields.js +0 -71
  293. package/utils/filterModelFields.js.map +0 -1
  294. package/utils/pluralizedTypeName.d.ts +0 -1
  295. package/utils/pluralizedTypeName.js +0 -20
  296. package/utils/pluralizedTypeName.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"names":["generateSchema","params","context","models","generatedSchemaPlugins","buildSchemaPlugins","ex","console","log","plugins","register","schemaPlugins","byType","CmsGraphQLSchemaPlugin","type","createExecutableSchema"],"sources":["generateSchema.ts"],"sourcesContent":["import { CmsContext, CmsModel } from \"~/types\";\nimport { buildSchemaPlugins } from \"./buildSchemaPlugins\";\nimport { createExecutableSchema } from \"./createExecutableSchema\";\nimport { GraphQLSchema } from \"graphql/type\";\nimport { CmsGraphQLSchemaPlugin } from \"~/plugins\";\n\ninterface GenerateSchemaParams {\n context: CmsContext;\n models: CmsModel[];\n}\nexport const generateSchema = async (params: GenerateSchemaParams): Promise<GraphQLSchema> => {\n const { context, models } = params;\n\n let generatedSchemaPlugins: CmsGraphQLSchemaPlugin[] = [];\n try {\n generatedSchemaPlugins = await buildSchemaPlugins({ context, models });\n } catch (ex) {\n console.log(`Error while building schema plugins.`);\n throw ex;\n }\n\n context.plugins.register(generatedSchemaPlugins);\n\n const schemaPlugins = context.plugins.byType<CmsGraphQLSchemaPlugin>(\n CmsGraphQLSchemaPlugin.type\n );\n return createExecutableSchema({\n plugins: schemaPlugins\n });\n};\n"],"mappings":";;;;;;AACA;AACA;AAEA;AAMO,MAAMA,cAAc,GAAG,MAAOC,MAA4B,IAA6B;EAC1F,MAAM;IAAEC,OAAO;IAAEC;EAAO,CAAC,GAAGF,MAAM;EAElC,IAAIG,sBAAgD,GAAG,EAAE;EACzD,IAAI;IACAA,sBAAsB,GAAG,MAAM,IAAAC,sCAAkB,EAAC;MAAEH,OAAO;MAAEC;IAAO,CAAC,CAAC;EAC1E,CAAC,CAAC,OAAOG,EAAE,EAAE;IACTC,OAAO,CAACC,GAAG,CAAE,sCAAqC,CAAC;IACnD,MAAMF,EAAE;EACZ;EAEAJ,OAAO,CAACO,OAAO,CAACC,QAAQ,CAACN,sBAAsB,CAAC;EAEhD,MAAMO,aAAa,GAAGT,OAAO,CAACO,OAAO,CAACG,MAAM,CACxCC,+BAAsB,CAACC,IAAI,CAC9B;EACD,OAAO,IAAAC,8CAAsB,EAAC;IAC1BN,OAAO,EAAEE;EACb,CAAC,CAAC;AACN,CAAC;AAAC"}
@@ -0,0 +1,17 @@
1
+ import { ApiEndpoint, CmsContext } from "../types";
2
+ import { Tenant } from "@webiny/api-tenancy/types";
3
+ import { I18NLocale } from "@webiny/api-i18n/types";
4
+ import { GraphQLSchema } from "graphql";
5
+ interface GetSchemaParams {
6
+ context: CmsContext;
7
+ type: ApiEndpoint;
8
+ getLastModifiedTime: () => Promise<Date | null>;
9
+ getTenant: () => Tenant;
10
+ getLocale: () => I18NLocale;
11
+ }
12
+ /**
13
+ * Gets an existing schema or rewrites existing one or creates a completely new one
14
+ * depending on the schemaId created from type and locale parameters
15
+ */
16
+ export declare const getSchema: (params: GetSchemaParams) => Promise<GraphQLSchema>;
17
+ export {};
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.getSchema = void 0;
8
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
+ var _codeFrame = _interopRequireDefault(require("code-frame"));
10
+ var _error = _interopRequireDefault(require("@webiny/error"));
11
+ var _generateSchema = require("./generateSchema");
12
+ // @ts-ignore `code-frame` has no types
13
+
14
+ const schemaList = new Map();
15
+
16
+ /**
17
+ * Method generates cache ID based on:
18
+ * - tenant
19
+ * - endpoint type
20
+ * - locale
21
+ */
22
+
23
+ const generateCacheId = params => {
24
+ const {
25
+ getTenant,
26
+ type,
27
+ getLocale
28
+ } = params;
29
+ return [`tenant:${getTenant().id}`, `endpoint:${type}`, `locale:${getLocale().code}`].join("#");
30
+ };
31
+ /**
32
+ * Method generates cache key based on last model change time.
33
+ * Or sets "unknown" - possible when no models in database.
34
+ */
35
+
36
+ const generateCacheKey = async params => {
37
+ const {
38
+ getLastModifiedTime
39
+ } = params;
40
+ const lastModelChange = await getLastModifiedTime();
41
+ if (!lastModelChange) {
42
+ return "unknown";
43
+ }
44
+ return lastModelChange.toISOString();
45
+ };
46
+
47
+ /**
48
+ * Gets an existing schema or rewrites existing one or creates a completely new one
49
+ * depending on the schemaId created from type and locale parameters
50
+ */
51
+ const getSchema = async params => {
52
+ const {
53
+ context
54
+ } = params;
55
+ const cacheId = generateCacheId(params);
56
+ const cacheKey = await generateCacheKey(params);
57
+ const cachedSchema = schemaList.get(cacheId);
58
+ if ((cachedSchema === null || cachedSchema === void 0 ? void 0 : cachedSchema.key) === cacheKey) {
59
+ return cachedSchema.schema;
60
+ }
61
+
62
+ /**
63
+ * We need all the API models.
64
+ * Private models are hidden in the GraphQL, so filter them out.
65
+ */
66
+ const models = await context.security.withoutAuthorization(async () => {
67
+ return (await context.cms.listModels()).filter(model => {
68
+ return model.isPrivate !== true;
69
+ });
70
+ });
71
+ try {
72
+ const schema = await (0, _generateSchema.generateSchema)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
73
+ models
74
+ }));
75
+ schemaList.set(cacheId, {
76
+ key: cacheKey,
77
+ schema
78
+ });
79
+ return schema;
80
+ } catch (err) {
81
+ if (!Array.isArray(err.locations)) {
82
+ throw new _error.default({
83
+ message: err.message,
84
+ code: err.code || "INVALID_GRAPHQL_SCHEMA_LOCATIONS",
85
+ data: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, err.data || {}), {}, {
86
+ locations: err.locations
87
+ })
88
+ });
89
+ }
90
+ const [location] = err.locations;
91
+ throw new _error.default({
92
+ code: "INVALID_GRAPHQL_SCHEMA",
93
+ message: err.message,
94
+ data: {
95
+ invalidSegment: (0, _codeFrame.default)(err.source.body, location.line, location.column, {
96
+ frameSize: 15
97
+ })
98
+ }
99
+ });
100
+ }
101
+ };
102
+ exports.getSchema = getSchema;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["schemaList","Map","generateCacheId","params","getTenant","type","getLocale","id","code","join","generateCacheKey","getLastModifiedTime","lastModelChange","toISOString","getSchema","context","cacheId","cacheKey","cachedSchema","get","key","schema","models","security","withoutAuthorization","cms","listModels","filter","model","isPrivate","generateSchema","set","err","Array","isArray","locations","WebinyError","message","data","location","invalidSegment","codeFrame","source","body","line","column","frameSize"],"sources":["getSchema.ts"],"sourcesContent":["// @ts-ignore `code-frame` has no types\nimport codeFrame from \"code-frame\";\nimport WebinyError from \"@webiny/error\";\nimport { generateSchema } from \"./generateSchema\";\nimport { ApiEndpoint, CmsContext } from \"~/types\";\nimport { Tenant } from \"@webiny/api-tenancy/types\";\nimport { I18NLocale } from \"@webiny/api-i18n/types\";\nimport { GraphQLSchema } from \"graphql\";\n\ninterface SchemaCache {\n key: string;\n schema: GraphQLSchema;\n}\n\ninterface GetSchemaParams {\n context: CmsContext;\n type: ApiEndpoint;\n getLastModifiedTime: () => Promise<Date | null>;\n getTenant: () => Tenant;\n getLocale: () => I18NLocale;\n}\n\nconst schemaList = new Map<string, SchemaCache>();\n\n/**\n * Method generates cache ID based on:\n * - tenant\n * - endpoint type\n * - locale\n */\ntype GenerateCacheIdParams = Pick<GetSchemaParams, \"getTenant\" | \"getLocale\" | \"type\">;\nconst generateCacheId = (params: GenerateCacheIdParams): string => {\n const { getTenant, type, getLocale } = params;\n return [`tenant:${getTenant().id}`, `endpoint:${type}`, `locale:${getLocale().code}`].join(\"#\");\n};\n/**\n * Method generates cache key based on last model change time.\n * Or sets \"unknown\" - possible when no models in database.\n */\ntype GenerateCacheKeyParams = Pick<GetSchemaParams, \"getLastModifiedTime\">;\nconst generateCacheKey = async (params: GenerateCacheKeyParams): Promise<string> => {\n const { getLastModifiedTime } = params;\n const lastModelChange = await getLastModifiedTime();\n if (!lastModelChange) {\n return \"unknown\";\n }\n return lastModelChange.toISOString();\n};\n\n/**\n * Gets an existing schema or rewrites existing one or creates a completely new one\n * depending on the schemaId created from type and locale parameters\n */\nexport const getSchema = async (params: GetSchemaParams): Promise<GraphQLSchema> => {\n const { context } = params;\n\n const cacheId = generateCacheId(params);\n\n const cacheKey = await generateCacheKey(params);\n const cachedSchema = schemaList.get(cacheId);\n if (cachedSchema?.key === cacheKey) {\n return cachedSchema.schema;\n }\n\n /**\n * We need all the API models.\n * Private models are hidden in the GraphQL, so filter them out.\n */\n const models = await context.security.withoutAuthorization(async () => {\n return (await context.cms.listModels()).filter(model => {\n return model.isPrivate !== true;\n });\n });\n try {\n const schema = await generateSchema({\n ...params,\n models\n });\n schemaList.set(cacheId, {\n key: cacheKey,\n schema\n });\n return schema;\n } catch (err) {\n if (!Array.isArray(err.locations)) {\n throw new WebinyError({\n message: err.message,\n code: err.code || \"INVALID_GRAPHQL_SCHEMA_LOCATIONS\",\n data: {\n ...(err.data || {}),\n locations: err.locations\n }\n });\n }\n const [location] = err.locations;\n\n throw new WebinyError({\n code: \"INVALID_GRAPHQL_SCHEMA\",\n message: err.message,\n data: {\n invalidSegment: codeFrame(err.source.body, location.line, location.column, {\n frameSize: 15\n })\n }\n });\n }\n};\n"],"mappings":";;;;;;;;AACA;AACA;AACA;AAHA;;AAsBA,MAAMA,UAAU,GAAG,IAAIC,GAAG,EAAuB;;AAEjD;AACA;AACA;AACA;AACA;AACA;;AAEA,MAAMC,eAAe,GAAIC,MAA6B,IAAa;EAC/D,MAAM;IAAEC,SAAS;IAAEC,IAAI;IAAEC;EAAU,CAAC,GAAGH,MAAM;EAC7C,OAAO,CAAE,UAASC,SAAS,EAAE,CAACG,EAAG,EAAC,EAAG,YAAWF,IAAK,EAAC,EAAG,UAASC,SAAS,EAAE,CAACE,IAAK,EAAC,CAAC,CAACC,IAAI,CAAC,GAAG,CAAC;AACnG,CAAC;AACD;AACA;AACA;AACA;;AAEA,MAAMC,gBAAgB,GAAG,MAAOP,MAA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cAAW,CAAC;QAClBC,OAAO,EAAEL,GAAG,CAACK,OAAO;QACpB7B,IAAI,EAAEwB,GAAG,CAACxB,IAAI,IAAI,kCAAkC;QACpD8B,IAAI,8DACIN,GAAG,CAACM,IAAI,IAAI,CAAC,CAAC;UAClBH,SAAS,EAAEH,GAAG,CAACG;QAAS;MAEhC,CAAC,CAAC;IACN;IACA,MAAM,CAACI,QAAQ,CAAC,GAAGP,GAAG,CAACG,SAAS;IAEhC,MAAM,IAAIC,cAAW,CAAC;MAClB5B,IAAI,EAAE,wBAAwB;MAC9B6B,OAAO,EAAEL,GAAG,CAACK,OAAO;MACpBC,IAAI,EAAE;QACFE,cAAc,EAAE,IAAAC,kBAAS,EAACT,GAAG,CAACU,MAAM,CAACC,IAAI,EAAEJ,QAAQ,CAACK,IAAI,EAAEL,QAAQ,CAACM,MAAM,EAAE;UACvEC,SAAS,EAAE;QACf,CAAC;MACL;IACJ,CAAC,CAAC;EACN;AACJ,CAAC;AAAC"}
@@ -5,124 +5,26 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.graphQLHandlerFactory = void 0;
8
- var _schema = require("@graphql-tools/schema");
9
- var _apiSecurity = require("@webiny/api-security");
10
8
  var _debugPlugins = _interopRequireDefault(require("@webiny/handler-graphql/debugPlugins"));
11
- var _processRequestBody = _interopRequireDefault(require("@webiny/handler-graphql/processRequestBody"));
12
- var _buildSchemaPlugins = require("./buildSchemaPlugins");
13
- var _plugins = require("@webiny/handler-graphql/plugins");
14
9
  var _handler = require("@webiny/handler");
15
- const schemaList = new Map();
16
- const generateCacheKey = async args => {
17
- const {
18
- context,
19
- locale,
20
- type
21
- } = args;
22
- const lastModelChange = await context.cms.getModelLastChange();
23
- return [locale.code, type, lastModelChange.toISOString()].join("#");
24
- };
25
- const generateSchema = async args => {
26
- const {
27
- context
28
- } = args;
29
- context.plugins.register(await (0, _buildSchemaPlugins.buildSchemaPlugins)(context));
30
- /**
31
- * Really hard to type this to satisfy the makeExecutableSchema
32
- */
33
- // TODO @ts-refactor
34
- const typeDefs = [];
35
- const resolvers = [];
36
-
37
- // Get schema definitions from plugins
38
- const schemaPlugins = context.plugins.byType(_plugins.GraphQLSchemaPlugin.type);
39
- for (const pl of schemaPlugins) {
40
- typeDefs.push(pl.schema.typeDefs);
41
- resolvers.push(pl.schema.resolvers);
42
- }
43
- return (0, _schema.makeExecutableSchema)({
44
- typeDefs,
45
- resolvers
46
- });
47
- };
48
-
49
- /**
50
- * Gets an existing schema or rewrites existing one or creates a completely new one
51
- * depending on the schemaId created from type and locale parameters
52
- */
53
- const getSchema = async params => {
54
- const {
55
- context,
56
- type,
57
- locale
58
- } = params;
59
- const tenantId = context.tenancy.getCurrentTenant().id;
60
- const id = `${tenantId}#${type}#${locale.code}`;
61
- const cacheKey = await generateCacheKey(params);
62
- if (!schemaList.has(id)) {
63
- const schema = await generateSchema(params);
64
- schemaList.set(id, {
65
- key: cacheKey,
66
- schema
67
- });
68
- return schema;
69
- }
70
- /**
71
- * Safe to cast because check was done few lines up.
72
- */
73
- const cache = schemaList.get(id);
74
- if (cache.key === cacheKey) {
75
- return cache.schema;
76
- }
77
- const schema = await generateSchema(params);
78
- schemaList.set(id, {
79
- key: cacheKey,
80
- schema
81
- });
82
- return schema;
83
- };
84
- const checkEndpointAccess = async context => {
85
- const permission = await context.security.getPermission(`cms.endpoint.${context.cms.type}`);
86
- if (!permission) {
87
- throw new _apiSecurity.NotAuthorizedError({
88
- data: {
89
- reason: `Not allowed to access "${context.cms.type}" endpoint.`
90
- }
91
- });
92
- }
93
- };
10
+ var _handleRequest = require("./handleRequest");
94
11
  const cmsRoutes = new _handler.RoutePlugin(({
95
12
  onPost,
96
13
  onOptions,
97
14
  context
98
15
  }) => {
99
16
  onPost("/cms/:type(^manage|preview|read$)/:locale", async (request, reply) => {
100
- try {
101
- await checkEndpointAccess(context);
102
- } catch (ex) {
103
- return reply.code(401).send({
104
- data: null,
105
- error: {
106
- message: ex.message || "Not authorized!",
107
- code: ex.code || "SECURITY_NOT_AUTHORIZED",
108
- data: ex.data || null,
109
- stack: null
110
- }
111
- });
112
- }
113
- const schema = await getSchema({
17
+ return (0, _handleRequest.handleRequest)({
114
18
  context,
115
- locale: context.cms.getLocale(),
116
- type: context.cms.type
19
+ request,
20
+ reply
117
21
  });
118
- const body = request.body;
119
- const result = await (0, _processRequestBody.default)(body, schema, context);
120
- return reply.code(200).send(result);
121
22
  });
122
23
  onOptions("/cms/:type(^manage|preview|read$)/:locale", async (_, reply) => {
123
- return reply.hijack().send({});
24
+ return reply.status(204).send({}).hijack();
124
25
  });
125
26
  });
27
+ cmsRoutes.name = "headless-cms.graphql.route.default";
126
28
  const graphQLHandlerFactory = ({
127
29
  debug
128
30
  }) => {
@@ -1 +1 @@
1
- {"version":3,"names":["schemaList","Map","generateCacheKey","args","context","locale","type","lastModelChange","cms","getModelLastChange","code","toISOString","join","generateSchema","plugins","register","buildSchemaPlugins","typeDefs","resolvers","schemaPlugins","byType","GraphQLSchemaPlugin","pl","push","schema","makeExecutableSchema","getSchema","params","tenantId","tenancy","getCurrentTenant","id","cacheKey","has","set","key","cache","get","checkEndpointAccess","permission","security","getPermission","NotAuthorizedError","data","reason","cmsRoutes","RoutePlugin","onPost","onOptions","request","reply","ex","send","error","message","stack","getLocale","body","result","processRequestBody","_","hijack","graphQLHandlerFactory","debug","debugPlugins"],"sources":["graphQLHandlerFactory.ts"],"sourcesContent":["import { GraphQLSchema } from \"graphql\";\nimport { makeExecutableSchema } from \"@graphql-tools/schema\";\nimport { ApiEndpoint, CmsContext } from \"~/types\";\nimport { I18NLocale } from \"@webiny/api-i18n/types\";\nimport { NotAuthorizedError } from \"@webiny/api-security\";\nimport { PluginCollection } from \"@webiny/plugins/types\";\nimport debugPlugins from \"@webiny/handler-graphql/debugPlugins\";\nimport processRequestBody from \"@webiny/handler-graphql/processRequestBody\";\nimport { buildSchemaPlugins } from \"./buildSchemaPlugins\";\nimport { GraphQLSchemaPlugin } from \"@webiny/handler-graphql/plugins\";\nimport { GraphQLRequestBody } from \"@webiny/handler-graphql/types\";\nimport { RoutePlugin } from \"@webiny/handler\";\n\ninterface SchemaCache {\n key: string;\n schema: GraphQLSchema;\n}\ninterface GetSchemaParams {\n context: CmsContext;\n type: ApiEndpoint;\n locale: I18NLocale;\n}\n\nconst schemaList = new Map<string, SchemaCache>();\n\nconst generateCacheKey = async (args: GetSchemaParams): Promise<string> => {\n const { context, locale, type } = args;\n const lastModelChange = await context.cms.getModelLastChange();\n return [locale.code, type, lastModelChange.toISOString()].join(\"#\");\n};\n\nconst generateSchema = async (args: GetSchemaParams): Promise<GraphQLSchema> => {\n const { context } = args;\n\n context.plugins.register(await buildSchemaPlugins(context));\n /**\n * Really hard to type this to satisfy the makeExecutableSchema\n */\n // TODO @ts-refactor\n const typeDefs: any = [];\n const resolvers: any = [];\n\n // Get schema definitions from plugins\n const schemaPlugins = context.plugins.byType<GraphQLSchemaPlugin>(GraphQLSchemaPlugin.type);\n for (const pl of schemaPlugins) {\n typeDefs.push(pl.schema.typeDefs);\n resolvers.push(pl.schema.resolvers);\n }\n\n return makeExecutableSchema({\n typeDefs,\n resolvers\n });\n};\n\n/**\n * Gets an existing schema or rewrites existing one or creates a completely new one\n * depending on the schemaId created from type and locale parameters\n */\nconst getSchema = async (params: GetSchemaParams): Promise<GraphQLSchema> => {\n const { context, type, locale } = params;\n const tenantId = context.tenancy.getCurrentTenant().id;\n const id = `${tenantId}#${type}#${locale.code}`;\n\n const cacheKey = await generateCacheKey(params);\n if (!schemaList.has(id)) {\n const schema = await generateSchema(params);\n\n schemaList.set(id, {\n key: cacheKey,\n schema\n });\n return schema;\n }\n /**\n * Safe to cast because check was done few lines up.\n */\n const cache = schemaList.get(id) as SchemaCache;\n if (cache.key === cacheKey) {\n return cache.schema;\n }\n const schema = await generateSchema(params);\n schemaList.set(id, {\n key: cacheKey,\n schema\n });\n return schema;\n};\n\nconst checkEndpointAccess = async (context: CmsContext): Promise<void> => {\n const permission = await context.security.getPermission(`cms.endpoint.${context.cms.type}`);\n if (!permission) {\n throw new NotAuthorizedError({\n data: {\n reason: `Not allowed to access \"${context.cms.type}\" endpoint.`\n }\n });\n }\n};\n\nexport interface GraphQLHandlerFactoryParams {\n debug?: boolean;\n}\n\nconst cmsRoutes = new RoutePlugin<CmsContext>(({ onPost, onOptions, context }) => {\n onPost(\"/cms/:type(^manage|preview|read$)/:locale\", async (request, reply) => {\n try {\n await checkEndpointAccess(context);\n } catch (ex) {\n return reply.code(401).send({\n data: null,\n error: {\n message: ex.message || \"Not authorized!\",\n code: ex.code || \"SECURITY_NOT_AUTHORIZED\",\n data: ex.data || null,\n stack: null\n }\n });\n }\n\n const schema = await getSchema({\n context,\n locale: context.cms.getLocale(),\n type: context.cms.type as ApiEndpoint\n });\n const body: GraphQLRequestBody | GraphQLRequestBody[] = request.body as any;\n const result = await processRequestBody(body, schema, context);\n return reply.code(200).send(result);\n });\n\n onOptions(\"/cms/:type(^manage|preview|read$)/:locale\", async (_, reply) => {\n return reply.hijack().send({});\n });\n});\n\nexport const graphQLHandlerFactory = ({ debug }: GraphQLHandlerFactoryParams): PluginCollection => {\n return [\n ...(debug ? debugPlugins() : []),\n cmsRoutes,\n {\n type: \"wcp-telemetry-tracker\"\n }\n ];\n};\n"],"mappings":";;;;;;;AACA;AAGA;AAEA;AACA;AACA;AACA;AAEA;AAYA,MAAMA,UAAU,GAAG,IAAIC,GAAG,EAAuB;AAEjD,MAAMC,gBAAgB,GAAG,MAAOC,IAAqB,IAAsB;EACvE,MAAM;IAAEC,OAAO;IAAEC,MAAM;IAAEC;EAAK,CAAC,GAAGH,IAAI;EACtC,MAAMI,eAAe,GAAG,MAAMH,OAAO,CAACI,GAAG,CAACC,kBAAkB,EAAE;EAC9D,OAAO,CAACJ,MAAM,CAACK,IAAI,EAAEJ,IAAI,EAAEC,eAAe,CAACI,WAAW,EAAE,CAAC,CAACC,IAAI,CAAC,GAAG,CAAC;AACvE,CAAC;AAED,MAAMC,c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,EAAE,CAACR,IAAI,IAAI,IAAI;UACrBY,KAAK,EAAE;QACX;MACJ,CAAC,CAAC;IACN;IAEA,MAAM/B,MAAM,GAAG,MAAME,SAAS,CAAC;MAC3BtB,OAAO;MACPC,MAAM,EAAED,OAAO,CAACI,GAAG,CAACgD,SAAS,EAAE;MAC/BlD,IAAI,EAAEF,OAAO,CAACI,GAAG,CAACF;IACtB,CAAC,CAAC;IACF,MAAMmD,IAA+C,GAAGR,OAAO,CAACQ,IAAW;IAC3E,MAAMC,MAAM,GAAG,MAAM,IAAAC,2BAAkB,EAACF,IAAI,EAAEjC,MAAM,EAAEpB,OAAO,CAAC;IAC9D,OAAO8C,KAAK,CAACxC,IAAI,CAAC,GAAG,CAAC,CAAC0C,IAAI,CAACM,MAAM,CAAC;EACvC,CAAC,CAAC;EAEFV,SAAS,CAAC,2CAA2C,EAAE,OAAOY,CAAC,EAAEV,KAAK,KAAK;IACvE,OAAOA,KAAK,CAACW,MAAM,EAAE,CAACT,IAAI,CAAC,CAAC,CAAC,CAAC;EAClC,CAAC,CAAC;AACN,CAAC,CAAC;AAEK,MAAMU,qBAAqB,GAAG,CAAC;EAAEC;AAAmC,CAAC,KAAuB;EAC/F,OAAO,CACH,IAAIA,KAAK,GAAG,IAAAC,qBAAY,GAAE,GAAG,EAAE,CAAC,EAChCnB,SAAS,EACT;IACIvC,IAAI,EAAE;EACV,CAAC,CACJ;AACL,CAAC;AAAC"}
1
+ {"version":3,"names":["cmsRoutes","RoutePlugin","onPost","onOptions","context","request","reply","handleRequest","_","status","send","hijack","name","graphQLHandlerFactory","debug","debugPlugins","type"],"sources":["graphQLHandlerFactory.ts"],"sourcesContent":["import debugPlugins from \"@webiny/handler-graphql/debugPlugins\";\nimport { CmsContext } from \"~/types\";\nimport { PluginCollection } from \"@webiny/plugins/types\";\nimport { RoutePlugin } from \"@webiny/handler\";\nimport { handleRequest } from \"./handleRequest\";\n\nexport interface GraphQLHandlerFactoryParams {\n debug?: boolean;\n}\n\nconst cmsRoutes = new RoutePlugin<CmsContext>(({ onPost, onOptions, context }) => {\n onPost(\"/cms/:type(^manage|preview|read$)/:locale\", async (request, reply) => {\n return handleRequest({ context, request, reply });\n });\n\n onOptions(\"/cms/:type(^manage|preview|read$)/:locale\", async (_, reply) => {\n return reply.status(204).send({}).hijack();\n });\n});\n\ncmsRoutes.name = \"headless-cms.graphql.route.default\";\n\nexport const graphQLHandlerFactory = ({ debug }: GraphQLHandlerFactoryParams): PluginCollection => {\n return [\n ...(debug ? debugPlugins() : []),\n cmsRoutes,\n {\n type: \"wcp-telemetry-tracker\"\n }\n ];\n};\n"],"mappings":";;;;;;;AAAA;AAGA;AACA;AAMA,MAAMA,SAAS,GAAG,IAAIC,oBAAW,CAAa,CAAC;EAAEC,MAAM;EAAEC,SAAS;EAAEC;AAAQ,CAAC,KAAK;EAC9EF,MAAM,CAAC,2CAA2C,EAAE,OAAOG,OAAO,EAAEC,KAAK,KAAK;IAC1E,OAAO,IAAAC,4BAAa,EAAC;MAAEH,OAAO;MAAEC,OAAO;MAAEC;IAAM,CAAC,CAAC;EACrD,CAAC,CAAC;EAEFH,SAAS,CAAC,2CAA2C,EAAE,OAAOK,CAAC,EAAEF,KAAK,KAAK;IACvE,OAAOA,KAAK,CAACG,MAAM,CAAC,GAAG,CAAC,CAACC,IAAI,CAAC,CAAC,CAAC,CAAC,CAACC,MAAM,EAAE;EAC9C,CAAC,CAAC;AACN,CAAC,CAAC;AAEFX,SAAS,CAACY,IAAI,GAAG,oCAAoC;AAE9C,MAAMC,qBAAqB,GAAG,CAAC;EAAEC;AAAmC,CAAC,KAAuB;EAC/F,OAAO,CACH,IAAIA,KAAK,GAAG,IAAAC,qBAAY,GAAE,GAAG,EAAE,CAAC,EAChCf,SAAS,EACT;IACIgB,IAAI,EAAE;EACV,CAAC,CACJ;AACL,CAAC;AAAC"}
@@ -0,0 +1,11 @@
1
+ import { CmsContext } from "../types";
2
+ import { Reply, Request } from "@webiny/handler/types";
3
+ export interface HandleRequestParams {
4
+ context: CmsContext;
5
+ request: Request;
6
+ reply: Reply;
7
+ }
8
+ export interface HandleRequest {
9
+ (params: HandleRequestParams): Promise<Reply>;
10
+ }
11
+ export declare const handleRequest: HandleRequest;
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.handleRequest = void 0;
7
+ var _checkEndpointAccess = require("./checkEndpointAccess");
8
+ var _createRequestBody = require("./createRequestBody");
9
+ var _formatErrorPayload = require("./formatErrorPayload");
10
+ var _getSchema = require("./getSchema");
11
+ var _handlerGraphql = require("@webiny/handler-graphql");
12
+ const handleRequest = async params => {
13
+ const {
14
+ context,
15
+ request,
16
+ reply
17
+ } = params;
18
+ try {
19
+ await (0, _checkEndpointAccess.checkEndpointAccess)(context);
20
+ } catch (ex) {
21
+ return reply.code(401).send({
22
+ data: null,
23
+ error: {
24
+ message: ex.message || "Not authorized!",
25
+ code: ex.code || "SECURITY_NOT_AUTHORIZED",
26
+ data: ex.data || null,
27
+ stack: null
28
+ }
29
+ });
30
+ }
31
+ const getTenant = () => {
32
+ return context.tenancy.getCurrentTenant();
33
+ };
34
+ const getLocale = () => {
35
+ return context.cms.getLocale();
36
+ };
37
+ const getLastModifiedTime = async () => {
38
+ return context.cms.getModelLastChange();
39
+ };
40
+ const schema = await context.benchmark.measure("headlessCms.graphql.getSchema", async () => {
41
+ try {
42
+ return await (0, _getSchema.getSchema)({
43
+ context,
44
+ getTenant,
45
+ getLastModifiedTime,
46
+ getLocale,
47
+ type: context.cms.type
48
+ });
49
+ } catch (ex) {
50
+ console.error(`Error while generating the schema.`);
51
+ console.error((0, _formatErrorPayload.formatErrorPayload)(ex));
52
+ throw ex;
53
+ }
54
+ });
55
+ const body = await context.benchmark.measure("headlessCms.graphql.createRequestBody", async () => {
56
+ try {
57
+ return (0, _createRequestBody.createRequestBody)(request.body);
58
+ } catch (ex) {
59
+ console.error(`Error while creating the body request.`);
60
+ console.error((0, _formatErrorPayload.formatErrorPayload)(ex));
61
+ throw ex;
62
+ }
63
+ });
64
+
65
+ /**
66
+ * We need to store the processRequestBody result in a variable and output it after the measurement.
67
+ * Otherwise, the measurement will not be shown in the output.
68
+ */
69
+ let result = null;
70
+ await context.benchmark.measure("headlessCms.graphql.processRequestBody", async () => {
71
+ try {
72
+ result = await (0, _handlerGraphql.processRequestBody)(body, schema, context);
73
+ } catch (ex) {
74
+ console.error(`Error while processing the body request.`);
75
+ console.error((0, _formatErrorPayload.formatErrorPayload)(ex));
76
+ throw ex;
77
+ }
78
+ });
79
+ return reply.code(200).send(result);
80
+ };
81
+ exports.handleRequest = handleRequest;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["handleRequest","params","context","request","reply","checkEndpointAccess","ex","code","send","data","error","message","stack","getTenant","tenancy","getCurrentTenant","getLocale","cms","getLastModifiedTime","getModelLastChange","schema","benchmark","measure","getSchema","type","console","formatErrorPayload","body","createRequestBody","result","processRequestBody"],"sources":["handleRequest.ts"],"sourcesContent":["import { ApiEndpoint, CmsContext } from \"~/types\";\nimport { checkEndpointAccess } from \"./checkEndpointAccess\";\nimport { createRequestBody } from \"./createRequestBody\";\nimport { formatErrorPayload } from \"./formatErrorPayload\";\nimport { getSchema } from \"./getSchema\";\nimport { Reply, Request } from \"@webiny/handler/types\";\nimport { processRequestBody } from \"@webiny/handler-graphql\";\nimport { ExecutionResult } from \"graphql\";\n\nexport interface HandleRequestParams {\n context: CmsContext;\n request: Request;\n reply: Reply;\n}\n\nexport interface HandleRequest {\n (params: HandleRequestParams): Promise<Reply>;\n}\n\nexport const handleRequest: HandleRequest = async params => {\n const { context, request, reply } = params;\n try {\n await checkEndpointAccess(context);\n } catch (ex) {\n return reply.code(401).send({\n data: null,\n error: {\n message: ex.message || \"Not authorized!\",\n code: ex.code || \"SECURITY_NOT_AUTHORIZED\",\n data: ex.data || null,\n stack: null\n }\n });\n }\n\n const getTenant = () => {\n return context.tenancy.getCurrentTenant();\n };\n\n const getLocale = () => {\n return context.cms.getLocale();\n };\n\n const getLastModifiedTime = async () => {\n return context.cms.getModelLastChange();\n };\n\n const schema = await context.benchmark.measure(\"headlessCms.graphql.getSchema\", async () => {\n try {\n return await getSchema({\n context,\n getTenant,\n getLastModifiedTime,\n getLocale,\n type: context.cms.type as ApiEndpoint\n });\n } catch (ex) {\n console.error(`Error while generating the schema.`);\n console.error(formatErrorPayload(ex));\n throw ex;\n }\n });\n\n const body = await context.benchmark.measure(\n \"headlessCms.graphql.createRequestBody\",\n async () => {\n try {\n return createRequestBody(request.body);\n } catch (ex) {\n console.error(`Error while creating the body request.`);\n console.error(formatErrorPayload(ex));\n throw ex;\n }\n }\n );\n\n /**\n * We need to store the processRequestBody result in a variable and output it after the measurement.\n * Otherwise, the measurement will not be shown in the output.\n */\n let result: ExecutionResult[] | ExecutionResult | null = null;\n\n await context.benchmark.measure(\"headlessCms.graphql.processRequestBody\", async () => {\n try {\n result = await processRequestBody(body, schema, context);\n } catch (ex) {\n console.error(`Error while processing the body request.`);\n console.error(formatErrorPayload(ex));\n throw ex;\n }\n });\n\n return reply.code(200).send(result);\n};\n"],"mappings":";;;;;;AACA;AACA;AACA;AACA;AAEA;AAaO,MAAMA,aAA4B,GAAG,MAAMC,MAAM,IAAI;EACxD,MAAM;IAAEC,OAAO;IAAEC,OAAO;IAAEC;EAAM,CAAC,GAAGH,MAAM;EAC1C,IAAI;IACA,MAAM,IAAAI,wCAAmB,EAACH,OAAO,CAAC;EACtC,CAAC,CAAC,OAAOI,EAAE,EAAE;IACT,OAAOF,KAAK,CAACG,IAAI,CAAC,GAAG,CAAC,CAACC,IAAI,CAAC;MACxBC,IAAI,EAAE,IAAI;MACVC,KAAK,EAAE;QACHC,OAAO,EAAEL,EAAE,CAACK,OAAO,IAAI,iBAAiB;QACxCJ,IAAI,EAAED,EAAE,CAACC,IAAI,IAAI,yBAAyB;QAC1CE,IAAI,EAAEH,EAAE,CAACG,IAAI,IAAI,IAAI;QACrBG,KAAK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AACC,OAAO,CAAC,wCAAwC,EAAE,YAAY;IAClF,IAAI;MACAO,MAAM,GAAG,MAAM,IAAAC,kCAAkB,EAACH,IAAI,EAAEP,MAAM,EAAElB,OAAO,CAAC;IAC5D,CAAC,CAAC,OAAOI,EAAE,EAAE;MACTmB,OAAO,CAACf,KAAK,CAAE,0CAAyC,CAAC;MACzDe,OAAO,CAACf,KAAK,CAAC,IAAAgB,sCAAkB,EAACpB,EAAE,CAAC,CAAC;MACrC,MAAMA,EAAE;IACZ;EACJ,CAAC,CAAC;EAEF,OAAOF,KAAK,CAACG,IAAI,CAAC,GAAG,CAAC,CAACC,IAAI,CAACqB,MAAM,CAAC;AACvC,CAAC;AAAC"}
@@ -1,5 +1,3 @@
1
- import { GraphQLSchemaPlugin } from "@webiny/handler-graphql/types";
2
1
  import { GraphQLHandlerFactoryParams } from "./graphQLHandlerFactory";
3
- import { CmsContext } from "../types";
4
2
  export declare type CreateGraphQLParams = GraphQLHandlerFactoryParams;
5
- export declare const createGraphQL: (params: CreateGraphQLParams) => (import("@webiny/api").ContextPlugin<CmsContext> | GraphQLSchemaPlugin<CmsContext> | import("@webiny/plugins/types").PluginCollection)[];
3
+ export declare const createGraphQL: (params: CreateGraphQLParams) => (import("@webiny/handler-graphql").GraphQLSchemaPlugin<import("../types").CmsContext> | import("@webiny/api").ContextPlugin<import("../types").CmsContext> | import("@webiny/plugins/types").PluginCollection)[];
package/graphql/index.js CHANGED
@@ -6,45 +6,8 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.createGraphQL = void 0;
7
7
  var _system = require("./system");
8
8
  var _graphQLHandlerFactory = require("./graphQLHandlerFactory");
9
- const createBaseSchema = () => {
10
- return {
11
- name: "cms.graphql.schema.base",
12
- type: "graphql-schema",
13
- schema: {
14
- typeDefs: /* GraphQL */`
15
- type CmsError {
16
- code: String
17
- message: String
18
- data: JSON
19
- stack: String
20
- }
21
-
22
- type CmsCursors {
23
- next: String
24
- previous: String
25
- }
26
-
27
- type CmsListMeta {
28
- cursor: String
29
- hasMoreItems: Boolean
30
- totalCount: Int
31
- }
32
-
33
- type CmsDeleteResponse {
34
- data: Boolean
35
- error: CmsError
36
- }
37
-
38
- type CmsBooleanResponse {
39
- data: Boolean
40
- error: CmsError
41
- }
42
- `,
43
- resolvers: {}
44
- }
45
- };
46
- };
9
+ var _baseSchema = require("./schema/baseSchema");
47
10
  const createGraphQL = params => {
48
- return [createBaseSchema(), (0, _system.createSystemSchemaPlugin)(), (0, _graphQLHandlerFactory.graphQLHandlerFactory)(params)];
11
+ return [...(0, _baseSchema.createBaseSchema)(), (0, _system.createSystemSchemaPlugin)(), (0, _graphQLHandlerFactory.graphQLHandlerFactory)(params)];
49
12
  };
50
13
  exports.createGraphQL = createGraphQL;
@@ -1 +1 @@
1
- {"version":3,"names":["createBaseSchema","name","type","schema","typeDefs","resolvers","createGraphQL","params","createSystemSchemaPlugin","graphQLHandlerFactory"],"sources":["index.ts"],"sourcesContent":["import { GraphQLSchemaPlugin } from \"@webiny/handler-graphql/types\";\nimport { createSystemSchemaPlugin } from \"./system\";\nimport { graphQLHandlerFactory, GraphQLHandlerFactoryParams } from \"./graphQLHandlerFactory\";\nimport { CmsContext } from \"~/types\";\n\nconst createBaseSchema = (): GraphQLSchemaPlugin<CmsContext> => {\n return {\n name: \"cms.graphql.schema.base\",\n type: \"graphql-schema\",\n schema: {\n typeDefs: /* GraphQL */ `\n type CmsError {\n code: String\n message: String\n data: JSON\n stack: String\n }\n\n type CmsCursors {\n next: String\n previous: String\n }\n\n type CmsListMeta {\n cursor: String\n hasMoreItems: Boolean\n totalCount: Int\n }\n\n type CmsDeleteResponse {\n data: Boolean\n error: CmsError\n }\n\n type CmsBooleanResponse {\n data: Boolean\n error: CmsError\n }\n `,\n resolvers: {}\n }\n };\n};\n\nexport type CreateGraphQLParams = GraphQLHandlerFactoryParams;\nexport const createGraphQL = (params: CreateGraphQLParams) => {\n return [createBaseSchema(), createSystemSchemaPlugin(), graphQLHandlerFactory(params)];\n};\n"],"mappings":";;;;;;AACA;AACA;AAGA,MAAMA,gBAAgB,GAAG,MAAuC;EAC5D,OAAO;IACHC,IAAI,EAAE,yBAAyB;IAC/BC,IAAI,EAAE,gBAAgB;IACtBC,MAAM,EAAE;MACJC,QAAQ,EAAE,aAAe;AACrC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAa;MACDC,SAAS,EAAE,CAAC;IAChB;EACJ,CAAC;AACL,CAAC;AAGM,MAAMC,aAAa,GAAIC,MAA2B,IAAK;EAC1D,OAAO,CAACP,gBAAgB,EAAE,EAAE,IAAAQ,gCAAwB,GAAE,EAAE,IAAAC,4CAAqB,EAACF,MAAM,CAAC,CAAC;AAC1F,CAAC;AAAC"}
1
+ {"version":3,"names":["createGraphQL","params","createBaseSchema","createSystemSchemaPlugin","graphQLHandlerFactory"],"sources":["index.ts"],"sourcesContent":["import { createSystemSchemaPlugin } from \"./system\";\nimport { graphQLHandlerFactory, GraphQLHandlerFactoryParams } from \"./graphQLHandlerFactory\";\nimport { createBaseSchema } from \"~/graphql/schema/baseSchema\";\n\nexport type CreateGraphQLParams = GraphQLHandlerFactoryParams;\nexport const createGraphQL = (params: CreateGraphQLParams) => {\n return [...createBaseSchema(), createSystemSchemaPlugin(), graphQLHandlerFactory(params)];\n};\n"],"mappings":";;;;;;AAAA;AACA;AACA;AAGO,MAAMA,aAAa,GAAIC,MAA2B,IAAK;EAC1D,OAAO,CAAC,GAAG,IAAAC,4BAAgB,GAAE,EAAE,IAAAC,gCAAwB,GAAE,EAAE,IAAAC,4CAAqB,EAACH,MAAM,CAAC,CAAC;AAC7F,CAAC;AAAC"}
@@ -1,3 +1,7 @@
1
1
  import { CmsContext } from "../../types";
2
- import { GraphQLSchemaPlugin } from "@webiny/handler-graphql/plugins/GraphQLSchemaPlugin";
3
- export declare const createBaseContentSchema: (context: CmsContext) => GraphQLSchemaPlugin;
2
+ import { CmsGraphQLSchemaPlugin } from "../../plugins";
3
+ interface Params {
4
+ context: CmsContext;
5
+ }
6
+ export declare const createBaseContentSchema: ({ context }: Params) => CmsGraphQLSchemaPlugin;
7
+ export {};
@@ -7,10 +7,12 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.createBaseContentSchema = void 0;
8
8
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
9
  var _builtInTypes = require("@webiny/handler-graphql/builtInTypes");
10
- var _GraphQLSchemaPlugin = require("@webiny/handler-graphql/plugins/GraphQLSchemaPlugin");
11
- const createBaseContentSchema = context => {
10
+ var _plugins = require("../../plugins");
11
+ const createBaseContentSchema = ({
12
+ context
13
+ }) => {
12
14
  const scalars = context.plugins.byType("graphql-scalar").map(item => item.scalar);
13
- return new _GraphQLSchemaPlugin.GraphQLSchemaPlugin({
15
+ const plugin = new _plugins.CmsGraphQLSchemaPlugin({
14
16
  typeDefs: /* GraphQL */`
15
17
  ${scalars.map(scalar => `scalar ${scalar.name}`).join(" ")}
16
18
  scalar JSON
@@ -29,13 +31,7 @@ const createBaseContentSchema = context => {
29
31
  _empty: String
30
32
  }
31
33
 
32
- type CmsCreatedBy {
33
- id: String
34
- displayName: String
35
- type: String
36
- }
37
-
38
- type CmsOwnedBy {
34
+ type CmsIdentity {
39
35
  id: String
40
36
  displayName: String
41
37
  type: String
@@ -52,7 +48,7 @@ const createBaseContentSchema = context => {
52
48
  }, {})), {}, {
53
49
  JSON: _builtInTypes.JsonScalar,
54
50
  Long: _builtInTypes.LongScalar,
55
- RefInput: _builtInTypes.RefInput,
51
+ RefInput: _builtInTypes.RefInputScalar,
56
52
  Number: _builtInTypes.NumberScalar,
57
53
  Any: _builtInTypes.AnyScalar,
58
54
  DateTime: _builtInTypes.DateTimeScalar,
@@ -64,5 +60,7 @@ const createBaseContentSchema = context => {
64
60
  }
65
61
  })
66
62
  });
63
+ plugin.name = `headless-cms.graphql.schema.baseContentSchema`;
64
+ return plugin;
67
65
  };
68
66
  exports.createBaseContentSchema = createBaseContentSchema;
@@ -1 +1 @@
1
- {"version":3,"names":["createBaseContentSchema","context","scalars","plugins","byType","map","item","scalar","GraphQLSchemaPlugin","typeDefs","name","join","resolvers","reduce","acc","s","JSON","JsonScalar","Long","LongScalar","RefInput","Number","NumberScalar","Any","AnyScalar","DateTime","DateTimeScalar","DateTimeZ","DateTimeZScalar","Date","DateScalar","Time","TimeScalar","Mutation","_empty"],"sources":["baseContentSchema.ts"],"sourcesContent":["import { GraphQLScalarPlugin } from \"@webiny/handler-graphql/types\";\nimport { CmsContext } from \"~/types\";\nimport {\n RefInput,\n NumberScalar,\n AnyScalar,\n DateTimeScalar,\n DateScalar,\n TimeScalar,\n LongScalar,\n JsonScalar,\n DateTimeZScalar\n} from \"@webiny/handler-graphql/builtInTypes\";\nimport { GraphQLSchemaPlugin } from \"@webiny/handler-graphql/plugins/GraphQLSchemaPlugin\";\nimport { GraphQLScalarType } from \"graphql\";\n\nexport const createBaseContentSchema = (context: CmsContext): GraphQLSchemaPlugin => {\n const scalars = context.plugins\n .byType<GraphQLScalarPlugin>(\"graphql-scalar\")\n .map(item => item.scalar);\n\n return new GraphQLSchemaPlugin({\n typeDefs: /* GraphQL */ `\n ${scalars.map(scalar => `scalar ${scalar.name}`).join(\" \")}\n scalar JSON\n scalar Long\n scalar RefInput\n scalar Number\n scalar Any\n scalar Date\n scalar DateTime\n scalar DateTimeZ\n scalar Time\n\n type Query\n\n type Mutation {\n _empty: String\n }\n\n type CmsCreatedBy {\n id: String\n displayName: String\n type: String\n }\n\n type CmsOwnedBy {\n id: String\n displayName: String\n type: String\n }\n\n enum CmsEntryStatusType {\n latest\n published\n }\n `,\n resolvers: {\n ...scalars.reduce((acc, s) => {\n acc[s.name] = s;\n return acc;\n }, {} as Record<string, GraphQLScalarType>),\n JSON: JsonScalar,\n Long: LongScalar,\n RefInput,\n Number: NumberScalar,\n Any: AnyScalar,\n DateTime: DateTimeScalar,\n DateTimeZ: DateTimeZScalar,\n Date: DateScalar,\n Time: TimeScalar,\n Mutation: {\n _empty: () => \"_empty\"\n }\n }\n });\n};\n"],"mappings":";;;;;;;;AAEA;AAWA;AAGO,MAAMA,uBAAuB,GAAIC,OAAmB,IAA0B;EACjF,MAAMC,OAAO,GAAGD,OAAO,CAACE,OAAO,CAC1BC,MAAM,CAAsB,gBAAgB,CAAC,CAC7CC,GAAG,CAACC,IAAI,IAAIA,IAAI,CAACC,MAAM,CAAC;EAE7B,OAAO,IAAIC,wCAAmB,CAAC;IAC3BC,QAAQ,EAAE,aAAe;AACjC,cAAcP,OAAO,CAACG,GAAG,CAACE,MAAM,IAAK,UAASA,MAAM,CAACG,IAAK,EAAC,CAAC,CAACC,IAAI,CAAC,GAAG,CAAE;AACvE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;IACDC,SAAS,8DACFV,OAAO,CAACW,MAAM,CAAC,CAACC,GAAG,EAAEC,CAAC,KAAK;MAC1BD,GAAG,CAACC,CAAC,CAACL,IAAI,CAAC,GAAGK,CAAC;MACf,OAAOD,GAAG;IACd,CAAC,EAAE,CAAC,CAAC,CAAsC;MAC3CE,IAAI,EAAEC,wBAAU;MAChBC,IAAI,EAAEC,wBAAU;MAChBC,QAAQ,EAARA,sBAAQ;MACRC,MAAM,EAAEC,0BAAY;MACpBC,GAAG,EAAEC,uBAAS;MACdC,QAAQ,EAAEC,4BAAc;MACxBC,SAAS,EAAEC,6BAAe;MAC1BC,IAAI,EAAEC,wBAAU;MAChBC,IAAI,EAAEC,wBAAU;MAChBC,QAAQ,EAAE;QACNC,MAAM,EAAE,MAAM;MAClB;IAAC;EAET,CAAC,CAAC;AACN,CAAC;AAAC"}
1
+ {"version":3,"names":["createBaseContentSchema","context","scalars","plugins","byType","map","item","scalar","plugin","CmsGraphQLSchemaPlugin","typeDefs","name","join","resolvers","reduce","acc","s","JSON","JsonScalar","Long","LongScalar","RefInput","RefInputScalar","Number","NumberScalar","Any","AnyScalar","DateTime","DateTimeScalar","DateTimeZ","DateTimeZScalar","Date","DateScalar","Time","TimeScalar","Mutation","_empty"],"sources":["baseContentSchema.ts"],"sourcesContent":["import { GraphQLScalarPlugin } from \"@webiny/handler-graphql/types\";\nimport { CmsContext } from \"~/types\";\nimport {\n RefInputScalar,\n NumberScalar,\n AnyScalar,\n DateTimeScalar,\n DateScalar,\n TimeScalar,\n LongScalar,\n JsonScalar,\n DateTimeZScalar\n} from \"@webiny/handler-graphql/builtInTypes\";\nimport { GraphQLScalarType } from \"graphql\";\nimport { CmsGraphQLSchemaPlugin } from \"~/plugins\";\n\ninterface Params {\n context: CmsContext;\n}\nexport const createBaseContentSchema = ({ context }: Params): CmsGraphQLSchemaPlugin => {\n const scalars = context.plugins\n .byType<GraphQLScalarPlugin>(\"graphql-scalar\")\n .map(item => item.scalar);\n\n const plugin = new CmsGraphQLSchemaPlugin({\n typeDefs: /* GraphQL */ `\n ${scalars.map(scalar => `scalar ${scalar.name}`).join(\" \")}\n scalar JSON\n scalar Long\n scalar RefInput\n scalar Number\n scalar Any\n scalar Date\n scalar DateTime\n scalar DateTimeZ\n scalar Time\n\n type Query\n\n type Mutation {\n _empty: String\n }\n\n type CmsIdentity {\n id: String\n displayName: String\n type: String\n }\n\n enum CmsEntryStatusType {\n latest\n published\n }\n `,\n resolvers: {\n ...scalars.reduce<Record<string, GraphQLScalarType>>((acc, s) => {\n acc[s.name] = s;\n return acc;\n }, {}),\n JSON: JsonScalar,\n Long: LongScalar,\n RefInput: RefInputScalar,\n Number: NumberScalar,\n Any: AnyScalar,\n DateTime: DateTimeScalar,\n DateTimeZ: DateTimeZScalar,\n Date: DateScalar,\n Time: TimeScalar,\n Mutation: {\n _empty: () => \"_empty\"\n }\n }\n });\n plugin.name = `headless-cms.graphql.schema.baseContentSchema`;\n\n return plugin;\n};\n"],"mappings":";;;;;;;;AAEA;AAYA;AAKO,MAAMA,uBAAuB,GAAG,CAAC;EAAEC;AAAgB,CAAC,KAA6B;EACpF,MAAMC,OAAO,GAAGD,OAAO,CAACE,OAAO,CAC1BC,MAAM,CAAsB,gBAAgB,CAAC,CAC7CC,GAAG,CAACC,IAAI,IAAIA,IAAI,CAACC,MAAM,CAAC;EAE7B,MAAMC,MAAM,GAAG,IAAIC,+BAAsB,CAAC;IACtCC,QAAQ,EAAE,aAAe;AACjC,cAAcR,OAAO,CAACG,GAAG,CAACE,MAAM,IAAK,UAASA,MAAM,CAACI,IAAK,EAAC,CAAC,CAACC,IAAI,CAAC,GAAG,CAAE;AACvE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;IACDC,SAAS,8DACFX,OAAO,CAACY,MAAM,CAAoC,CAACC,GAAG,EAAEC,CAAC,KAAK;MAC7DD,GAAG,CAACC,CAAC,CAACL,IAAI,CAAC,GAAGK,CAAC;MACf,OAAOD,GAAG;IACd,CAAC,EAAE,CAAC,CAAC,CAAC;MACNE,IAAI,EAAEC,wBAAU;MAChBC,IAAI,EAAEC,wBAAU;MAChBC,QAAQ,EAAEC,4BAAc;MACxBC,MAAM,EAAEC,0BAAY;MACpBC,GAAG,EAAEC,uBAAS;MACdC,QAAQ,EAAEC,4BAAc;MACxBC,SAAS,EAAEC,6BAAe;MAC1BC,IAAI,EAAEC,wBAAU;MAChBC,IAAI,EAAEC,wBAAU;MAChBC,QAAQ,EAAE;QACNC,MAAM,EAAE,MAAM;MAClB;IAAC;EAET,CAAC,CAAC;EACF5B,MAAM,CAACG,IAAI,GAAI,+CAA8C;EAE7D,OAAOH,MAAM;AACjB,CAAC;AAAC"}
@@ -0,0 +1,3 @@
1
+ import { CmsContext } from "../../types";
2
+ import { GraphQLSchemaPlugin } from "@webiny/handler-graphql";
3
+ export declare const createBaseSchema: () => GraphQLSchemaPlugin<CmsContext>[];
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createBaseSchema = void 0;
7
+ var _plugins = require("../../plugins");
8
+ var _handlerGraphql = require("@webiny/handler-graphql");
9
+ const createBaseSchema = () => {
10
+ const cmsPlugin = new _plugins.CmsGraphQLSchemaPlugin({
11
+ typeDefs: /* GraphQL */`
12
+ type CmsError {
13
+ code: String
14
+ message: String
15
+ data: JSON
16
+ stack: String
17
+ }
18
+
19
+ type CmsCursors {
20
+ next: String
21
+ previous: String
22
+ }
23
+
24
+ type CmsListMeta {
25
+ cursor: String
26
+ hasMoreItems: Boolean
27
+ totalCount: Int
28
+ }
29
+
30
+ input CmsDeleteEntryOptions {
31
+ # force delete an entry that might have some records left behind in the database
32
+ # see CmsDeleteEntryOptions in types.ts
33
+ force: Boolean
34
+ }
35
+
36
+ type CmsDeleteResponse {
37
+ data: Boolean
38
+ error: CmsError
39
+ }
40
+
41
+ type CmsDeleteMultipleDataResponse {
42
+ id: ID!
43
+ }
44
+
45
+ type CmsDeleteMultipleResponse {
46
+ data: [CmsDeleteMultipleDataResponse!]
47
+ error: CmsError
48
+ }
49
+
50
+ type CmsBooleanResponse {
51
+ data: Boolean
52
+ error: CmsError
53
+ }
54
+ `,
55
+ resolvers: {}
56
+ });
57
+ cmsPlugin.name = "headless-cms.graphql.schema.base";
58
+ const corePlugin = new _handlerGraphql.GraphQLSchemaPlugin({
59
+ typeDefs: cmsPlugin.schema.typeDefs,
60
+ resolvers: cmsPlugin.schema.resolvers
61
+ });
62
+ corePlugin.name = "headless-cms.graphql.core.schema.base";
63
+ /**
64
+ * Due to splitting of CMS and Core schema plugins, we must have both defined for CMS to work.
65
+ */
66
+ return [cmsPlugin, corePlugin];
67
+ };
68
+ exports.createBaseSchema = createBaseSchema;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createBaseSchema","cmsPlugin","CmsGraphQLSchemaPlugin","typeDefs","resolvers","name","corePlugin","GraphQLSchemaPlugin","schema"],"sources":["baseSchema.ts"],"sourcesContent":["import { CmsContext } from \"~/types\";\nimport { CmsGraphQLSchemaPlugin } from \"~/plugins\";\nimport { GraphQLSchemaPlugin } from \"@webiny/handler-graphql\";\n\nexport const createBaseSchema = (): GraphQLSchemaPlugin<CmsContext>[] => {\n const cmsPlugin = new CmsGraphQLSchemaPlugin({\n typeDefs: /* GraphQL */ `\n type CmsError {\n code: String\n message: String\n data: JSON\n stack: String\n }\n\n type CmsCursors {\n next: String\n previous: String\n }\n\n type CmsListMeta {\n cursor: String\n hasMoreItems: Boolean\n totalCount: Int\n }\n\n input CmsDeleteEntryOptions {\n # force delete an entry that might have some records left behind in the database\n # see CmsDeleteEntryOptions in types.ts\n force: Boolean\n }\n\n type CmsDeleteResponse {\n data: Boolean\n error: CmsError\n }\n\n type CmsDeleteMultipleDataResponse {\n id: ID!\n }\n\n type CmsDeleteMultipleResponse {\n data: [CmsDeleteMultipleDataResponse!]\n error: CmsError\n }\n\n type CmsBooleanResponse {\n data: Boolean\n error: CmsError\n }\n `,\n resolvers: {}\n });\n cmsPlugin.name = \"headless-cms.graphql.schema.base\";\n const corePlugin = new GraphQLSchemaPlugin<CmsContext>({\n typeDefs: cmsPlugin.schema.typeDefs,\n resolvers: cmsPlugin.schema.resolvers\n });\n corePlugin.name = \"headless-cms.graphql.core.schema.base\";\n /**\n * Due to splitting of CMS and Core schema plugins, we must have both defined for CMS to work.\n */\n return [cmsPlugin, corePlugin];\n};\n"],"mappings":";;;;;;AACA;AACA;AAEO,MAAMA,gBAAgB,GAAG,MAAyC;EACrE,MAAMC,SAAS,GAAG,IAAIC,+BAAsB,CAAC;IACzCC,QAAQ,EAAE,aAAe;AACjC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;IACDC,SAAS,EAAE,CAAC;EAChB,CAAC,CAAC;EACFH,SAAS,CAACI,IAAI,GAAG,kCAAkC;EACnD,MAAMC,UAAU,GAAG,IAAIC,mCAAmB,CAAa;IACnDJ,QAAQ,EAAEF,SAAS,CAACO,MAAM,CAACL,QAAQ;IACnCC,SAAS,EAAEH,SAAS,CAACO,MAAM,CAACJ;EAChC,CAAC,CAAC;EACFE,UAAU,CAACD,IAAI,GAAG,uCAAuC;EACzD;AACJ;AACA;EACI,OAAO,CAACJ,SAAS,EAAEK,UAAU,CAAC;AAClC,CAAC;AAAC"}