@webbio/strapi-plugin-page-builder 0.2.2 → 0.2.4
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/README.md +98 -98
- package/admin/src/api/collection-type.ts +110 -110
- package/admin/src/api/has-page-relation.ts +34 -34
- package/admin/src/api/page-type.ts +31 -31
- package/admin/src/api/template.ts +27 -27
- package/admin/src/components/Combobox/index.tsx +77 -77
- package/admin/src/components/Combobox/react-select-custom-styles.tsx +120 -111
- package/admin/src/components/Combobox/styles.ts +22 -22
- package/admin/src/components/ConfirmModal/index.tsx +90 -90
- package/admin/src/components/EditView/CollectionTypeSearch/index.tsx +124 -124
- package/admin/src/components/EditView/CollectionTypeSettings/CreatePageButton/index.tsx +104 -101
- package/admin/src/components/EditView/CollectionTypeSettings/CreatePageButton/styles.ts +19 -19
- package/admin/src/components/EditView/CollectionTypeSettings/index.tsx +74 -74
- package/admin/src/components/EditView/Details/index.tsx +47 -47
- package/admin/src/components/EditView/Details/styles.ts +51 -51
- package/admin/src/components/EditView/PageSettings/index.tsx +104 -104
- package/admin/src/components/EditView/Template/TemplateConfirmModal/index.tsx +36 -36
- package/admin/src/components/EditView/Template/TemplateSelect/index.tsx +69 -69
- package/admin/src/components/EditView/Template/TemplateSelect/use-template-modules.ts +38 -38
- package/admin/src/components/EditView/index.tsx +29 -29
- package/admin/src/components/EditView/page-type-select.tsx +32 -32
- package/admin/src/components/EditView/wrapper.tsx +35 -35
- package/admin/src/components/Initializer/index.tsx +24 -24
- package/admin/src/components/PageTypeFilter/index.tsx +17 -17
- package/admin/src/components/PageTypeFilter/page-type-filter.tsx +130 -130
- package/admin/src/components/PluginIcon/index.tsx +12 -12
- package/admin/src/constants.ts +3 -3
- package/admin/src/index.tsx +59 -59
- package/admin/src/middlewares/index.tsx +37 -37
- package/admin/src/pluginId.ts +5 -5
- package/admin/src/translations/en.json +6 -6
- package/admin/src/translations/nl.json +6 -6
- package/admin/src/utils/getRequestUrl.ts +11 -11
- package/admin/src/utils/getTrad.ts +5 -5
- package/admin/src/utils/hooks/useDebounce.ts +17 -17
- package/admin/src/utils/hooks/useGetLocaleFromUrl.ts +9 -9
- package/admin/src/utils/hooks/usePrevious.ts +12 -12
- package/admin/src/utils/sanitizeModules.ts +43 -10
- package/custom.d.ts +5 -5
- package/dist/package.json +9 -9
- package/dist/server/graphql/page-by-slug.js +9 -9
- package/dist/server/graphql/pages-by-uid.js +14 -14
- package/dist/server/services/builder.js +7 -4
- package/dist/server/services/template.js +1 -2
- package/dist/server/utils/graphql.js +18 -18
- package/dist/server/utils/strapi.js +1 -4
- package/dist/tsconfig.server.tsbuildinfo +1 -1
- package/package.json +71 -71
- package/server/bootstrap/collection-type-lifecycles.ts +47 -47
- package/server/bootstrap/permissions.ts +42 -42
- package/server/bootstrap.ts +198 -198
- package/server/config/index.ts +4 -4
- package/server/content-types/index.ts +1 -1
- package/server/controllers/collection-types.ts +27 -27
- package/server/controllers/index.ts +11 -11
- package/server/controllers/page-type.ts +13 -13
- package/server/controllers/page.ts +9 -9
- package/server/controllers/template.ts +16 -16
- package/server/destroy.ts +5 -5
- package/server/graphql/index.ts +9 -9
- package/server/graphql/page-by-slug.ts +98 -98
- package/server/graphql/page-type.ts +67 -67
- package/server/graphql/pages-by-uid.ts +127 -127
- package/server/index.ts +23 -23
- package/server/middlewares/index.ts +1 -1
- package/server/policies/index.ts +1 -1
- package/server/register.ts +15 -15
- package/server/routes/index.ts +58 -58
- package/server/schema/page-end.json +91 -91
- package/server/schema/page-start.json +87 -87
- package/server/schema/page-type-end.json +43 -43
- package/server/schema/page-type-start.json +38 -38
- package/server/schema/template-start.json +35 -35
- package/server/services/builder.ts +137 -134
- package/server/services/collection-types.ts +88 -88
- package/server/services/index.ts +13 -13
- package/server/services/page-type.ts +26 -26
- package/server/services/page.ts +24 -24
- package/server/services/template.ts +13 -14
- package/server/utils/filter-underscore-arguments.ts +12 -12
- package/server/utils/graphql.ts +113 -113
- package/server/utils/paginationValidation.ts +39 -39
- package/server/utils/reload-strapi-on-load.ts +13 -13
- package/server/utils/strapi.ts +45 -49
- package/shared/utils/constants.ts +4 -4
- package/shared/utils/sleep.ts +1 -1
- package/strapi-admin.js +3 -3
- package/strapi-server.js +3 -3
- package/tsconfig.json +20 -20
- package/tsconfig.server.json +25 -25
- package/dist/server/controllers/platform.js +0 -20
- package/dist/server/schema/platform-start.json +0 -31
- package/dist/server/services/platform.js +0 -36
|
@@ -1,98 +1,98 @@
|
|
|
1
|
-
import { Strapi } from '@strapi/strapi';
|
|
2
|
-
|
|
3
|
-
import { filterUnderscoreArguments } from '../utils/filter-underscore-arguments';
|
|
4
|
-
import { PAGE_UID } from '../../shared/utils/constants';
|
|
5
|
-
|
|
6
|
-
const getPageBySlug = (strapi: Strapi) => {
|
|
7
|
-
const typeDefs = () => {
|
|
8
|
-
return `
|
|
9
|
-
extend type Page {
|
|
10
|
-
collectionType: GenericMorph
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
type Query {
|
|
14
|
-
getPageBySlug(path: String, _locale: String, _publicationState: PublicationState): PageEntity
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
`;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const resolvers = (strapi: Strapi) => {
|
|
21
|
-
const { transformArgs } = strapi.plugin('graphql').service('builders').utils;
|
|
22
|
-
|
|
23
|
-
return {
|
|
24
|
-
Query: {
|
|
25
|
-
getPageBySlug: {
|
|
26
|
-
resolve: async (_parent: any, args: Record<string, any>, ctx: any) => {
|
|
27
|
-
const filteredArgs = {
|
|
28
|
-
...filterUnderscoreArguments(args)
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const { toEntityResponse } = strapi.plugin('graphql').service('format').returnTypes;
|
|
32
|
-
|
|
33
|
-
const getPage = async () => {
|
|
34
|
-
const transformedArgs = transformArgs(filteredArgs, {
|
|
35
|
-
contentType: strapi.contentTypes[PAGE_UID],
|
|
36
|
-
usePagination: false
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
const results = await strapi.entityService?.findMany(PAGE_UID, {
|
|
40
|
-
filters: transformedArgs,
|
|
41
|
-
locale: args._locale,
|
|
42
|
-
publicationState: args._publicationState,
|
|
43
|
-
populate: '*'
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
const entityResponse = toEntityResponse(results?.[0] || {}, {
|
|
47
|
-
args: transformedArgs,
|
|
48
|
-
resourceUID: PAGE_UID
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
if (!entityResponse?.value || Object.keys(entityResponse.value).length === 0) {
|
|
52
|
-
throw new Error(ctx.koaContext.response.message);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const collectionTypeDataFilter = entityResponse?.value?.collectionTypeData?.filter(Boolean);
|
|
56
|
-
|
|
57
|
-
const collectionType: Record<string, any> | null =
|
|
58
|
-
collectionTypeDataFilter.length === 1 ? collectionTypeDataFilter?.[0] : null;
|
|
59
|
-
|
|
60
|
-
const addedAttributes = {
|
|
61
|
-
collectionType: collectionType
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
const result = {
|
|
65
|
-
...entityResponse.value,
|
|
66
|
-
...addedAttributes
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
return result;
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
const results: Record<string, any> = await getPage();
|
|
73
|
-
|
|
74
|
-
if (Object.values(results)?.filter(Boolean).length > 0) {
|
|
75
|
-
return results;
|
|
76
|
-
} else {
|
|
77
|
-
throw new Error(ctx.koaContext.response.message);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
const resolversConfig = {
|
|
86
|
-
'Query.getPageBySlug': {
|
|
87
|
-
auth: false
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
return {
|
|
92
|
-
typeDefs: typeDefs(),
|
|
93
|
-
resolvers: resolvers(strapi),
|
|
94
|
-
resolversConfig
|
|
95
|
-
};
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
export default getPageBySlug;
|
|
1
|
+
import { Strapi } from '@strapi/strapi';
|
|
2
|
+
|
|
3
|
+
import { filterUnderscoreArguments } from '../utils/filter-underscore-arguments';
|
|
4
|
+
import { PAGE_UID } from '../../shared/utils/constants';
|
|
5
|
+
|
|
6
|
+
const getPageBySlug = (strapi: Strapi) => {
|
|
7
|
+
const typeDefs = () => {
|
|
8
|
+
return `
|
|
9
|
+
extend type Page {
|
|
10
|
+
collectionType: GenericMorph
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
type Query {
|
|
14
|
+
getPageBySlug(path: String, _locale: String, _publicationState: PublicationState): PageEntity
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
`;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const resolvers = (strapi: Strapi) => {
|
|
21
|
+
const { transformArgs } = strapi.plugin('graphql').service('builders').utils;
|
|
22
|
+
|
|
23
|
+
return {
|
|
24
|
+
Query: {
|
|
25
|
+
getPageBySlug: {
|
|
26
|
+
resolve: async (_parent: any, args: Record<string, any>, ctx: any) => {
|
|
27
|
+
const filteredArgs = {
|
|
28
|
+
...filterUnderscoreArguments(args)
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const { toEntityResponse } = strapi.plugin('graphql').service('format').returnTypes;
|
|
32
|
+
|
|
33
|
+
const getPage = async () => {
|
|
34
|
+
const transformedArgs = transformArgs(filteredArgs, {
|
|
35
|
+
contentType: strapi.contentTypes[PAGE_UID],
|
|
36
|
+
usePagination: false
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const results = await strapi.entityService?.findMany(PAGE_UID, {
|
|
40
|
+
filters: transformedArgs,
|
|
41
|
+
locale: args._locale,
|
|
42
|
+
publicationState: args._publicationState,
|
|
43
|
+
populate: '*'
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const entityResponse = toEntityResponse(results?.[0] || {}, {
|
|
47
|
+
args: transformedArgs,
|
|
48
|
+
resourceUID: PAGE_UID
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
if (!entityResponse?.value || Object.keys(entityResponse.value).length === 0) {
|
|
52
|
+
throw new Error(ctx.koaContext.response.message);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const collectionTypeDataFilter = entityResponse?.value?.collectionTypeData?.filter(Boolean);
|
|
56
|
+
|
|
57
|
+
const collectionType: Record<string, any> | null =
|
|
58
|
+
collectionTypeDataFilter.length === 1 ? collectionTypeDataFilter?.[0] : null;
|
|
59
|
+
|
|
60
|
+
const addedAttributes = {
|
|
61
|
+
collectionType: collectionType
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const result = {
|
|
65
|
+
...entityResponse.value,
|
|
66
|
+
...addedAttributes
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
return result;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const results: Record<string, any> = await getPage();
|
|
73
|
+
|
|
74
|
+
if (Object.values(results)?.filter(Boolean).length > 0) {
|
|
75
|
+
return results;
|
|
76
|
+
} else {
|
|
77
|
+
throw new Error(ctx.koaContext.response.message);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const resolversConfig = {
|
|
86
|
+
'Query.getPageBySlug': {
|
|
87
|
+
auth: false
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
typeDefs: typeDefs(),
|
|
93
|
+
resolvers: resolvers(strapi),
|
|
94
|
+
resolversConfig
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export default getPageBySlug;
|
|
@@ -1,67 +1,67 @@
|
|
|
1
|
-
import { Common } from '@strapi/strapi';
|
|
2
|
-
import { ICollectionTypeGL } from '../services/collection-types';
|
|
3
|
-
|
|
4
|
-
const pageType = ({ nexus }) => {
|
|
5
|
-
// @ts-ignore service does exist
|
|
6
|
-
const collectionTypes: ICollectionTypeGL[] = strapi.service('plugin::page-builder.collection-types').withPageMorph();
|
|
7
|
-
|
|
8
|
-
// Extends collectiontype types to include extra fields.
|
|
9
|
-
const collectionTypesNexus = collectionTypes.map((collectionType) =>
|
|
10
|
-
nexus.extendType({
|
|
11
|
-
type: collectionType.type,
|
|
12
|
-
definition(t: any) {
|
|
13
|
-
t.string('id', { resolve: (root) => root?.id || null });
|
|
14
|
-
t.string('uid', { resolve: () => collectionType?.uid || null });
|
|
15
|
-
t.field('page', {
|
|
16
|
-
type: 'Page',
|
|
17
|
-
resolve: async (root) => {
|
|
18
|
-
try {
|
|
19
|
-
const results = await strapi.entityService.findOne(
|
|
20
|
-
collectionType.uid as Common.UID.ContentType,
|
|
21
|
-
root?.id,
|
|
22
|
-
{
|
|
23
|
-
populate: '*'
|
|
24
|
-
}
|
|
25
|
-
);
|
|
26
|
-
|
|
27
|
-
if (!results) {
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return results.page?.[0];
|
|
32
|
-
} catch {
|
|
33
|
-
return null;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
})
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
// Extends the page type to include its id.
|
|
42
|
-
const pageTypeExtendNexus = nexus.extendType({
|
|
43
|
-
type: 'Page',
|
|
44
|
-
definition(t: any) {
|
|
45
|
-
t.string('id', { resolve: (root) => root?.id || null });
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
// Extends the inputTypes for collectiontypes so filtering on Page is possible.
|
|
50
|
-
// This however gives a problem when querying, for now we cannot use this.
|
|
51
|
-
// const collectionInputTypesNexus = collectionTypes.map((collectionType) =>
|
|
52
|
-
// nexus.extendInputType({
|
|
53
|
-
// type: collectionType.inputType,
|
|
54
|
-
// definition(t) {
|
|
55
|
-
// t.field('page', {
|
|
56
|
-
// type: 'PageFiltersInput',
|
|
57
|
-
// });
|
|
58
|
-
// }
|
|
59
|
-
// })
|
|
60
|
-
// );
|
|
61
|
-
|
|
62
|
-
return {
|
|
63
|
-
types: [pageTypeExtendNexus, ...collectionTypesNexus]
|
|
64
|
-
};
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
export default pageType;
|
|
1
|
+
import { Common } from '@strapi/strapi';
|
|
2
|
+
import { ICollectionTypeGL } from '../services/collection-types';
|
|
3
|
+
|
|
4
|
+
const pageType = ({ nexus }) => {
|
|
5
|
+
// @ts-ignore service does exist
|
|
6
|
+
const collectionTypes: ICollectionTypeGL[] = strapi.service('plugin::page-builder.collection-types').withPageMorph();
|
|
7
|
+
|
|
8
|
+
// Extends collectiontype types to include extra fields.
|
|
9
|
+
const collectionTypesNexus = collectionTypes.map((collectionType) =>
|
|
10
|
+
nexus.extendType({
|
|
11
|
+
type: collectionType.type,
|
|
12
|
+
definition(t: any) {
|
|
13
|
+
t.string('id', { resolve: (root) => root?.id || null });
|
|
14
|
+
t.string('uid', { resolve: () => collectionType?.uid || null });
|
|
15
|
+
t.field('page', {
|
|
16
|
+
type: 'Page',
|
|
17
|
+
resolve: async (root) => {
|
|
18
|
+
try {
|
|
19
|
+
const results = await strapi.entityService.findOne(
|
|
20
|
+
collectionType.uid as Common.UID.ContentType,
|
|
21
|
+
root?.id,
|
|
22
|
+
{
|
|
23
|
+
populate: '*'
|
|
24
|
+
}
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
if (!results) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return results.page?.[0];
|
|
32
|
+
} catch {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
})
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
// Extends the page type to include its id.
|
|
42
|
+
const pageTypeExtendNexus = nexus.extendType({
|
|
43
|
+
type: 'Page',
|
|
44
|
+
definition(t: any) {
|
|
45
|
+
t.string('id', { resolve: (root) => root?.id || null });
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// Extends the inputTypes for collectiontypes so filtering on Page is possible.
|
|
50
|
+
// This however gives a problem when querying, for now we cannot use this.
|
|
51
|
+
// const collectionInputTypesNexus = collectionTypes.map((collectionType) =>
|
|
52
|
+
// nexus.extendInputType({
|
|
53
|
+
// type: collectionType.inputType,
|
|
54
|
+
// definition(t) {
|
|
55
|
+
// t.field('page', {
|
|
56
|
+
// type: 'PageFiltersInput',
|
|
57
|
+
// });
|
|
58
|
+
// }
|
|
59
|
+
// })
|
|
60
|
+
// );
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
types: [pageTypeExtendNexus, ...collectionTypesNexus]
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export default pageType;
|
|
@@ -1,127 +1,127 @@
|
|
|
1
|
-
import { Strapi } from '@strapi/strapi';
|
|
2
|
-
|
|
3
|
-
import { filterUnderscoreArguments } from '../utils/filter-underscore-arguments';
|
|
4
|
-
import { PAGE_UID } from '../../shared/utils/constants';
|
|
5
|
-
import { Pagination } from '../utils/paginationValidation';
|
|
6
|
-
|
|
7
|
-
const getPageInfoFromUID = (strapi: Strapi) => {
|
|
8
|
-
// @ts-ignore service does exist
|
|
9
|
-
const collectionTypes: ICollectionTypeGL[] = strapi.service('plugin::page-builder.collection-types').withPageMorph();
|
|
10
|
-
|
|
11
|
-
const typeDefs = () => {
|
|
12
|
-
const metaInfo = `type MetaInfo {
|
|
13
|
-
total: Int
|
|
14
|
-
page: Int
|
|
15
|
-
pageCount: Int
|
|
16
|
-
pageSize: Int
|
|
17
|
-
}`;
|
|
18
|
-
const entityInfo = collectionTypes.map((collectionType) => {
|
|
19
|
-
return `
|
|
20
|
-
extend type ${collectionType.type}EntityResponseCollection {
|
|
21
|
-
metaInfo: MetaInfo
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
type Query {
|
|
25
|
-
get${collectionType.type}Pages(filters: ${collectionType.type}FiltersInput,pagination: PaginationArg, sort:[String], pageFilters: PageFiltersInput): ${collectionType.type}EntityResponseCollection
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
`;
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
return `${metaInfo} ${entityInfo}`;
|
|
32
|
-
};
|
|
33
|
-
const resolvers = (strapi: Strapi) => {
|
|
34
|
-
const { transformArgs } = strapi.plugin('graphql').service('builders').utils;
|
|
35
|
-
const pageQuery = collectionTypes.map((collectionType) => {
|
|
36
|
-
return {
|
|
37
|
-
[`get${collectionType.type}Pages`]: {
|
|
38
|
-
resolve: async (_parent: any, args: Record<string, any>, ctx: any) => {
|
|
39
|
-
if (!args.pagination || !args.pagination.page || !args.pagination.pageSize) {
|
|
40
|
-
throw new Error('page and pageSize is required');
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const { start, limit } = Pagination.checkPagination(args.pagination.page, args.pagination.pageSize);
|
|
44
|
-
|
|
45
|
-
const filteredArgs = {
|
|
46
|
-
...filterUnderscoreArguments(args)
|
|
47
|
-
};
|
|
48
|
-
const pageFilters = { filters: args.pageFilters };
|
|
49
|
-
|
|
50
|
-
const { toEntityResponseCollection } = strapi.plugin('graphql').service('format').returnTypes;
|
|
51
|
-
|
|
52
|
-
const getPage = async () => {
|
|
53
|
-
const transformedArgs = transformArgs(filteredArgs, {
|
|
54
|
-
contentType: strapi.contentTypes[collectionType.uid],
|
|
55
|
-
usePagination: true
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
const transformedpageArgs = transformArgs(pageFilters, {
|
|
59
|
-
contentType: strapi.contentTypes[PAGE_UID],
|
|
60
|
-
usePagination: true
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
const results = await (strapi as Strapi)?.entityService?.findMany(collectionType.uid, {
|
|
64
|
-
populate: '*',
|
|
65
|
-
filters: {
|
|
66
|
-
...transformedArgs.filters,
|
|
67
|
-
hasPage: { $eq: true },
|
|
68
|
-
page: { ...transformedpageArgs.filters }
|
|
69
|
-
},
|
|
70
|
-
sort: transformedArgs.sort,
|
|
71
|
-
start: start,
|
|
72
|
-
limit: limit
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
const entityResponse = toEntityResponseCollection(results || [], {
|
|
76
|
-
args: transformedArgs,
|
|
77
|
-
resourceUID: collectionType.uid
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
const entityResponsePaginated = Pagination.getPaginationInfo(
|
|
81
|
-
transformedpageArgs,
|
|
82
|
-
transformedArgs,
|
|
83
|
-
start,
|
|
84
|
-
args.pagination.pageSize,
|
|
85
|
-
entityResponse,
|
|
86
|
-
collectionType.uid
|
|
87
|
-
);
|
|
88
|
-
|
|
89
|
-
return entityResponsePaginated;
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
const results: Record<string, any> = await getPage();
|
|
93
|
-
|
|
94
|
-
if (Object.values(results)?.filter(Boolean).length > 0) {
|
|
95
|
-
return results;
|
|
96
|
-
} else {
|
|
97
|
-
throw new Error(ctx.koaContext.response.message);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
return {
|
|
105
|
-
Query: Object.assign({}, ...pageQuery)
|
|
106
|
-
};
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
const resolversConfig = () => {
|
|
110
|
-
const configQuery = collectionTypes.map((collectionType) => {
|
|
111
|
-
return {
|
|
112
|
-
[`Query.get${collectionType.type}Pages`]: {
|
|
113
|
-
auth: false
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
});
|
|
117
|
-
return Object.assign({}, ...configQuery);
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
return {
|
|
121
|
-
typeDefs: typeDefs(),
|
|
122
|
-
resolvers: resolvers(strapi),
|
|
123
|
-
resolversConfig: resolversConfig()
|
|
124
|
-
};
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
export default getPageInfoFromUID;
|
|
1
|
+
import { Strapi } from '@strapi/strapi';
|
|
2
|
+
|
|
3
|
+
import { filterUnderscoreArguments } from '../utils/filter-underscore-arguments';
|
|
4
|
+
import { PAGE_UID } from '../../shared/utils/constants';
|
|
5
|
+
import { Pagination } from '../utils/paginationValidation';
|
|
6
|
+
|
|
7
|
+
const getPageInfoFromUID = (strapi: Strapi) => {
|
|
8
|
+
// @ts-ignore service does exist
|
|
9
|
+
const collectionTypes: ICollectionTypeGL[] = strapi.service('plugin::page-builder.collection-types').withPageMorph();
|
|
10
|
+
|
|
11
|
+
const typeDefs = () => {
|
|
12
|
+
const metaInfo = `type MetaInfo {
|
|
13
|
+
total: Int
|
|
14
|
+
page: Int
|
|
15
|
+
pageCount: Int
|
|
16
|
+
pageSize: Int
|
|
17
|
+
}`;
|
|
18
|
+
const entityInfo = collectionTypes.map((collectionType) => {
|
|
19
|
+
return `
|
|
20
|
+
extend type ${collectionType.type}EntityResponseCollection {
|
|
21
|
+
metaInfo: MetaInfo
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
type Query {
|
|
25
|
+
get${collectionType.type}Pages(filters: ${collectionType.type}FiltersInput,pagination: PaginationArg, sort:[String], pageFilters: PageFiltersInput): ${collectionType.type}EntityResponseCollection
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
`;
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
return `${metaInfo} ${entityInfo}`;
|
|
32
|
+
};
|
|
33
|
+
const resolvers = (strapi: Strapi) => {
|
|
34
|
+
const { transformArgs } = strapi.plugin('graphql').service('builders').utils;
|
|
35
|
+
const pageQuery = collectionTypes.map((collectionType) => {
|
|
36
|
+
return {
|
|
37
|
+
[`get${collectionType.type}Pages`]: {
|
|
38
|
+
resolve: async (_parent: any, args: Record<string, any>, ctx: any) => {
|
|
39
|
+
if (!args.pagination || !args.pagination.page || !args.pagination.pageSize) {
|
|
40
|
+
throw new Error('page and pageSize is required');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const { start, limit } = Pagination.checkPagination(args.pagination.page, args.pagination.pageSize);
|
|
44
|
+
|
|
45
|
+
const filteredArgs = {
|
|
46
|
+
...filterUnderscoreArguments(args)
|
|
47
|
+
};
|
|
48
|
+
const pageFilters = { filters: args.pageFilters };
|
|
49
|
+
|
|
50
|
+
const { toEntityResponseCollection } = strapi.plugin('graphql').service('format').returnTypes;
|
|
51
|
+
|
|
52
|
+
const getPage = async () => {
|
|
53
|
+
const transformedArgs = transformArgs(filteredArgs, {
|
|
54
|
+
contentType: strapi.contentTypes[collectionType.uid],
|
|
55
|
+
usePagination: true
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const transformedpageArgs = transformArgs(pageFilters, {
|
|
59
|
+
contentType: strapi.contentTypes[PAGE_UID],
|
|
60
|
+
usePagination: true
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const results = await (strapi as Strapi)?.entityService?.findMany(collectionType.uid, {
|
|
64
|
+
populate: '*',
|
|
65
|
+
filters: {
|
|
66
|
+
...transformedArgs.filters,
|
|
67
|
+
hasPage: { $eq: true },
|
|
68
|
+
page: { ...transformedpageArgs.filters }
|
|
69
|
+
},
|
|
70
|
+
sort: transformedArgs.sort,
|
|
71
|
+
start: start,
|
|
72
|
+
limit: limit
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
const entityResponse = toEntityResponseCollection(results || [], {
|
|
76
|
+
args: transformedArgs,
|
|
77
|
+
resourceUID: collectionType.uid
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
const entityResponsePaginated = Pagination.getPaginationInfo(
|
|
81
|
+
transformedpageArgs,
|
|
82
|
+
transformedArgs,
|
|
83
|
+
start,
|
|
84
|
+
args.pagination.pageSize,
|
|
85
|
+
entityResponse,
|
|
86
|
+
collectionType.uid
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
return entityResponsePaginated;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const results: Record<string, any> = await getPage();
|
|
93
|
+
|
|
94
|
+
if (Object.values(results)?.filter(Boolean).length > 0) {
|
|
95
|
+
return results;
|
|
96
|
+
} else {
|
|
97
|
+
throw new Error(ctx.koaContext.response.message);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
return {
|
|
105
|
+
Query: Object.assign({}, ...pageQuery)
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const resolversConfig = () => {
|
|
110
|
+
const configQuery = collectionTypes.map((collectionType) => {
|
|
111
|
+
return {
|
|
112
|
+
[`Query.get${collectionType.type}Pages`]: {
|
|
113
|
+
auth: false
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
});
|
|
117
|
+
return Object.assign({}, ...configQuery);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
return {
|
|
121
|
+
typeDefs: typeDefs(),
|
|
122
|
+
resolvers: resolvers(strapi),
|
|
123
|
+
resolversConfig: resolversConfig()
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
export default getPageInfoFromUID;
|
package/server/index.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import register from './register';
|
|
2
|
-
import bootstrap from './bootstrap';
|
|
3
|
-
import destroy from './destroy';
|
|
4
|
-
import config from './config';
|
|
5
|
-
import contentTypes from './content-types';
|
|
6
|
-
import controllers from './controllers';
|
|
7
|
-
import routes from './routes';
|
|
8
|
-
import middlewares from './middlewares';
|
|
9
|
-
import policies from './policies';
|
|
10
|
-
import services from './services';
|
|
11
|
-
|
|
12
|
-
export default {
|
|
13
|
-
register,
|
|
14
|
-
bootstrap,
|
|
15
|
-
destroy,
|
|
16
|
-
config,
|
|
17
|
-
controllers,
|
|
18
|
-
routes,
|
|
19
|
-
services,
|
|
20
|
-
contentTypes,
|
|
21
|
-
policies,
|
|
22
|
-
middlewares
|
|
23
|
-
};
|
|
1
|
+
import register from './register';
|
|
2
|
+
import bootstrap from './bootstrap';
|
|
3
|
+
import destroy from './destroy';
|
|
4
|
+
import config from './config';
|
|
5
|
+
import contentTypes from './content-types';
|
|
6
|
+
import controllers from './controllers';
|
|
7
|
+
import routes from './routes';
|
|
8
|
+
import middlewares from './middlewares';
|
|
9
|
+
import policies from './policies';
|
|
10
|
+
import services from './services';
|
|
11
|
+
|
|
12
|
+
export default {
|
|
13
|
+
register,
|
|
14
|
+
bootstrap,
|
|
15
|
+
destroy,
|
|
16
|
+
config,
|
|
17
|
+
controllers,
|
|
18
|
+
routes,
|
|
19
|
+
services,
|
|
20
|
+
contentTypes,
|
|
21
|
+
policies,
|
|
22
|
+
middlewares
|
|
23
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default {};
|
|
1
|
+
export default {};
|
package/server/policies/index.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default {};
|
|
1
|
+
export default {};
|
package/server/register.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { Strapi } from '@strapi/strapi';
|
|
2
|
-
|
|
3
|
-
import getPageBySlug from './graphql/page-by-slug';
|
|
4
|
-
import pageType from './graphql/page-type';
|
|
5
|
-
import getPageInfoFromUID from './graphql/pages-by-uid';
|
|
6
|
-
|
|
7
|
-
export default async ({ strapi }: { strapi: Strapi }) => {
|
|
8
|
-
const extensionService = strapi.plugin('graphql').service('extension');
|
|
9
|
-
|
|
10
|
-
extensionService.use(pageType);
|
|
11
|
-
extensionService.use(getPageBySlug(strapi));
|
|
12
|
-
extensionService.use(getPageInfoFromUID(strapi));
|
|
13
|
-
|
|
14
|
-
await strapi.services?.['plugin::page-builder.builder']?.buildContentTypes();
|
|
15
|
-
};
|
|
1
|
+
import { Strapi } from '@strapi/strapi';
|
|
2
|
+
|
|
3
|
+
import getPageBySlug from './graphql/page-by-slug';
|
|
4
|
+
import pageType from './graphql/page-type';
|
|
5
|
+
import getPageInfoFromUID from './graphql/pages-by-uid';
|
|
6
|
+
|
|
7
|
+
export default async ({ strapi }: { strapi: Strapi }) => {
|
|
8
|
+
const extensionService = strapi.plugin('graphql').service('extension');
|
|
9
|
+
|
|
10
|
+
extensionService.use(pageType);
|
|
11
|
+
extensionService.use(getPageBySlug(strapi));
|
|
12
|
+
extensionService.use(getPageInfoFromUID(strapi));
|
|
13
|
+
|
|
14
|
+
await strapi.services?.['plugin::page-builder.builder']?.buildContentTypes();
|
|
15
|
+
};
|