@webiny/api-headless-cms 5.34.8 → 5.35.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/context.js +47 -68
- package/context.js.map +1 -1
- package/crud/contentEntry/afterDelete.js +0 -5
- package/crud/contentEntry/afterDelete.js.map +1 -1
- package/crud/contentEntry/beforeCreate.js +0 -3
- package/crud/contentEntry/beforeCreate.js.map +1 -1
- package/crud/contentEntry/beforeUpdate.js +0 -3
- package/crud/contentEntry/beforeUpdate.js.map +1 -1
- package/crud/contentEntry/entryDataValidation.js +1 -40
- package/crud/contentEntry/entryDataValidation.js.map +1 -1
- package/crud/contentEntry/markLockedFields.d.ts +1 -1
- package/crud/contentEntry/markLockedFields.js +5 -26
- package/crud/contentEntry/markLockedFields.js.map +1 -1
- package/crud/contentEntry/referenceFieldsMapping.js +39 -66
- package/crud/contentEntry/referenceFieldsMapping.js.map +1 -1
- package/crud/contentEntry/searchableFields.js +1 -12
- package/crud/contentEntry/searchableFields.js.map +1 -1
- package/crud/contentEntry.crud.d.ts +5 -2
- package/crud/contentEntry.crud.js +859 -941
- package/crud/contentEntry.crud.js.map +1 -1
- package/crud/contentModel/afterCreate.js +0 -2
- package/crud/contentModel/afterCreate.js.map +1 -1
- package/crud/contentModel/afterCreateFrom.js +0 -2
- package/crud/contentModel/afterCreateFrom.js.map +1 -1
- package/crud/contentModel/afterDelete.js +0 -2
- package/crud/contentModel/afterDelete.js.map +1 -1
- package/crud/contentModel/afterUpdate.js +0 -2
- package/crud/contentModel/afterUpdate.js.map +1 -1
- package/crud/contentModel/beforeCreate.js +39 -105
- package/crud/contentModel/beforeCreate.js.map +1 -1
- package/crud/contentModel/beforeDelete.d.ts +1 -1
- package/crud/contentModel/beforeDelete.js +1 -15
- package/crud/contentModel/beforeDelete.js.map +1 -1
- package/crud/contentModel/beforeUpdate.js +31 -8
- 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/contentModelManagerFactory.js +0 -7
- package/crud/contentModel/contentModelManagerFactory.js.map +1 -1
- package/crud/contentModel/createFieldStorageId.js +0 -3
- package/crud/contentModel/createFieldStorageId.js.map +1 -1
- 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/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/validateLayout.js +0 -8
- package/crud/contentModel/validateLayout.js.map +1 -1
- package/crud/contentModel/validateModel.d.ts +1 -0
- package/crud/contentModel/validateModel.js +0 -8
- package/crud/contentModel/validateModel.js.map +1 -1
- package/crud/contentModel/validateModelFields.d.ts +2 -1
- package/crud/contentModel/validateModelFields.js +25 -133
- package/crud/contentModel/validateModelFields.js.map +1 -1
- package/crud/contentModel/validation.d.ts +551 -0
- package/crud/contentModel/validation.js +145 -0
- package/crud/contentModel/validation.js.map +1 -0
- package/crud/contentModel.crud.js +354 -373
- package/crud/contentModel.crud.js.map +1 -1
- package/crud/contentModelGroup/beforeCreate.js +0 -12
- package/crud/contentModelGroup/beforeCreate.js.map +1 -1
- package/crud/contentModelGroup/beforeDelete.js +0 -8
- package/crud/contentModelGroup/beforeDelete.js.map +1 -1
- package/crud/contentModelGroup/beforeUpdate.js +0 -5
- package/crud/contentModelGroup/beforeUpdate.js.map +1 -1
- package/crud/contentModelGroup/validation.d.ts +30 -0
- package/crud/contentModelGroup/validation.js +34 -0
- package/crud/contentModelGroup/validation.js.map +1 -0
- package/crud/contentModelGroup.crud.js +177 -221
- package/crud/contentModelGroup.crud.js.map +1 -1
- package/crud/settings.crud.d.ts +1 -1
- package/crud/settings.crud.js +5 -22
- package/crud/settings.crud.js.map +1 -1
- package/crud/system.crud.js +1 -96
- package/crud/system.crud.js.map +1 -1
- package/fieldConverters/CmsModelDefaultFieldConverterPlugin.js +0 -13
- package/fieldConverters/CmsModelDefaultFieldConverterPlugin.js.map +1 -1
- package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js +0 -36
- package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js.map +1 -1
- package/fieldConverters/CmsModelObjectFieldConverterPlugin.js +0 -53
- package/fieldConverters/CmsModelObjectFieldConverterPlugin.js.map +1 -1
- package/fieldConverters/index.js +0 -5
- package/fieldConverters/index.js.map +1 -1
- package/graphql/buildSchemaPlugins.d.ts +2 -2
- package/graphql/buildSchemaPlugins.js +4 -9
- package/graphql/buildSchemaPlugins.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 +2 -6
- 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 +2 -9
- 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 -173
- 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/index.d.ts +1 -1
- package/graphql/index.js +0 -5
- package/graphql/index.js.map +1 -1
- package/graphql/schema/baseContentSchema.d.ts +2 -2
- package/graphql/schema/baseContentSchema.js +5 -19
- package/graphql/schema/baseContentSchema.js.map +1 -1
- package/graphql/schema/baseSchema.d.ts +1 -1
- package/graphql/schema/baseSchema.js +5 -10
- package/graphql/schema/baseSchema.js.map +1 -1
- package/graphql/schema/contentEntries.d.ts +2 -2
- package/graphql/schema/contentEntries.js +98 -100
- package/graphql/schema/contentEntries.js.map +1 -1
- package/graphql/schema/contentModelGroups.d.ts +2 -2
- package/graphql/schema/contentModelGroups.js +12 -29
- package/graphql/schema/contentModelGroups.js.map +1 -1
- package/graphql/schema/contentModels.d.ts +2 -2
- package/graphql/schema/contentModels.js +28 -31
- package/graphql/schema/contentModels.js.map +1 -1
- package/graphql/schema/createFieldResolvers.js +7 -29
- package/graphql/schema/createFieldResolvers.js.map +1 -1
- package/graphql/schema/createManageResolvers.d.ts +1 -1
- package/graphql/schema/createManageResolvers.js +33 -43
- package/graphql/schema/createManageResolvers.js.map +1 -1
- package/graphql/schema/createManageSDL.d.ts +1 -0
- package/graphql/schema/createManageSDL.js +56 -63
- package/graphql/schema/createManageSDL.js.map +1 -1
- package/graphql/schema/createPreviewResolvers.js +3 -17
- package/graphql/schema/createPreviewResolvers.js.map +1 -1
- package/graphql/schema/createReadResolvers.js +4 -18
- package/graphql/schema/createReadResolvers.js.map +1 -1
- package/graphql/schema/createReadSDL.d.ts +1 -0
- package/graphql/schema/createReadSDL.js +24 -32
- package/graphql/schema/createReadSDL.js.map +1 -1
- package/graphql/schema/resolvers/commonFieldResolvers.d.ts +3 -2
- package/graphql/schema/resolvers/commonFieldResolvers.js +2 -3
- package/graphql/schema/resolvers/commonFieldResolvers.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveCreate.js +0 -3
- package/graphql/schema/resolvers/manage/resolveCreate.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveCreateFrom.js +0 -3
- package/graphql/schema/resolvers/manage/resolveCreateFrom.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveDelete.js +0 -6
- package/graphql/schema/resolvers/manage/resolveDelete.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveGet.js +0 -16
- package/graphql/schema/resolvers/manage/resolveGet.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveGetByIds.js +0 -3
- package/graphql/schema/resolvers/manage/resolveGetByIds.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveGetRevisions.js +0 -3
- package/graphql/schema/resolvers/manage/resolveGetRevisions.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveList.js +0 -3
- package/graphql/schema/resolvers/manage/resolveList.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolvePublish.js +0 -3
- package/graphql/schema/resolvers/manage/resolvePublish.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveRepublish.js +0 -3
- package/graphql/schema/resolvers/manage/resolveRepublish.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveUnpublish.js +0 -3
- package/graphql/schema/resolvers/manage/resolveUnpublish.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveUpdate.js +0 -3
- package/graphql/schema/resolvers/manage/resolveUpdate.js.map +1 -1
- package/graphql/schema/resolvers/preview/resolveGet.js +0 -8
- package/graphql/schema/resolvers/preview/resolveGet.js.map +1 -1
- package/graphql/schema/resolvers/preview/resolveList.js +0 -3
- package/graphql/schema/resolvers/preview/resolveList.js.map +1 -1
- package/graphql/schema/resolvers/read/resolveGet.js +0 -8
- package/graphql/schema/resolvers/read/resolveGet.js.map +1 -1
- package/graphql/schema/resolvers/read/resolveList.js +0 -3
- package/graphql/schema/resolvers/read/resolveList.js.map +1 -1
- package/graphql/schema/schemaPlugins.d.ts +2 -2
- package/graphql/schema/schemaPlugins.js +21 -30
- package/graphql/schema/schemaPlugins.js.map +1 -1
- package/graphql/system.js +55 -87
- package/graphql/system.js.map +1 -1
- package/graphqlFields/boolean.js +0 -12
- package/graphqlFields/boolean.js.map +1 -1
- package/graphqlFields/datetime.js +0 -17
- package/graphqlFields/datetime.js.map +1 -1
- package/graphqlFields/dynamicZone/dynamicZoneField.d.ts +1 -1
- package/graphqlFields/dynamicZone/dynamicZoneField.js +57 -48
- package/graphqlFields/dynamicZone/dynamicZoneField.js.map +1 -1
- package/graphqlFields/dynamicZone/dynamicZoneStorage.js +2 -18
- package/graphqlFields/dynamicZone/dynamicZoneStorage.js.map +1 -1
- package/graphqlFields/dynamicZone/index.js +0 -2
- package/graphqlFields/dynamicZone/index.js.map +1 -1
- package/graphqlFields/file.js +0 -8
- package/graphqlFields/file.js.map +1 -1
- package/graphqlFields/helpers.js +0 -10
- package/graphqlFields/helpers.js.map +1 -1
- package/graphqlFields/index.js +0 -12
- package/graphqlFields/index.js.map +1 -1
- package/graphqlFields/longText.js +0 -10
- package/graphqlFields/longText.js.map +1 -1
- package/graphqlFields/number.js +0 -12
- package/graphqlFields/number.js.map +1 -1
- package/graphqlFields/object.js +21 -38
- package/graphqlFields/object.js.map +1 -1
- package/graphqlFields/ref.js +59 -65
- package/graphqlFields/ref.js.map +1 -1
- package/graphqlFields/richText.js +0 -9
- package/graphqlFields/richText.js.map +1 -1
- package/graphqlFields/text.js +0 -11
- package/graphqlFields/text.js.map +1 -1
- package/index.d.ts +4 -2
- package/index.js +26 -22
- package/index.js.map +1 -1
- package/modelManager/DefaultCmsModelManager.js +0 -16
- package/modelManager/DefaultCmsModelManager.js.map +1 -1
- package/modelManager/index.js +0 -4
- package/modelManager/index.js.map +1 -1
- package/package.json +26 -28
- package/parameters/context.js +0 -4
- package/parameters/context.js.map +1 -1
- package/parameters/header.js +0 -11
- package/parameters/header.js.map +1 -1
- package/parameters/index.js +0 -8
- package/parameters/index.js.map +1 -1
- package/parameters/manual.js +1 -8
- package/parameters/manual.js.map +1 -1
- package/parameters/path.js +0 -11
- package/parameters/path.js.map +1 -1
- package/plugins/CmsGraphQLSchemaPlugin.d.ts +5 -0
- package/plugins/CmsGraphQLSchemaPlugin.js +12 -0
- package/plugins/CmsGraphQLSchemaPlugin.js.map +1 -0
- package/plugins/CmsGraphQLSchemaSorterPlugin.js +0 -10
- package/plugins/CmsGraphQLSchemaSorterPlugin.js.map +1 -1
- package/plugins/CmsGroupPlugin.js +0 -8
- package/plugins/CmsGroupPlugin.js.map +1 -1
- package/plugins/CmsModelFieldConverterPlugin.js +0 -5
- package/plugins/CmsModelFieldConverterPlugin.js.map +1 -1
- package/plugins/CmsModelPlugin.d.ts +21 -3
- package/plugins/CmsModelPlugin.js +30 -40
- package/plugins/CmsModelPlugin.js.map +1 -1
- package/plugins/CmsParametersPlugin.js +0 -7
- package/plugins/CmsParametersPlugin.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/StorageTransformPlugin.js +0 -9
- package/plugins/StorageTransformPlugin.js.map +1 -1
- package/plugins/index.d.ts +2 -0
- package/plugins/index.js +22 -12
- package/plugins/index.js.map +1 -1
- package/storage/default.js +0 -3
- package/storage/default.js.map +1 -1
- package/storage/object.js +0 -19
- package/storage/object.js.map +1 -1
- package/types.d.ts +173 -79
- package/types.js +23 -73
- package/types.js.map +1 -1
- package/utils/access.js +11 -25
- package/utils/access.js.map +1 -1
- package/utils/converters/Converter.js +0 -13
- package/utils/converters/Converter.js.map +1 -1
- package/utils/converters/ConverterCollection.js +9 -33
- package/utils/converters/ConverterCollection.js.map +1 -1
- package/utils/converters/valueKeyStorageConverter.d.ts +1 -5
- package/utils/converters/valueKeyStorageConverter.js +21 -44
- package/utils/converters/valueKeyStorageConverter.js.map +1 -1
- package/utils/createTypeFromFields.d.ts +1 -0
- package/utils/createTypeFromFields.js +11 -20
- package/utils/createTypeFromFields.js.map +1 -1
- package/utils/createTypeName.d.ts +0 -2
- package/utils/createTypeName.js +2 -19
- package/utils/createTypeName.js.map +1 -1
- package/utils/entryStorage.js +10 -26
- package/utils/entryStorage.js.map +1 -1
- package/utils/filterAsync.js +0 -5
- package/utils/filterAsync.js.map +1 -1
- package/utils/getBaseFieldType.js +0 -2
- package/utils/getBaseFieldType.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/getEntryTitle.js +0 -9
- package/utils/getEntryTitle.js.map +1 -1
- package/utils/getSchemaFromFieldPlugins.d.ts +4 -7
- package/utils/getSchemaFromFieldPlugins.js +23 -19
- package/utils/getSchemaFromFieldPlugins.js.map +1 -1
- 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 +0 -8
- package/utils/ownership.js.map +1 -1
- package/utils/permissions.js +8 -23
- package/utils/permissions.js.map +1 -1
- package/utils/renderFields.d.ts +2 -1
- package/utils/renderFields.js +8 -10
- package/utils/renderFields.js.map +1 -1
- package/utils/renderGetFilterFields.js +0 -13
- package/utils/renderGetFilterFields.js.map +1 -1
- package/utils/renderInputFields.d.ts +2 -1
- package/utils/renderInputFields.js +4 -9
- package/utils/renderInputFields.js.map +1 -1
- package/utils/renderListFilterFields.js +1 -10
- package/utils/renderListFilterFields.js.map +1 -1
- package/utils/renderSortEnum.js +0 -9
- package/utils/renderSortEnum.js.map +1 -1
- package/utils/toSlug.js +0 -4
- package/utils/toSlug.js.map +1 -1
- package/validators/dateGte.js +0 -7
- package/validators/dateGte.js.map +1 -1
- package/validators/dateLte.js +0 -7
- package/validators/dateLte.js.map +1 -1
- package/validators/dynamicZone.js +0 -4
- package/validators/dynamicZone.js.map +1 -1
- package/validators/gte.js +0 -8
- package/validators/gte.js.map +1 -1
- package/validators/in.js +0 -8
- package/validators/in.js.map +1 -1
- package/validators/index.js +0 -16
- package/validators/index.js.map +1 -1
- package/validators/lte.js +0 -8
- package/validators/lte.js.map +1 -1
- package/validators/maxLength.js +0 -8
- package/validators/maxLength.js.map +1 -1
- package/validators/minLength.js +0 -8
- package/validators/minLength.js.map +1 -1
- package/validators/pattern.js +0 -9
- package/validators/pattern.js.map +1 -1
- package/validators/patternPlugins/email.js +0 -2
- package/validators/patternPlugins/email.js.map +1 -1
- package/validators/patternPlugins/index.js +0 -8
- package/validators/patternPlugins/index.js.map +1 -1
- package/validators/patternPlugins/lowerCase.js +0 -2
- package/validators/patternPlugins/lowerCase.js.map +1 -1
- package/validators/patternPlugins/lowerCaseSpace.js +0 -2
- package/validators/patternPlugins/lowerCaseSpace.js.map +1 -1
- package/validators/patternPlugins/upperCase.js +0 -2
- package/validators/patternPlugins/upperCase.js.map +1 -1
- package/validators/patternPlugins/upperCaseSpace.js +0 -2
- package/validators/patternPlugins/upperCaseSpace.js.map +1 -1
- package/validators/patternPlugins/url.js +0 -2
- package/validators/patternPlugins/url.js.map +1 -1
- package/validators/required.js +0 -5
- package/validators/required.js.map +1 -1
- package/validators/timeGte.js +0 -8
- package/validators/timeGte.js.map +1 -1
- package/validators/timeLte.js +0 -8
- package/validators/timeLte.js.map +1 -1
- package/validators/unique.js +0 -7
- package/validators/unique.js.map +1 -1
|
@@ -4,20 +4,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.generateSchema = void 0;
|
|
7
|
-
|
|
8
|
-
var _handlerGraphql = require("@webiny/handler-graphql");
|
|
9
|
-
|
|
10
7
|
var _buildSchemaPlugins = require("./buildSchemaPlugins");
|
|
11
|
-
|
|
12
8
|
var _createExecutableSchema = require("./createExecutableSchema");
|
|
13
|
-
|
|
9
|
+
var _plugins = require("../plugins");
|
|
14
10
|
const generateSchema = async params => {
|
|
15
11
|
const {
|
|
16
12
|
context,
|
|
17
13
|
models
|
|
18
14
|
} = params;
|
|
19
15
|
let generatedSchemaPlugins = [];
|
|
20
|
-
|
|
21
16
|
try {
|
|
22
17
|
generatedSchemaPlugins = await (0, _buildSchemaPlugins.buildSchemaPlugins)({
|
|
23
18
|
context,
|
|
@@ -27,12 +22,10 @@ const generateSchema = async params => {
|
|
|
27
22
|
console.log(`Error while building schema plugins.`);
|
|
28
23
|
throw ex;
|
|
29
24
|
}
|
|
30
|
-
|
|
31
25
|
context.plugins.register(generatedSchemaPlugins);
|
|
32
|
-
const schemaPlugins = context.plugins.byType(
|
|
26
|
+
const schemaPlugins = context.plugins.byType(_plugins.CmsGraphQLSchemaPlugin.type);
|
|
33
27
|
return (0, _createExecutableSchema.createExecutableSchema)({
|
|
34
28
|
plugins: schemaPlugins
|
|
35
29
|
});
|
|
36
30
|
};
|
|
37
|
-
|
|
38
31
|
exports.generateSchema = generateSchema;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["generateSchema","params","context","models","generatedSchemaPlugins","buildSchemaPlugins","ex","console","log","plugins","register","schemaPlugins","byType","
|
|
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,MAA8B,IAAsB;EAChF,MAAM;IAAEQ;EAAoB,CAAC,GAAGR,MAAM;EACtC,MAAMS,eAAe,GAAG,MAAMD,mBAAmB,EAAE;EACnD,IAAI,CAACC,eAAe,EAAE;IAClB,OAAO,SAAS;EACpB;EACA,OAAOA,eAAe,CAACC,WAAW,EAAE;AACxC,CAAC;;AAED;AACA;AACA;AACA;AACO,MAAMC,SAAS,GAAG,MAAOX,MAAuB,IAA6B;EAChF,MAAM;IAAEY;EAAQ,CAAC,GAAGZ,MAAM;EAE1B,MAAMa,OAAO,GAAGd,eAAe,CAACC,MAAM,CAAC;EAEvC,MAAMc,QAAQ,GAAG,MAAMP,gBAAgB,CAACP,MAAM,CAAC;EA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,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"}
|
|
@@ -1,196 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.graphQLHandlerFactory = void 0;
|
|
9
|
-
|
|
10
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
-
|
|
12
|
-
var _apiSecurity = require("@webiny/api-security");
|
|
13
|
-
|
|
14
8
|
var _debugPlugins = _interopRequireDefault(require("@webiny/handler-graphql/debugPlugins"));
|
|
15
|
-
|
|
16
|
-
var _processRequestBody = _interopRequireDefault(require("@webiny/handler-graphql/processRequestBody"));
|
|
17
|
-
|
|
18
9
|
var _handler = require("@webiny/handler");
|
|
19
|
-
|
|
20
|
-
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
21
|
-
|
|
22
|
-
var _codeFrame = _interopRequireDefault(require("code-frame"));
|
|
23
|
-
|
|
24
|
-
var _generateSchema = require("./generateSchema");
|
|
25
|
-
|
|
26
|
-
// @ts-ignore `code-frame` has no types
|
|
27
|
-
const createRequestBody = body => {
|
|
28
|
-
/**
|
|
29
|
-
* We are trusting that the body payload is correct.
|
|
30
|
-
* The `processRequestBody` will fail if it is not.
|
|
31
|
-
*/
|
|
32
|
-
return typeof body === "string" ? JSON.parse(body) : body;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const schemaList = new Map();
|
|
36
|
-
|
|
37
|
-
const generateCacheKey = async args => {
|
|
38
|
-
const {
|
|
39
|
-
context,
|
|
40
|
-
locale,
|
|
41
|
-
type
|
|
42
|
-
} = args;
|
|
43
|
-
const lastModelChange = await context.cms.getModelLastChange();
|
|
44
|
-
return [locale.code, type, lastModelChange.toISOString()].join("#");
|
|
45
|
-
};
|
|
46
|
-
/**
|
|
47
|
-
* Gets an existing schema or rewrites existing one or creates a completely new one
|
|
48
|
-
* depending on the schemaId created from type and locale parameters
|
|
49
|
-
*/
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const getSchema = async params => {
|
|
53
|
-
const {
|
|
54
|
-
context,
|
|
55
|
-
type,
|
|
56
|
-
locale
|
|
57
|
-
} = params;
|
|
58
|
-
const tenantId = context.tenancy.getCurrentTenant().id;
|
|
59
|
-
const id = `${tenantId}#${type}#${locale.code}`;
|
|
60
|
-
const cacheKey = await generateCacheKey(params);
|
|
61
|
-
const cachedSchema = schemaList.get(id);
|
|
62
|
-
|
|
63
|
-
if ((cachedSchema === null || cachedSchema === void 0 ? void 0 : cachedSchema.key) === cacheKey) {
|
|
64
|
-
return cachedSchema.schema;
|
|
65
|
-
} // Load model data
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
context.security.disableAuthorization();
|
|
69
|
-
const models = (await context.cms.listModels()).filter(model => model.isPrivate !== true);
|
|
70
|
-
context.security.enableAuthorization();
|
|
71
|
-
|
|
72
|
-
try {
|
|
73
|
-
const schema = await (0, _generateSchema.generateSchema)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
|
|
74
|
-
models
|
|
75
|
-
}));
|
|
76
|
-
schemaList.set(id, {
|
|
77
|
-
key: cacheKey,
|
|
78
|
-
schema
|
|
79
|
-
});
|
|
80
|
-
return schema;
|
|
81
|
-
} catch (err) {
|
|
82
|
-
if (!Array.isArray(err.locations)) {
|
|
83
|
-
throw new _error.default({
|
|
84
|
-
message: err.message,
|
|
85
|
-
code: err.code || "INVALID_GRAPHQL_SCHEMA_LOCATIONS",
|
|
86
|
-
data: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, err.data || {}), {}, {
|
|
87
|
-
locations: err.locations
|
|
88
|
-
})
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const [location] = err.locations;
|
|
93
|
-
throw new _error.default({
|
|
94
|
-
code: "INVALID_GRAPHQL_SCHEMA",
|
|
95
|
-
message: err.message,
|
|
96
|
-
data: {
|
|
97
|
-
invalidSegment: (0, _codeFrame.default)(err.source.body, location.line, location.column, {
|
|
98
|
-
frameSize: 15
|
|
99
|
-
})
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
const checkEndpointAccess = async context => {
|
|
106
|
-
const permission = await context.security.getPermission(`cms.endpoint.${context.cms.type}`);
|
|
107
|
-
|
|
108
|
-
if (!permission) {
|
|
109
|
-
throw new _apiSecurity.NotAuthorizedError({
|
|
110
|
-
data: {
|
|
111
|
-
reason: `Not allowed to access "${context.cms.type}" endpoint.`
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
const formatErrorPayload = error => {
|
|
118
|
-
if (error instanceof _error.default) {
|
|
119
|
-
return JSON.stringify({
|
|
120
|
-
type: "CmsGraphQLWebinyError",
|
|
121
|
-
message: error.message,
|
|
122
|
-
code: error.code,
|
|
123
|
-
data: error.data
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
return JSON.stringify({
|
|
128
|
-
type: "Error",
|
|
129
|
-
name: error.name,
|
|
130
|
-
message: error.message,
|
|
131
|
-
stack: error.stack
|
|
132
|
-
});
|
|
133
|
-
};
|
|
134
|
-
|
|
10
|
+
var _handleRequest = require("./handleRequest");
|
|
135
11
|
const cmsRoutes = new _handler.RoutePlugin(({
|
|
136
12
|
onPost,
|
|
137
13
|
onOptions,
|
|
138
14
|
context
|
|
139
15
|
}) => {
|
|
140
16
|
onPost("/cms/:type(^manage|preview|read$)/:locale", async (request, reply) => {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
error: {
|
|
147
|
-
message: ex.message || "Not authorized!",
|
|
148
|
-
code: ex.code || "SECURITY_NOT_AUTHORIZED",
|
|
149
|
-
data: ex.data || null,
|
|
150
|
-
stack: null
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
let schema;
|
|
156
|
-
|
|
157
|
-
try {
|
|
158
|
-
schema = await getSchema({
|
|
159
|
-
context,
|
|
160
|
-
locale: context.cms.getLocale(),
|
|
161
|
-
type: context.cms.type
|
|
162
|
-
});
|
|
163
|
-
} catch (ex) {
|
|
164
|
-
console.error(`Error while generating the schema.`);
|
|
165
|
-
console.error(formatErrorPayload(ex));
|
|
166
|
-
throw ex;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
let body = [];
|
|
170
|
-
|
|
171
|
-
try {
|
|
172
|
-
body = createRequestBody(request.body);
|
|
173
|
-
} catch (ex) {
|
|
174
|
-
console.error(`Error while creating the body request.`);
|
|
175
|
-
console.error(formatErrorPayload(ex));
|
|
176
|
-
throw ex;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
try {
|
|
180
|
-
const result = await (0, _processRequestBody.default)(body, schema, context);
|
|
181
|
-
return reply.code(200).send(result);
|
|
182
|
-
} catch (ex) {
|
|
183
|
-
console.error(`Error while processing the body request.`);
|
|
184
|
-
console.error(formatErrorPayload(ex));
|
|
185
|
-
throw ex;
|
|
186
|
-
}
|
|
17
|
+
return (0, _handleRequest.handleRequest)({
|
|
18
|
+
context,
|
|
19
|
+
request,
|
|
20
|
+
reply
|
|
21
|
+
});
|
|
187
22
|
});
|
|
188
23
|
onOptions("/cms/:type(^manage|preview|read$)/:locale", async (_, reply) => {
|
|
189
24
|
return reply.status(204).send({}).hijack();
|
|
190
25
|
});
|
|
191
26
|
});
|
|
192
27
|
cmsRoutes.name = "headless-cms.graphql.route.default";
|
|
193
|
-
|
|
194
28
|
const graphQLHandlerFactory = ({
|
|
195
29
|
debug
|
|
196
30
|
}) => {
|
|
@@ -198,5 +32,4 @@ const graphQLHandlerFactory = ({
|
|
|
198
32
|
type: "wcp-telemetry-tracker"
|
|
199
33
|
}];
|
|
200
34
|
};
|
|
201
|
-
|
|
202
35
|
exports.graphQLHandlerFactory = graphQLHandlerFactory;
|
|
@@ -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","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.error(`Error while generating the schema.`);\n console.error(formatErrorPayload(ex));\n throw ex;\n }\n\n let body: GraphQLRequestBody | GraphQLRequestBody[] = [];\n try {\n body = 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 try {\n const result = await processRequestBody(body, schema, context);\n return reply.code(200).send(result);\n } catch (ex) {\n console.error(`Error while processing the body request.`);\n console.error(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,IAAD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CAFQ,CAAT;AAGH,CAnDiB,CAAlB;AAqDAd,SAAS,CAACF,IAAV,GAAiB,oCAAjB;;AAEO,MAAMiB,qBAAqB,GAAG,CAAC;EAAEC;AAAF,CAAD,KAA8D;EAC/F,OAAO,CACH,IAAIA,KAAK,GAAG,IAAAC,qBAAA,GAAH,GAAoB,EAA7B,CADG,EAEHjB,SAFG,EAGH;IACIpD,IAAI,EAAE;EADV,CAHG,CAAP;AAOH,CARM"}
|
|
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,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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"}
|
package/graphql/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { GraphQLHandlerFactoryParams } from "./graphQLHandlerFactory";
|
|
2
2
|
export declare type CreateGraphQLParams = GraphQLHandlerFactoryParams;
|
|
3
|
-
export declare const createGraphQL: (params: CreateGraphQLParams) => (import("@webiny/
|
|
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
|
@@ -4,15 +4,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.createGraphQL = void 0;
|
|
7
|
-
|
|
8
7
|
var _system = require("./system");
|
|
9
|
-
|
|
10
8
|
var _graphQLHandlerFactory = require("./graphQLHandlerFactory");
|
|
11
|
-
|
|
12
9
|
var _baseSchema = require("./schema/baseSchema");
|
|
13
|
-
|
|
14
10
|
const createGraphQL = params => {
|
|
15
11
|
return [...(0, _baseSchema.createBaseSchema)(), (0, _system.createSystemSchemaPlugin)(), (0, _graphQLHandlerFactory.graphQLHandlerFactory)(params)];
|
|
16
12
|
};
|
|
17
|
-
|
|
18
13
|
exports.createGraphQL = createGraphQL;
|
package/graphql/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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":"
|
|
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,7 +1,7 @@
|
|
|
1
1
|
import { CmsContext } from "../../types";
|
|
2
|
-
import {
|
|
2
|
+
import { CmsGraphQLSchemaPlugin } from "../../plugins";
|
|
3
3
|
interface Params {
|
|
4
4
|
context: CmsContext;
|
|
5
5
|
}
|
|
6
|
-
export declare const createBaseContentSchema: ({ context }: Params) =>
|
|
6
|
+
export declare const createBaseContentSchema: ({ context }: Params) => CmsGraphQLSchemaPlugin;
|
|
7
7
|
export {};
|
|
@@ -1,26 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.createBaseContentSchema = void 0;
|
|
9
|
-
|
|
10
8
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
-
|
|
12
9
|
var _builtInTypes = require("@webiny/handler-graphql/builtInTypes");
|
|
13
|
-
|
|
14
|
-
var _GraphQLSchemaPlugin = require("@webiny/handler-graphql/plugins/GraphQLSchemaPlugin");
|
|
15
|
-
|
|
10
|
+
var _plugins = require("../../plugins");
|
|
16
11
|
const createBaseContentSchema = ({
|
|
17
12
|
context
|
|
18
13
|
}) => {
|
|
19
14
|
const scalars = context.plugins.byType("graphql-scalar").map(item => item.scalar);
|
|
20
|
-
const plugin = new
|
|
21
|
-
typeDefs:
|
|
22
|
-
/* GraphQL */
|
|
23
|
-
`
|
|
15
|
+
const plugin = new _plugins.CmsGraphQLSchemaPlugin({
|
|
16
|
+
typeDefs: /* GraphQL */`
|
|
24
17
|
${scalars.map(scalar => `scalar ${scalar.name}`).join(" ")}
|
|
25
18
|
scalar JSON
|
|
26
19
|
scalar Long
|
|
@@ -38,13 +31,7 @@ const createBaseContentSchema = ({
|
|
|
38
31
|
_empty: String
|
|
39
32
|
}
|
|
40
33
|
|
|
41
|
-
type
|
|
42
|
-
id: String
|
|
43
|
-
displayName: String
|
|
44
|
-
type: String
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
type CmsOwnedBy {
|
|
34
|
+
type CmsIdentity {
|
|
48
35
|
id: String
|
|
49
36
|
displayName: String
|
|
50
37
|
type: String
|
|
@@ -73,8 +60,7 @@ const createBaseContentSchema = ({
|
|
|
73
60
|
}
|
|
74
61
|
})
|
|
75
62
|
});
|
|
76
|
-
plugin.name = `headless-cms.graphql.schema.
|
|
63
|
+
plugin.name = `headless-cms.graphql.schema.baseContentSchema`;
|
|
77
64
|
return plugin;
|
|
78
65
|
};
|
|
79
|
-
|
|
80
66
|
exports.createBaseContentSchema = createBaseContentSchema;
|