@webiny/api-headless-cms 0.0.0-unstable.d65ec29d44 → 0.0.0-unstable.da99e0b846
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.
- package/context.js +47 -43
- package/context.js.map +1 -1
- package/crud/contentEntry/markLockedFields.d.ts +1 -1
- package/crud/contentEntry/markLockedFields.js +3 -0
- package/crud/contentEntry/markLockedFields.js.map +1 -1
- package/crud/contentEntry.crud.d.ts +5 -2
- package/crud/contentEntry.crud.js +848 -830
- package/crud/contentEntry.crud.js.map +1 -1
- package/crud/contentModel/beforeCreate.js +39 -76
- package/crud/contentModel/beforeCreate.js.map +1 -1
- package/crud/contentModel/beforeDelete.d.ts +1 -1
- package/crud/contentModel/beforeDelete.js +1 -5
- package/crud/contentModel/beforeDelete.js.map +1 -1
- package/crud/contentModel/beforeUpdate.js +31 -3
- package/crud/contentModel/beforeUpdate.js.map +1 -1
- package/crud/contentModel/compatibility/modelApiName.d.ts +3 -0
- package/crud/contentModel/compatibility/modelApiName.js +24 -0
- package/crud/contentModel/compatibility/modelApiName.js.map +1 -0
- package/crud/contentModel/defaultFields.d.ts +5 -0
- package/crud/contentModel/defaultFields.js +58 -0
- package/crud/contentModel/defaultFields.js.map +1 -0
- package/crud/contentModel/fields/descriptionField.d.ts +2 -0
- package/crud/contentModel/fields/descriptionField.js +42 -0
- package/crud/contentModel/fields/descriptionField.js.map +1 -0
- package/crud/contentModel/fields/imageField.d.ts +2 -0
- package/crud/contentModel/fields/imageField.js +46 -0
- package/crud/contentModel/fields/imageField.js.map +1 -0
- package/crud/contentModel/fields/titleField.d.ts +2 -0
- package/crud/contentModel/fields/titleField.js +58 -0
- package/crud/contentModel/fields/titleField.js.map +1 -0
- package/crud/contentModel/systemFields.js.map +1 -1
- package/crud/contentModel/validate/endingAllowed.d.ts +6 -0
- package/crud/contentModel/validate/endingAllowed.js +26 -0
- package/crud/contentModel/validate/endingAllowed.js.map +1 -0
- package/crud/contentModel/validate/isModelEndingAllowed.d.ts +6 -0
- package/crud/contentModel/validate/isModelEndingAllowed.js +24 -0
- package/crud/contentModel/validate/isModelEndingAllowed.js.map +1 -0
- package/crud/contentModel/validate/modelId.d.ts +11 -0
- package/crud/contentModel/validate/modelId.js +36 -0
- package/crud/contentModel/validate/modelId.js.map +1 -0
- package/crud/contentModel/validate/pluralApiName.d.ts +7 -0
- package/crud/contentModel/validate/pluralApiName.js +24 -0
- package/crud/contentModel/validate/pluralApiName.js.map +1 -0
- package/crud/contentModel/validate/singularApiName.d.ts +7 -0
- package/crud/contentModel/validate/singularApiName.js +24 -0
- package/crud/contentModel/validate/singularApiName.js.map +1 -0
- package/crud/contentModel/validateModel.d.ts +1 -0
- package/crud/contentModel/validateModel.js.map +1 -1
- package/crud/contentModel/validateModelFields.d.ts +2 -1
- package/crud/contentModel/validateModelFields.js +19 -57
- package/crud/contentModel/validateModelFields.js.map +1 -1
- package/crud/contentModel/validation.d.ts +136 -62
- package/crud/contentModel/validation.js +61 -13
- package/crud/contentModel/validation.js.map +1 -1
- package/crud/contentModel.crud.js +346 -285
- package/crud/contentModel.crud.js.map +1 -1
- package/crud/contentModelGroup.crud.js +170 -142
- package/crud/contentModelGroup.crud.js.map +1 -1
- package/crud/settings.crud.d.ts +1 -1
- package/crud/settings.crud.js +5 -10
- package/crud/settings.crud.js.map +1 -1
- package/crud/system.crud.js +0 -60
- package/crud/system.crud.js.map +1 -1
- package/graphql/checkEndpointAccess.d.ts +2 -0
- package/graphql/checkEndpointAccess.js +18 -0
- package/graphql/checkEndpointAccess.js.map +1 -0
- package/graphql/createExecutableSchema.d.ts +2 -3
- package/graphql/createExecutableSchema.js.map +1 -1
- package/graphql/createRequestBody.d.ts +2 -0
- package/graphql/createRequestBody.js +14 -0
- package/graphql/createRequestBody.js.map +1 -0
- package/graphql/formatErrorPayload.d.ts +1 -0
- package/graphql/formatErrorPayload.js +25 -0
- package/graphql/formatErrorPayload.js.map +1 -0
- package/graphql/generateSchema.js.map +1 -1
- package/graphql/getSchema.d.ts +17 -0
- package/graphql/getSchema.js +102 -0
- package/graphql/getSchema.js.map +1 -0
- package/graphql/graphQLHandlerFactory.js +6 -145
- package/graphql/graphQLHandlerFactory.js.map +1 -1
- package/graphql/handleRequest.d.ts +11 -0
- package/graphql/handleRequest.js +81 -0
- package/graphql/handleRequest.js.map +1 -0
- package/graphql/schema/baseContentSchema.js +1 -7
- package/graphql/schema/baseContentSchema.js.map +1 -1
- package/graphql/schema/contentEntries.js +90 -53
- package/graphql/schema/contentEntries.js.map +1 -1
- package/graphql/schema/contentModelGroups.js +7 -7
- package/graphql/schema/contentModelGroups.js.map +1 -1
- package/graphql/schema/contentModels.js +23 -4
- package/graphql/schema/contentModels.js.map +1 -1
- package/graphql/schema/createManageResolvers.d.ts +1 -1
- package/graphql/schema/createManageResolvers.js +33 -17
- package/graphql/schema/createManageResolvers.js.map +1 -1
- package/graphql/schema/createManageSDL.d.ts +1 -0
- package/graphql/schema/createManageSDL.js +55 -49
- package/graphql/schema/createManageSDL.js.map +1 -1
- package/graphql/schema/createPreviewResolvers.js +3 -7
- package/graphql/schema/createPreviewResolvers.js.map +1 -1
- package/graphql/schema/createReadResolvers.js +4 -8
- package/graphql/schema/createReadResolvers.js.map +1 -1
- package/graphql/schema/createReadSDL.d.ts +1 -0
- package/graphql/schema/createReadSDL.js +24 -22
- package/graphql/schema/createReadSDL.js.map +1 -1
- package/graphql/schema/resolvers/commonFieldResolvers.d.ts +3 -2
- package/graphql/schema/resolvers/commonFieldResolvers.js +2 -1
- package/graphql/schema/resolvers/commonFieldResolvers.js.map +1 -1
- package/graphql/schema/schemaPlugins.js +12 -12
- package/graphql/schema/schemaPlugins.js.map +1 -1
- package/graphql/system.js +0 -16
- package/graphql/system.js.map +1 -1
- package/graphqlFields/dynamicZone/dynamicZoneField.js +12 -4
- package/graphqlFields/dynamicZone/dynamicZoneField.js.map +1 -1
- package/graphqlFields/object.js +21 -2
- package/graphqlFields/object.js.map +1 -1
- package/graphqlFields/ref.js +42 -14
- package/graphqlFields/ref.js.map +1 -1
- package/index.d.ts +3 -1
- package/index.js +25 -2
- package/index.js.map +1 -1
- package/package.json +22 -23
- package/plugins/CmsModelPlugin.d.ts +19 -3
- package/plugins/CmsModelPlugin.js +28 -2
- package/plugins/CmsModelPlugin.js.map +1 -1
- package/plugins/StorageOperationsCmsModelPlugin.d.ts +23 -0
- package/plugins/StorageOperationsCmsModelPlugin.js +42 -0
- package/plugins/StorageOperationsCmsModelPlugin.js.map +1 -0
- package/plugins/index.d.ts +1 -0
- package/plugins/index.js +11 -0
- package/plugins/index.js.map +1 -1
- package/types.d.ts +118 -66
- package/types.js +1 -1
- package/types.js.map +1 -1
- package/upgrades/5.33.0/index.js +26 -3
- package/upgrades/5.33.0/index.js.map +1 -1
- package/upgrades/index.js +3 -0
- package/upgrades/index.js.map +1 -1
- package/utils/converters/valueKeyStorageConverter.d.ts +1 -5
- package/utils/converters/valueKeyStorageConverter.js +21 -18
- package/utils/converters/valueKeyStorageConverter.js.map +1 -1
- package/utils/createTypeFromFields.d.ts +1 -0
- package/utils/createTypeFromFields.js +7 -5
- package/utils/createTypeFromFields.js.map +1 -1
- package/utils/createTypeName.d.ts +0 -2
- package/utils/createTypeName.js +2 -10
- package/utils/createTypeName.js.map +1 -1
- package/utils/getEntryDescription.d.ts +2 -0
- package/utils/getEntryDescription.js +17 -0
- package/utils/getEntryDescription.js.map +1 -0
- package/utils/getEntryImage.d.ts +2 -0
- package/utils/getEntryImage.js +17 -0
- package/utils/getEntryImage.js.map +1 -0
- package/utils/incrementEntryIdVersion.d.ts +5 -0
- package/utils/incrementEntryIdVersion.js +29 -0
- package/utils/incrementEntryIdVersion.js.map +1 -0
- package/utils/ownership.d.ts +3 -3
- package/utils/ownership.js.map +1 -1
- package/utils/pluralizedTypeName.js +6 -0
- package/utils/pluralizedTypeName.js.map +1 -1
- package/utils/renderFields.d.ts +2 -1
- package/utils/renderFields.js +8 -1
- package/utils/renderFields.js.map +1 -1
- package/utils/renderInputFields.d.ts +2 -1
- package/utils/renderInputFields.js +4 -0
- package/utils/renderInputFields.js.map +1 -1
|
@@ -5,159 +5,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.graphQLHandlerFactory = void 0;
|
|
8
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
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
9
|
var _handler = require("@webiny/handler");
|
|
13
|
-
var
|
|
14
|
-
var _codeFrame = _interopRequireDefault(require("code-frame"));
|
|
15
|
-
var _generateSchema = require("./generateSchema");
|
|
16
|
-
// @ts-ignore `code-frame` has no types
|
|
17
|
-
|
|
18
|
-
const createRequestBody = body => {
|
|
19
|
-
/**
|
|
20
|
-
* We are trusting that the body payload is correct.
|
|
21
|
-
* The `processRequestBody` will fail if it is not.
|
|
22
|
-
*/
|
|
23
|
-
return typeof body === "string" ? JSON.parse(body) : body;
|
|
24
|
-
};
|
|
25
|
-
const schemaList = new Map();
|
|
26
|
-
const generateCacheKey = async args => {
|
|
27
|
-
const {
|
|
28
|
-
context,
|
|
29
|
-
locale,
|
|
30
|
-
type
|
|
31
|
-
} = args;
|
|
32
|
-
const lastModelChange = await context.cms.getModelLastChange();
|
|
33
|
-
return [locale.code, type, lastModelChange.toISOString()].join("#");
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Gets an existing schema or rewrites existing one or creates a completely new one
|
|
38
|
-
* depending on the schemaId created from type and locale parameters
|
|
39
|
-
*/
|
|
40
|
-
const getSchema = async params => {
|
|
41
|
-
const {
|
|
42
|
-
context,
|
|
43
|
-
type,
|
|
44
|
-
locale
|
|
45
|
-
} = params;
|
|
46
|
-
const tenantId = context.tenancy.getCurrentTenant().id;
|
|
47
|
-
const id = `${tenantId}#${type}#${locale.code}`;
|
|
48
|
-
const cacheKey = await generateCacheKey(params);
|
|
49
|
-
const cachedSchema = schemaList.get(id);
|
|
50
|
-
if ((cachedSchema === null || cachedSchema === void 0 ? void 0 : cachedSchema.key) === cacheKey) {
|
|
51
|
-
return cachedSchema.schema;
|
|
52
|
-
}
|
|
53
|
-
// Load model data
|
|
54
|
-
context.security.disableAuthorization();
|
|
55
|
-
const models = (await context.cms.listModels()).filter(model => model.isPrivate !== true);
|
|
56
|
-
context.security.enableAuthorization();
|
|
57
|
-
try {
|
|
58
|
-
const schema = await (0, _generateSchema.generateSchema)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
|
|
59
|
-
models
|
|
60
|
-
}));
|
|
61
|
-
schemaList.set(id, {
|
|
62
|
-
key: cacheKey,
|
|
63
|
-
schema
|
|
64
|
-
});
|
|
65
|
-
return schema;
|
|
66
|
-
} catch (err) {
|
|
67
|
-
if (!Array.isArray(err.locations)) {
|
|
68
|
-
throw new _error.default({
|
|
69
|
-
message: err.message,
|
|
70
|
-
code: err.code || "INVALID_GRAPHQL_SCHEMA_LOCATIONS",
|
|
71
|
-
data: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, err.data || {}), {}, {
|
|
72
|
-
locations: err.locations
|
|
73
|
-
})
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
const [location] = err.locations;
|
|
77
|
-
throw new _error.default({
|
|
78
|
-
code: "INVALID_GRAPHQL_SCHEMA",
|
|
79
|
-
message: err.message,
|
|
80
|
-
data: {
|
|
81
|
-
invalidSegment: (0, _codeFrame.default)(err.source.body, location.line, location.column, {
|
|
82
|
-
frameSize: 15
|
|
83
|
-
})
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
const checkEndpointAccess = async context => {
|
|
89
|
-
const permission = await context.security.getPermission(`cms.endpoint.${context.cms.type}`);
|
|
90
|
-
if (!permission) {
|
|
91
|
-
throw new _apiSecurity.NotAuthorizedError({
|
|
92
|
-
data: {
|
|
93
|
-
reason: `Not allowed to access "${context.cms.type}" endpoint.`
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
const formatErrorPayload = error => {
|
|
99
|
-
if (error instanceof _error.default) {
|
|
100
|
-
return JSON.stringify({
|
|
101
|
-
type: "CmsGraphQLWebinyError",
|
|
102
|
-
message: error.message,
|
|
103
|
-
code: error.code,
|
|
104
|
-
data: error.data
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
return JSON.stringify({
|
|
108
|
-
type: "Error",
|
|
109
|
-
name: error.name,
|
|
110
|
-
message: error.message,
|
|
111
|
-
stack: error.stack
|
|
112
|
-
});
|
|
113
|
-
};
|
|
10
|
+
var _handleRequest = require("./handleRequest");
|
|
114
11
|
const cmsRoutes = new _handler.RoutePlugin(({
|
|
115
12
|
onPost,
|
|
116
13
|
onOptions,
|
|
117
14
|
context
|
|
118
15
|
}) => {
|
|
119
16
|
onPost("/cms/:type(^manage|preview|read$)/:locale", async (request, reply) => {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
error: {
|
|
126
|
-
message: ex.message || "Not authorized!",
|
|
127
|
-
code: ex.code || "SECURITY_NOT_AUTHORIZED",
|
|
128
|
-
data: ex.data || null,
|
|
129
|
-
stack: null
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
let schema;
|
|
134
|
-
try {
|
|
135
|
-
schema = await getSchema({
|
|
136
|
-
context,
|
|
137
|
-
locale: context.cms.getLocale(),
|
|
138
|
-
type: context.cms.type
|
|
139
|
-
});
|
|
140
|
-
} catch (ex) {
|
|
141
|
-
console.log(`Error while generating the schema.`);
|
|
142
|
-
console.log(formatErrorPayload(ex));
|
|
143
|
-
throw ex;
|
|
144
|
-
}
|
|
145
|
-
let body = [];
|
|
146
|
-
try {
|
|
147
|
-
body = createRequestBody(request.body);
|
|
148
|
-
} catch (ex) {
|
|
149
|
-
console.log(`Error while creating the body request.`);
|
|
150
|
-
console.log(formatErrorPayload(ex));
|
|
151
|
-
throw ex;
|
|
152
|
-
}
|
|
153
|
-
try {
|
|
154
|
-
const result = await (0, _processRequestBody.default)(body, schema, context);
|
|
155
|
-
return reply.code(200).send(result);
|
|
156
|
-
} catch (ex) {
|
|
157
|
-
console.log(`Error while processing the body request.`);
|
|
158
|
-
console.log(formatErrorPayload(ex));
|
|
159
|
-
throw ex;
|
|
160
|
-
}
|
|
17
|
+
return (0, _handleRequest.handleRequest)({
|
|
18
|
+
context,
|
|
19
|
+
request,
|
|
20
|
+
reply
|
|
21
|
+
});
|
|
161
22
|
});
|
|
162
23
|
onOptions("/cms/:type(^manage|preview|read$)/:locale", async (_, reply) => {
|
|
163
24
|
return reply.status(204).send({}).hijack();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createRequestBody","body","JSON","parse","schemaList","Map","generateCacheKey","args","context","locale","type","lastModelChange","cms","getModelLastChange","code","toISOString","join","getSchema","params","tenantId","tenancy","getCurrentTenant","id","cacheKey","cachedSchema","get","key","schema","security","disableAuthorization","models","listModels","filter","model","isPrivate","enableAuthorization","generateSchema","set","err","Array","isArray","locations","WebinyError","message","data","location","invalidSegment","codeFrame","source","line","column","frameSize","checkEndpointAccess","permission","getPermission","NotAuthorizedError","reason","formatErrorPayload","error","stringify","name","stack","cmsRoutes","RoutePlugin","onPost","onOptions","request","reply","ex","send","getLocale","console","log","result","processRequestBody","_","status","hijack","graphQLHandlerFactory","debug","debugPlugins"],"sources":["graphQLHandlerFactory.ts"],"sourcesContent":["import { GraphQLSchema } from \"graphql\";\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 { GraphQLRequestBody } from \"@webiny/handler-graphql/types\";\nimport { RoutePlugin } from \"@webiny/handler\";\nimport WebinyError from \"@webiny/error\";\n// @ts-ignore `code-frame` has no types\nimport codeFrame from \"code-frame\";\nimport { generateSchema } from \"~/graphql/generateSchema\";\n\ninterface SchemaCache {\n key: string;\n schema: GraphQLSchema;\n}\ninterface GetSchemaParams {\n context: CmsContext;\n type: ApiEndpoint;\n locale: I18NLocale;\n}\n\nconst createRequestBody = (body: unknown): GraphQLRequestBody | GraphQLRequestBody[] => {\n /**\n * We are trusting that the body payload is correct.\n * The `processRequestBody` will fail if it is not.\n */\n return typeof body === \"string\" ? JSON.parse(body) : body;\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\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 const cachedSchema = schemaList.get(id);\n if (cachedSchema?.key === cacheKey) {\n return cachedSchema.schema;\n }\n // Load model data\n context.security.disableAuthorization();\n const models = (await context.cms.listModels()).filter(model => model.isPrivate !== true);\n context.security.enableAuthorization();\n try {\n const schema = await generateSchema({\n ...params,\n models\n });\n schemaList.set(id, {\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\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\nconst formatErrorPayload = (error: Error): string => {\n if (error instanceof WebinyError) {\n return JSON.stringify({\n type: \"CmsGraphQLWebinyError\",\n message: error.message,\n code: error.code,\n data: error.data\n });\n }\n\n return JSON.stringify({\n type: \"Error\",\n name: error.name,\n message: error.message,\n stack: error.stack\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 let schema: GraphQLSchema;\n try {\n schema = await getSchema({\n context,\n locale: context.cms.getLocale(),\n type: context.cms.type as ApiEndpoint\n });\n } catch (ex) {\n console.log(`Error while generating the schema.`);\n console.log(formatErrorPayload(ex));\n throw ex;\n }\n\n let body: GraphQLRequestBody | GraphQLRequestBody[] = [];\n try {\n body = createRequestBody(request.body);\n } catch (ex) {\n console.log(`Error while creating the body request.`);\n console.log(formatErrorPayload(ex));\n throw ex;\n }\n\n try {\n const result = await processRequestBody(body, schema, context);\n return reply.code(200).send(result);\n } catch (ex) {\n console.log(`Error while processing the body request.`);\n console.log(formatErrorPayload(ex));\n throw ex;\n }\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":";;;;;;;;AAGA;AAEA;AACA;AAEA;AACA;AAEA;AACA;AAFA;;AAcA,MAAMA,iBAAiB,GAAIC,IAAa,IAAgD;EACpF;AACJ;AACA;AACA;EACI,OAAO,OAAOA,IAAI,KAAK,QAAQ,GAAGC,IAAI,CAACC,KAAK,CAACF,IAAI,CAAC,GAAGA,IAAI;AAC7D,CAAC;AAED,MAAMG,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;AACA;AACA;AACA;AACA,MAAMC,SAAS,GAAG,MAAOC,MAAuB,IAA6B;EACzE,MAAM;IAAEV,OAAO;IAAEE,IAAI;IAAED;EAAO,CAAC,GAAGS,MAAM;EACxC,MAAMC,QAAQ,GAAGX,OAAO,CAACY,OAAO,CAACC,gBAAgB,EAAE,CAACC,EAAE;EACtD,MAAMA,EAAE,GAAI,GAAEH,QAAS,IAAGT,IAAK,IAAGD,MAAM,CAACK,IAAK,EAAC;EAE/C,MAAMS,QAAQ,GAAG,MAAMjB,gBAAgB,CAACY,MAA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,CAAC,OAAOL,EAAE,EAAE;MACTG,OAAO,CAACC,GAAG,CAAE,0CAAyC,CAAC;MACvDD,OAAO,CAACC,GAAG,CAACf,kBAAkB,CAACW,EAAE,CAAC,CAAC;MACnC,MAAMA,EAAE;IACZ;EACJ,CAAC,CAAC;EAEFH,SAAS,CAAC,2CAA2C,EAAE,OAAOU,CAAC,EAAER,KAAK,KAAK;IACvE,OAAOA,KAAK,CAACS,MAAM,CAAC,GAAG,CAAC,CAACP,IAAI,CAAC,CAAC,CAAC,CAAC,CAACQ,MAAM,EAAE;EAC9C,CAAC,CAAC;AACN,CAAC,CAAC;AAEFf,SAAS,CAACF,IAAI,GAAG,oCAAoC;AAE9C,MAAMkB,qBAAqB,GAAG,CAAC;EAAEC;AAAmC,CAAC,KAAuB;EAC/F,OAAO,CACH,IAAIA,KAAK,GAAG,IAAAC,qBAAY,GAAE,GAAG,EAAE,CAAC,EAChClB,SAAS,EACT;IACIpD,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,IAA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AMqB,IAAI,GAAG,MAAMzB,OAAO,CAACmB,SAAS,CAACC,OAAO,CACxC,uCAAuC,EACvC,YAAY;IACR,IAAI;MACA,OAAO,IAAAM,oCAAiB,EAACzB,OAAO,CAACwB,IAAI,CAAC;IAC1C,CAAC,CAAC,OAAOrB,EAAE,EAAE;MACTmB,OAAO,CAACf,KAAK,CAAE,wCAAuC,CAAC;MACvDe,OAAO,CAACf,KAAK,CAAC,IAAAgB,sCAAkB,EAACpB,EAAE,CAAC,CAAC;MACrC,MAAMA,EAAE;IACZ;EACJ,CAAC,CACJ;;EAED;AACJ;AACA;AACA;EACI,IAAIuB,MAAkD,GAAG,IAAI;EAE7D,MAAM3B,OAAO,CAACmB,SAAS,CAACC,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 +1 @@
|
|
|
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
|
|
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"}
|
|
@@ -5,11 +5,38 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.createContentEntriesSchema = void 0;
|
|
8
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
8
9
|
var _handlerGraphql = require("@webiny/handler-graphql");
|
|
9
10
|
var _apiSecurity = require("@webiny/api-security");
|
|
10
11
|
var _getEntryTitle = require("../../utils/getEntryTitle");
|
|
11
12
|
var _plugins = require("../../plugins");
|
|
12
|
-
var
|
|
13
|
+
var _getEntryDescription = require("../../utils/getEntryDescription");
|
|
14
|
+
var _getEntryImage = require("../../utils/getEntryImage");
|
|
15
|
+
var _entryStorage = require("../../utils/entryStorage");
|
|
16
|
+
const createDate = date => {
|
|
17
|
+
try {
|
|
18
|
+
return new Date(date);
|
|
19
|
+
} catch {}
|
|
20
|
+
return new Date();
|
|
21
|
+
};
|
|
22
|
+
const createCmsEntryRecord = (model, entry) => {
|
|
23
|
+
return {
|
|
24
|
+
id: entry.id,
|
|
25
|
+
entryId: entry.entryId,
|
|
26
|
+
model: {
|
|
27
|
+
modelId: model.modelId,
|
|
28
|
+
name: model.name
|
|
29
|
+
},
|
|
30
|
+
status: entry.status,
|
|
31
|
+
title: (0, _getEntryTitle.getEntryTitle)(model, entry),
|
|
32
|
+
description: (0, _getEntryDescription.getEntryDescription)(model, entry),
|
|
33
|
+
image: (0, _getEntryImage.getEntryImage)(model, entry),
|
|
34
|
+
createdBy: entry.createdBy,
|
|
35
|
+
modifiedBy: entry.modifiedBy,
|
|
36
|
+
createdOn: createDate(entry.createdOn),
|
|
37
|
+
savedOn: createDate(entry.savedOn)
|
|
38
|
+
};
|
|
39
|
+
};
|
|
13
40
|
const getFetchMethod = (type, context) => {
|
|
14
41
|
if (!getContentEntriesMethods[type]) {
|
|
15
42
|
throw new _error.default(`Unknown getContentEntries method "${type}". Could not fetch content entries.`, "UNKNOWN_METHOD_ERROR", {
|
|
@@ -72,16 +99,7 @@ const getContentEntries = async params => {
|
|
|
72
99
|
const entries = results.reduce((collection, items) => {
|
|
73
100
|
return collection.concat(items.map(item => {
|
|
74
101
|
const model = modelsMap[item.modelId];
|
|
75
|
-
return
|
|
76
|
-
id: item.id,
|
|
77
|
-
entryId: item.entryId,
|
|
78
|
-
model: {
|
|
79
|
-
modelId: model.modelId,
|
|
80
|
-
name: model.name
|
|
81
|
-
},
|
|
82
|
-
status: item.status,
|
|
83
|
-
title: (0, _getEntryTitle.getEntryTitle)(model, item)
|
|
84
|
-
};
|
|
102
|
+
return createCmsEntryRecord(model, item);
|
|
85
103
|
}));
|
|
86
104
|
}, []).filter(Boolean);
|
|
87
105
|
return new _handlerGraphql.Response(entries);
|
|
@@ -125,16 +143,37 @@ const getContentEntry = async params => {
|
|
|
125
143
|
if (!entry) {
|
|
126
144
|
return new _handlerGraphql.Response(null);
|
|
127
145
|
}
|
|
128
|
-
return new _handlerGraphql.Response(
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
146
|
+
return new _handlerGraphql.Response(createCmsEntryRecord(model, entry));
|
|
147
|
+
};
|
|
148
|
+
/**
|
|
149
|
+
* As we support description field, we need to transform the value from storage.
|
|
150
|
+
*/
|
|
151
|
+
const createResolveDescription = () => {
|
|
152
|
+
return async (parent, _, context) => {
|
|
153
|
+
const models = await context.cms.listModels();
|
|
154
|
+
const model = models.find(({
|
|
155
|
+
modelId
|
|
156
|
+
}) => {
|
|
157
|
+
return parent.model.modelId === modelId;
|
|
158
|
+
});
|
|
159
|
+
if (!model) {
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
const field = model.fields.find(f => f.fieldId === model.descriptionFieldId);
|
|
163
|
+
if (!field) {
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
const value = parent.description || parent[field.fieldId];
|
|
167
|
+
if (!value) {
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
return (0, _entryStorage.entryFieldFromStorageTransform)({
|
|
171
|
+
context,
|
|
172
|
+
model,
|
|
173
|
+
field,
|
|
174
|
+
value
|
|
175
|
+
});
|
|
176
|
+
};
|
|
138
177
|
};
|
|
139
178
|
const createContentEntriesSchema = ({
|
|
140
179
|
context
|
|
@@ -150,27 +189,36 @@ const createContentEntriesSchema = ({
|
|
|
150
189
|
const plugin = new _plugins.CmsGraphQLSchemaPlugin({
|
|
151
190
|
typeDefs: /* GraphQL */`
|
|
152
191
|
type CmsModelMeta {
|
|
153
|
-
modelId: String
|
|
154
|
-
name: String
|
|
192
|
+
modelId: String!
|
|
193
|
+
name: String!
|
|
155
194
|
}
|
|
156
195
|
|
|
157
196
|
type CmsPublishedContentEntry {
|
|
158
197
|
id: ID!
|
|
159
198
|
entryId: String!
|
|
160
199
|
title: String
|
|
200
|
+
description: String
|
|
201
|
+
image: String
|
|
161
202
|
}
|
|
162
203
|
|
|
163
204
|
type CmsContentEntry {
|
|
164
205
|
id: ID!
|
|
165
206
|
entryId: String!
|
|
166
|
-
model: CmsModelMeta
|
|
167
|
-
status: String
|
|
168
|
-
title: String
|
|
207
|
+
model: CmsModelMeta!
|
|
208
|
+
status: String!
|
|
209
|
+
title: String!
|
|
210
|
+
description: String
|
|
211
|
+
image: String
|
|
212
|
+
createdBy: CmsIdentity!
|
|
213
|
+
ownedBy: CmsIdentity!
|
|
214
|
+
modifiedBy: CmsIdentity
|
|
169
215
|
published: CmsPublishedContentEntry
|
|
216
|
+
createdOn: DateTime!
|
|
217
|
+
savedOn: DateTime!
|
|
170
218
|
}
|
|
171
219
|
|
|
172
220
|
type CmsContentEntriesResponse {
|
|
173
|
-
data: [CmsContentEntry]
|
|
221
|
+
data: [CmsContentEntry!]
|
|
174
222
|
error: CmsError
|
|
175
223
|
}
|
|
176
224
|
|
|
@@ -191,20 +239,20 @@ const createContentEntriesSchema = ({
|
|
|
191
239
|
query: String
|
|
192
240
|
fields: [String!]
|
|
193
241
|
limit: Int
|
|
194
|
-
): CmsContentEntriesResponse
|
|
242
|
+
): CmsContentEntriesResponse!
|
|
195
243
|
|
|
196
244
|
# Get content entry meta data
|
|
197
|
-
getContentEntry(entry: CmsModelEntryInput!): CmsContentEntryResponse
|
|
245
|
+
getContentEntry(entry: CmsModelEntryInput!): CmsContentEntryResponse!
|
|
198
246
|
|
|
199
|
-
getLatestContentEntry(entry: CmsModelEntryInput!): CmsContentEntryResponse
|
|
200
|
-
getPublishedContentEntry(entry: CmsModelEntryInput!): CmsContentEntryResponse
|
|
247
|
+
getLatestContentEntry(entry: CmsModelEntryInput!): CmsContentEntryResponse!
|
|
248
|
+
getPublishedContentEntry(entry: CmsModelEntryInput!): CmsContentEntryResponse!
|
|
201
249
|
|
|
202
250
|
# Get content entries meta data
|
|
203
|
-
getContentEntries(entries: [CmsModelEntryInput!]!): CmsContentEntriesResponse
|
|
204
|
-
getLatestContentEntries(entries: [CmsModelEntryInput!]!): CmsContentEntriesResponse
|
|
251
|
+
getContentEntries(entries: [CmsModelEntryInput!]!): CmsContentEntriesResponse!
|
|
252
|
+
getLatestContentEntries(entries: [CmsModelEntryInput!]!): CmsContentEntriesResponse!
|
|
205
253
|
getPublishedContentEntries(
|
|
206
254
|
entries: [CmsModelEntryInput!]!
|
|
207
|
-
): CmsContentEntriesResponse
|
|
255
|
+
): CmsContentEntriesResponse!
|
|
208
256
|
}
|
|
209
257
|
`,
|
|
210
258
|
resolvers: {
|
|
@@ -224,15 +272,15 @@ const createContentEntriesSchema = ({
|
|
|
224
272
|
if (!entry) {
|
|
225
273
|
return null;
|
|
226
274
|
}
|
|
227
|
-
return
|
|
228
|
-
id: entry.id,
|
|
229
|
-
entryId: entry.entryId,
|
|
230
|
-
title: (0, _getEntryTitle.getEntryTitle)(model, entry)
|
|
231
|
-
};
|
|
275
|
+
return createCmsEntryRecord(model, entry);
|
|
232
276
|
} catch (ex) {
|
|
233
277
|
return null;
|
|
234
278
|
}
|
|
235
|
-
}
|
|
279
|
+
},
|
|
280
|
+
description: createResolveDescription()
|
|
281
|
+
},
|
|
282
|
+
CmsPublishedContentEntry: {
|
|
283
|
+
description: createResolveDescription()
|
|
236
284
|
},
|
|
237
285
|
Query: {
|
|
238
286
|
async searchContentEntries(_, args, context) {
|
|
@@ -253,23 +301,12 @@ const createContentEntriesSchema = ({
|
|
|
253
301
|
fields: fields || []
|
|
254
302
|
});
|
|
255
303
|
return items.map(entry => {
|
|
256
|
-
return
|
|
257
|
-
id: entry.id,
|
|
258
|
-
entryId: entry.entryId,
|
|
259
|
-
model: {
|
|
260
|
-
modelId: model.modelId,
|
|
261
|
-
name: model.name
|
|
262
|
-
},
|
|
263
|
-
status: entry.status,
|
|
264
|
-
title: (0, _getEntryTitle.getEntryTitle)(model, entry),
|
|
265
|
-
// We need `savedOn` to sort entries from latest to oldest
|
|
266
|
-
savedOn: entry.savedOn
|
|
267
|
-
};
|
|
304
|
+
return createCmsEntryRecord(model, entry);
|
|
268
305
|
});
|
|
269
306
|
});
|
|
270
307
|
try {
|
|
271
308
|
const entries = await Promise.all(getters).then(results => results.reduce((result, item) => result.concat(item), []));
|
|
272
|
-
return new _handlerGraphql.Response(entries.sort((a, b) =>
|
|
309
|
+
return new _handlerGraphql.Response(entries.sort((a, b) => b.savedOn.getTime() - a.savedOn.getTime()).slice(0, limit));
|
|
273
310
|
} catch (ex) {
|
|
274
311
|
return new _handlerGraphql.ErrorResponse(ex);
|
|
275
312
|
}
|