Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rerender page from the page builder #2092

Merged
merged 3 commits into from Dec 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 37 additions & 2 deletions packages/api-page-builder/src/graphql/graphql/pages.gql.ts
@@ -1,11 +1,17 @@
import { ListResponse, Response, ErrorResponse } from "@webiny/handler-graphql/responses";
import {
ListResponse,
Response,
ErrorResponse,
NotFoundResponse
} from "@webiny/handler-graphql/responses";
import { GraphQLSchemaPlugin } from "@webiny/handler-graphql/types";
import { Page, PbContext } from "~/types";
import { Page, PbContext, PageSecurityPermission } from "~/types";
import Error from "@webiny/error";
import resolve from "./utils/resolve";
import pageSettings from "./pages/pageSettings";
import { fetchEmbed, findProvider } from "./pages/oEmbed";
import lodashGet from "lodash/get";
import checkBasePermissions from "~/graphql/crud/utils/checkBasePermissions";

const plugin: GraphQLSchemaPlugin<PbContext> = {
type: "graphql-schema",
Expand Down Expand Up @@ -272,6 +278,9 @@ const plugin: GraphQLSchemaPlugin<PbContext> = {
deleteRevision(id: ID!): PbDeleteResponse

updateImageSize: PbDeleteResponse

# Re-renders given page.
rerenderPage(id: ID!): PbPageResponse
}
`,
resolvers: {
Expand Down Expand Up @@ -448,6 +457,32 @@ const plugin: GraphQLSchemaPlugin<PbContext> = {

requestChanges: async (_, args: { id: string }, context) => {
return resolve(() => context.pageBuilder.pages.requestChanges(args.id));
},

rerenderPage: async (_, args: { id: string }, context) => {
try {
await checkBasePermissions<PageSecurityPermission>(context, "pb.page", {
pw: "p"
});

// If permissions-checks were successful, let's continue with the rest.
// Retrieve the original page. If it doesn't exist, immediately exit.
const page = await context.pageBuilder.pages.get(args.id);
if (!page) {
console.warn(`no page with id ${args.id}`);
return new NotFoundResponse("Page not found.");
}

// We only need the `id` of the newly created page.
await context.pageBuilder.pages.prerendering.render({
context,
paths: [{ path: page.path }]
});

return new Response(page);
} catch (e) {
return new ErrorResponse(e);
}
}
},
PbPageSettings: {
Expand Down
@@ -1,4 +1,5 @@
import * as React from "react";

import { PbPageDetailsPlugin } from "~/types";
import Header from "./Header";
import RevisionSelector from "./revisionSelector/RevisionSelector";
Expand Down