Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default async (root: any, args: Object, context: Object) => {
if (!args.parent && !args.url) {
return new NotFoundResponse("Page parent or URL missing.");
}
// We utilize the same query used for listing published pages (single source of truth = less maintenance).
const Page = context.getEntity("PbPage");
const Category = context.getEntity("PbCategory");
const [page] = await listPublishedPages({ Page, Category, args: { ...args, perPage: 1 } });
if (!page) {
return new NotFoundResponse("The requested page was not found.");
}
return new Response(page);
};
export default async (root: any, args: Object, context: Object) => {
if (!args.parent && !args.url) {
return new NotFoundResponse("Page parent or URL missing.");
}
// We utilize the same query used for listing published pages (single source of truth = less maintenance).
const Page = context.getEntity("PbPage");
const Category = context.getEntity("PbCategory");
const [page] = await listPublishedPages({ Page, Category, args: { ...args, perPage: 1 } });
if (!page) {
return new NotFoundResponse("The requested page was not found.");
}
return new Response(page);
};
export default (entityFetcher: EntityFetcher) => async (
root: any,
args: Object,
context: Object
) => {
const { slug } = args;
const entityClass = entityFetcher(context);
const entity = await entityClass.findOne({ query: { slug } });
if (!entity) {
return new NotFoundResponse("Menu not found.");
}
return new Response({
id: entity.id,
title: entity.title,
items: prepareMenuItems({ entity, context })
});
};