@paroicms/server
Version:
The ParoiCMS server
67 lines • 2.95 kB
JavaScript
import { getDocumentTypeByName } from "@paroicms/internal-anywhere-lib";
import { parseLNodeId } from "@paroicms/public-anywhere-lib";
import { siteReadyGuard } from "../../graphql/graphql.types.js";
import { authGuard } from "../auth/auth.helper.js";
import { getTypeNameOf } from "../node/node.queries.js";
import { movePart } from "./part-moving.queries.js";
import { createNodeWithPart, createPartOnNode, deletePart, loadPartSeed, readPartSeedsOf, } from "./part.queries.js";
export const partResolvers = {
Query: {
part: async (_parent, { lNodeId }, { siteContext, httpContext }) => {
authGuard(httpContext);
siteReadyGuard(siteContext);
return await loadPartSeed(siteContext, parseLNodeId(lNodeId));
},
partsOf: async (_parent, { documentId }, { siteContext, httpContext }) => {
authGuard(httpContext);
siteReadyGuard(siteContext);
const { nodeId, language } = parseLNodeId(documentId);
const typeName = await getTypeNameOf(siteContext, nodeId);
const documentType = getDocumentTypeByName(siteContext.siteSchema, typeName);
if (!documentType.lists || documentType.lists.length === 0)
return null;
return await readPartSeedsOf(siteContext, {
documentNodeId: nodeId,
language,
});
},
},
Mutation: {
createPartOnNode: async (_parent, { language, nodeId }, { siteContext, httpContext }) => {
authGuard(httpContext);
siteReadyGuard(siteContext);
const newId = await createPartOnNode(siteContext, {
language,
nodeId,
});
return await loadPartSeed(siteContext, newId);
},
createNodeWithPart: async (_parent, { parentLNodeId, listName, typeName }, { siteContext, httpContext }) => {
authGuard(httpContext);
siteReadyGuard(siteContext);
const newId = await createNodeWithPart(siteContext, {
listName,
parentLNodeId: parseLNodeId(parentLNodeId),
typeName,
});
return await loadPartSeed(siteContext, newId);
},
deletePart: async (_parent, { lNodeId }, { siteContext, httpContext }) => {
authGuard(httpContext);
siteReadyGuard(siteContext);
await deletePart(siteContext, parseLNodeId(lNodeId));
return true;
},
movePart: async (_parent, { partNodeId, newParentNodeId, newListName }, { siteContext, httpContext }) => {
authGuard(httpContext);
siteReadyGuard(siteContext);
await movePart(siteContext, {
partNodeId,
newParentNodeId,
newListName,
});
return true;
},
},
};
//# sourceMappingURL=part.resolver.js.map